Looking for a toy example of object oriented simulation of neurons

Implementation of simulation of connected neurons can become easily complicated if you have different kind of neurons. I am looking for a toy example that each neuron is defined as a class, having access to index of neurons that send spike to a target neuron and stuff like that.
Do you know some reference, example comment …?
C++ or Python is preferred.

This one is fine but too complicated to consider as a toy example suitable for learning.

1 Like

Hi! I am rewriting a traditional network in a OO way. It is super easy due to my poor programing ability:) But I write it in Matlab way. And there is no doc yet:(. Here is the link: https://github.com/Kun-Ming/OpenNetwork

1 Like

Maybe we could write together? I also want write these in python.

Thank you. I briefly looked the link. Could you provide a super easy example. If I get the concept yes pair programming would be nice.
Getting more efficiency will be the next step.

That will be a long story and I didn’t finish it yet. I plan to make a base class of neuron, and inherited other neuron models form the base neuron class, I am writing EIF(exponential integrate-and-fire) neuron model now. And the layer also has a base class, inherited another kind of layer with special feature from the base layer class. I am writing feedforward layer now, which is the special layer for our lab’s project.

Each neuron has a spike train, and may affected by other neurons, i.e., affected by 800 neurons. So we can calculate 1 neuron’s spike train through the 800 neurons’s spike train. Maybe that can do what you want.

1 Like

This is like what I like to do

A toy example from Brian2.

eqs = '''
dv/dt = (I-v)/tau : 1
I : 1
tau : second
'''
G = NeuronGroup(2, eqs, threshold='v>1', reset='v = 0', method='exact')
G.I = [2, 0]
G.tau = [10, 100]*ms

# Comment these two lines out to see what happens without Synapses
S = Synapses(G, G, on_pre='v_post += 0.2')
S.connect(i=0, j=1)

M = StateMonitor(G, 'v', record=True)

run(100*ms)

plot(M.t/ms, M.v[0], label='Neuron 0')
plot(M.t/ms, M.v[1], label='Neuron 1')
xlabel('Time (ms)')
ylabel('v')

NEST and Brian are two mature software with their pros and con. NEST is more complicated to develop and does not provide access to voltage of pre-synaptic neurons, and Brian is not appropriate for large scale simulations.
These software are designed to provide variety of applications, and keep users apart from dealing with complicated coding. But toy example can be very simple and just do necessary tasks and for now not user friendly.

These are necessities:

  • I think it will be straightforward to define each neuron as a class.
  • Communication of neurons will be a bit tricky.
  • There should be global index (GID) for each neuron in the network.
  • Each neuron should have access to GID of incoming neurons to update voltage at each time step (if there is a spike).
  • The list of incoming neurons for each target neuron will be updated at each time step based on presence of spike.
  • The synapse of the target neuron should have access to the voltage of pre-synaptic neuron (conductance base neurons connectivity depend on pre-synaptic voltage).
  • In each neuron there is an update function to update the voltage according to total incoming currents.
  • Each neuron class need some functions to set and get variables.
  • The base class can provide default method for updating, integration, …
  • The neurons only communicate GID and voltage. (communication of double numbers make it slow), so many functions will be common regardless of neuron model.

Adding layer (topography), optimization, defining suitable date structure, parallelization, … are other things need to be decided about.

I try to update the post when making progress.

1 Like

You came up a lot good points! Actually I have a framework about this. There can be neuron, synapse and layer, three base class.

  1. The neuron base class should perform like what you say. And a recording of spike train in neuron base class may help a lot.
  2. The synapse base class should be perform like map(a kind of data structure), one neuron map to a list or vector(also a kind of data structure), recording the connect strength, excitatory or inhibitory, etc. Each neuron has an ID.
  3. The layer base class should consist of synapses. The synapse class’s map only has 1 key and 1 value, the layer base class’s map may has many keys and values, cause layer has many synapses.
  4. In simulation case, each neuron can be paralleled in GPU or multi core CPU.

Thank you for provide the information about Brian2 and NEST, these will be good material to study. Maybe we can extend from them and reduce the coding time.