Fix _float_connection_matrix silently overwriting values for multi-synapse connections#79
Conversation
…napse connections Signed-off-by: Sanchit2662 <sanchit2662@gmail.com>
|
Thanks for the PR @Sanchit2662. I'm not quite sure about this one, though. The |
|
Thanks for pointing that out, I missed that plot_synapses already handles this at the public API level with the NotImplementedError. So patching the internal function doesn't really solve anything meaningful since it's never actually reached with multi-synapse values through the normal flow. |
I was looking through the plotting utilities and found a bug in _float_connection_matrix that silently produces wrong output for networks with multiple synapses between the same source-target pair.
The original code does a plain NumPy fancy index assignment:
When you have multi-synaptic connections, multiple entries in sources and targets point to the same matrix cell. NumPy just overwrites each time, so only the last synapse's value survives. If you had two synapses between neuron 0 and neuron 1 with weights 0.3 and 0.7, the matrix would show 0.7 and the 0.3 is gone with no warning.
I fixed it by replacing the assignment with two np.add.at accumulations one summing the values, one counting how many synapses hit each cell then dividing to get the mean. Mean makes sense here because the matrix is displaying a synaptic property like weight or delay per connection pair, so the average across al synapses between that pair is the meaningful thing to show.
I also updated the docstring to mention that multi-synaptic pairs display the mean, so users know what they're looking at.