PoissonGroup rates update

36 views
Skip to first unread message

Filippo Ferrari

unread,
Aug 4, 2020, 6:52:58 PM8/4/20
to Brian
Hi, 
I am working on a model in which I have to accumulate the spikes fired by a NeuronGroup during the simulation and, based on the accumulated values, I have to update the rates of a PoissonGroup which acts as an input to the network. 

I have attached an example script. 
Basically, each simulation "step" lasts 20ms, there is an input which consists in the rate for each neuron at each step. 
The issue is that this input has to change based on some computation that I cannot express using Brian2 Equation objects.
So, at the beginning at each step I count the spikes fired in the previous 20ms, perform the "accumulation" (which is used to control an agent in a 2d simulation) and then I need to update the rates of the stimulus for the next 20ms. 

As it is right now, the stimulus_values array gets updated correctly, but the spikes generated from the PoissonGroup are not updated in the same way. 

I have also tried to split up the run commands in the following way:

net = Network(collect())
for _ in range(sim_steps):
    net.run(time_step *ms)

but it behaves in the same way. 

Thank you very much!
Filippo 

example.py

Marcel Stimberg

unread,
Aug 6, 2020, 11:13:21 AM8/6/20
to Brian
Hi Filippo,
as a first comment: you can count spikes as part of the simulation rather easily. In your model, include a variable `spike_count : integer` and add `spike_count += 1` to the reset statement. You can reset this counter with `neurons.spike_count = 0` either as part of your network_operation or in between runs.

In your code you try to create a new TimedArray for each of your simulation steps – this does not work, because the PoissonGroup still references the previous TimedArray (references are resolved when you call run). But from your code excerpt it looks as if the stimulus is constant during the simulation step – in this case you do not need to use a TimedArray at all if you use multiple runs or a network_operation to set it.  Instead, you can set the PoissonGroup to use constant rates (say, "PG = PoissonGroup(2, rates=[100, 200]*Hz)") and then you can change its rates between runs or in the network_operation with something like "PG.rates = [50, 300]*Hz".

Hope that helps, best
  Marcel

Filippo Ferrari

unread,
Aug 6, 2020, 12:06:30 PM8/6/20
to Brian
Hi Marcel, 

Thanks for the count spike change, I was sure there was a better way to do it.
Setting the rates at each 20ms step is working as I was expecting!

Thanks again, 
Filippo 

Filippo Ferrari

unread,
Aug 6, 2020, 7:08:12 PM8/6/20
to Brian
Hi Marcel, 
I am now running the simulation in this way (part of it was already structured like this)

net = Network(collect())
for _ in range(sim_steps):
    net.run(time_step *ms)

and now the total time increased by more than 3x. 

Is there any way to speed things up?
I looked in the documentation but couldn't find anything about this. 
I assume there must be some overhead in keep restarting the simulation, can part of it be reduced?

Thank you!
Filippo 

Felix Kern

unread,
Aug 12, 2020, 11:01:26 PM8/12/20
to Brian
Filippo,
Yes, calls to run() can have quite a lot of overhead, unfortunately (one of the downsides of the code generation approach). Is there a particular reason for not using run_regularly or network operations?
Best, Felix

Filippo Ferrari

unread,
Aug 13, 2020, 6:37:57 AM8/13/20
to Brian
Hi Felix,

Thanks for your reply!
In the end I restructured the code and I am now running everything as network operations.
Thanks! 
Filippo 
Reply all
Reply to author
Forward
0 new messages