How do I delete a synaptic connection?

Description of problem

For example, if I want to delete the connection between neuron i =0 and neuron j=1, how do I do that

Minimal code to reproduce problem

S = Synapses(G, G,‘w :1’ ,on_pre=‘v_post += w’)
S.connect(i=0, j=[1,2])

What you have aready tried

Expected output (if relevant)

Actual output (if relevant)

Full traceback of error (if relevant)

Hi @HotCoCo . Unfortunately, it is not possible at the moment to delete connections. See Structural plasticity · Issue #166 · brian-team/brian2 · GitHub for a discussion of this feature. I assume that you want to run the simulation with the connection for a while, and then remove the connection (since otherwise you should simply not create it in the first place)? The usual workaround for that would be to not delete the connections, but instead to set synaptic weights for the “deleted” connections to zero. If your model is complex and there are various things depending on the presence/absence of the synapse, you could also have an explicit “deleted : boolean (constant)” parameter in your synapse model. You can then use something like int(not deleted) to get a value of 0 for deleted synapses, and a value of 1 otherwise.

Thank you very much for your answer. What I want to do is quickly read a pre-set synaptic connection, but make some changes to it, such as add some connections, subtract some connections. I was worried that resetting weights to zero would slow down the speed by loading more and more synaptic connections each time.

Could you be more specific what you mean by “read a pre-set synaptic connection”? If all you want to do is to load e.g. a connectivity matrix from a file and then add/remove some connections, the easiest way would be to do all that before you do a Synapses.connect call.

I build the connection matrix out of the file like this once, and then I save it as .npz(learn from one issue). And then every time I use it, I’m just reading .npz, changing the connection and overwriting this .npz .Actually, I have one more question… Can I add and delete neurons in NeuronsGroup…

In this case, I would simply recommend not to create any synapses until you’ve finished setting up your connections. E.g. in the make_network situation, you could store things in arrays instead of calling S.connect:

source_indices = []
target_indices = []
weights = []
# a = ...
for index in range(N):
    target_indices.extend(np.ones_like(a, dtype=int)*index)
   # my_number = ...
    weights.extend(np.ones_like(a, dtype=int)*random.random()*0.8*my_number)

Saving these lists will do the same thing as saving the information from the Synapses object. Then, if you load and change these values, you again do it directly on the lists/arrays before you create a Synapses object.

No. You’ll have to decide how many neurons you need before you create the NeuronGroup.

You are such a warm-hearted person, I will try this method.

1 Like