Counting spikes

Dear all,

As SNNs are mainly driven by efficient computation and power constrained systems, I would like to know how I could decode the spike frequency of each neuron for a certain input to get a ballpark figure on the network’s power consumption.

Does someone know how to plot spike counts or to record number of spikes during simulation per neuron or per layer?

Hi sjoks,

You can record the number of spikes with a probe, like:

with nengo.Network() as net:
    ens = nengo.Ensemble(...)
    my_spike_probe = nengo.Probe(ens.neurons)

...

with nengo.Simulator(net) as sim:
    sim.run(1.0) # run for one second
    my_spike_counts = np.sum(sim.data[my_spike_probe] > 0, axis=0)

Let me know if this helps!

1 Like

Thanks! So to get the average spike activity per neuron, I would do np.average(np.sum…) ?

Hi sjoks,

‘Average spike activity’ is a little more nuanced so I’ll add the caveat that this is how you get the average activity given your input.

When you probe ens.neurons and read the data after running the simulation you will get an array of shape (n_steps, n_neurons). Since the neurons will react differently to different inputs, this array will give the activity given the specific input signal passed in during the simulation.

What Kris wrote above gives you the total number of spikes for each neuron because you are summing across the time dimension where the activity is greater than zero.

To get the average number of steps of activity, given the current input, you need to divide by the total number of steps, which is determined by how long you run your sim for and what you set dt on your nengo.Simulator() object.

For example, if you set up your simulation as:

   sim.run(1)

You will run the simulation for 500 steps (1 sec / 0.002 sec). More simply, you can get the total number of steps from sim.data[my_spike_probe].shape[0]