Hi Xavier,

 

I don’t quite understand what you mean. GetConnections() allows you to provide any NodeCollection as source or target argument and then you will get the connections from the given sources to the given targets. But I guess you then would like to extract from the resulting SynapseCollection only those entries that have a given target i.

 

A first step would be as follows:

 

n = nest.Create('parrot_neuron', 5)

nest.Connect(n, n, {'rule': 'fixed_indegree', 'indegree': 2})

c = nest.GetConnections(n, n)

 

c2 = [cc for cc in c if cc.target == n[2]]

 

which will give you a list of single-element synapse collections which all have n[2] as their target. The problem is then that there currently is no way to turn this into a new SynapseCollection you could to

 

c2.weight = 25

 

One way to fix this would be to change the SynapseCollection constructor (https://github.com/nest/nest-simulator/blob/8e85268ca512e0f509240fb5ef06f62a4e61a67e/pynest/nest/lib/hl_api_types.py#L603) to allow a list of SynapseCollections as input and simply join their _datum elements into one new _datum element. Then you could pass c2 to that constructor and get new collection.

 

A slightly more complex fix would be to add a filtering capability to the SynapseCollection itself, i.e., a method returning a subset of connections fulfilling certain criteria.

 

Finally, one could created a "grouped” SynapseCollection from the start, where individual components could be addressed by a given criterion, e.g., by the target number. The return value could for simplicity be a dict mapping the criterion key to the corresponding SynapseCollection, or the same again wrapped into a synapse collection to support pretty printing.

 

Do you want to explore this and then provide a pull request? Why not drop by our next open developer video conference on Monday 26 Feb at 11.30 CET (https://github.com/nest/nest-simulator/wiki/2024-02-26-Open-NEST-Developer-Video-Conference)?

 

Best,

Hans Ekkehard

 

-- 

 

Prof. Dr. Hans Ekkehard Plesser

 

Department of Data Science

Faculty of Science and Technology

Norwegian University of Life Sciences

PO Box 5003, 1432 Aas, Norway

 

Phone +47 6723 1560

Email hans.ekkehard.plesser@nmbu.no

Home http://arken.nmbu.no/~plesser

 

 

 

From: Xavier Otazu <xotazu@cvc.uab.cat>
Date: Monday, 19 February 2024 at 12:16
To: users@nest-simulator.org <users@nest-simulator.org>
Subject: [NEST Users] GetConnections() enhancement request

Hi!

In order to perform connections weight normalization, I am using the GetConnections() function to obtain the input connections for every neuron. That is, I use a code like

for i in range(number_of neurons)
   conn[i] = GetConnections(my_source, my_target[i], ...)

Later in the code, I use conn[i].weight to perform my normalization.

It implies that for big networks (number_of_neurons=10k) I have to call GetConnections() around 10k times. Hence, the execution time is huge.

Could it be possible that you enhance GetConnections() (or define a new function) in order to return the connections for all the neurons in the target in array with the same longitude as the number of neurons in target instead of the number of connections? That is, indexed by neurons instead of indexed by connections.

I understand that present implementation of GetConnections() visits all the connections and return only the input connections to target. I do not want to tell developers how to do it :-) but I believe it could be implemented by visiting all the connections (related to target) just ONCE and copy each one to the corresponding output array indexed by neuron. This way, it would be a single call to GetConnections() (plus the time needed to internally manage the assignment to the output array), instead of 10k times.

It would be very much appreciated.

Thanks a lot in advance!

Xavier
_______________________________________________
NEST Users mailing list -- users@nest-simulator.org
To unsubscribe send an email to users-leave@nest-simulator.org