Looks like I can't call the value of the matrix in 'on_pre'

Description of problem

I defined a 2-dimensional synaptic connection matrix M[ ], and using the Synapses() function. I define on_pre=’ g_ampa = M[ i_pre, i_post ] 0.3nS ', but it reports an error, it looks like I can’t call the value of the matrix in on_pre? Does anyone have a solution to this problem?

Minimal code to reproduce problem

on_pre=’ g_ampa = M[ i_pre, i_post ] 0.3nS ’

The method mentioned here will likely be useful for you:

The difference is that I need to index the array in on_pre=’ ‘, for example on_pre=’ g_ampa = M[i_pre] *0.3nS ‘. I have tried on_pre=’ g_ampa = i_pre *0.3nS ’ which works, but can not index arrays or matrices, what I need is this.

Hi @zeroinput .
You do not need matrix indexing in your case. Brian’s equation system describes everything from a the perspective of a single neuron or single synapse. In your case, you want each synapse to have its own weight and the synapse does only need access to its own weight, not the full matrix. You can use @adam’s suggestion and set the weights in your model from your matrix, i.e.:

syn = Synapses(source, target, 'w : 1 (constant)',
               on_pre='g_ampa += w * 0.3*nS')
syn.connect()
syn.w[:] = M.flatten()

I used g_ampa += instead of g_ampa = above, since usually you want to have multiple incoming spikes add up.

Hope that makes things clearer, best
Marcel

Hi Marcel,
Thanks for your replies!
I did this because I wanted to add dendrites to the neurons (say with 3 dendrites), so I defined the (100, 100*3) matrix to correspond to the connections to the synapses. I need to index the number of different dendrites at on_pre and provide them to g_ampa1,g_ampa2 and g_gama3. So it seems that there is still no way to avoid having to index the array in on_pre

Hi again. Just to make sure that I understand, can you give a bit more detail on how you are adding dendrites to the neurons? Do you do this as part of the equations, e.g. by having dv_dend1/dt = ..., dv_dend2/dt = ..., etc. terms?

Marcel

For example:

dv/dt=(-(v-El) -(g_1ampa*v) -(g_2ampa*v)  )/taum : volt
dg_1ampa/dt = ...
dg_2gaba/dt = ...

Ok, I see.
I think you basically have two options: either store three weight variables in a single Synapses object, or use a separate Synapses object for each dendrite. The first approach is the easiest and most efficient if you use all-to-all connections (in particular, each pre-synaptic neuron targets each dendrite of the post-synaptic neuron). Something along the lines of:

syn = Synapses(source, target,
               '''w1 : 1 (constant)
                  w2 : 1 (constant)
                  w3 : 1 (constant)''',
               on_pre='''g_ampa1 += w1 * 0.3*nS
                         g_ampa2 += w2 * 0.3*nS
                         g_ampa3 += w3 * 0.3*nS''')
syn.connect()
syn.w1[:] = M[:, :, 0].flatten()
syn.w2[:] = M[:, :, 1].flatten()
syn.w3[:] = M[:, :, 2].flatten()

Best,
Marcel

1 Like

Thanks, you saved my day! :smiley:

2 Likes