NeuromorphicProcessorProject / snn_toolbox

Toolbox for converting analog to spiking neural networks (ANN to SNN), and running them in a spiking neuron simulator.
MIT License
360 stars 104 forks source link

Membrane Potential Values after spike conv layer. #137

Closed shreshth-29 closed 9 months ago

shreshth-29 commented 1 year ago

I used the SNN toolbox to convert a CNN into a spiking network. In the config file, I set the encoding as 'temporal_mean_rate', threshold as 1mv and dt as 1ms. The time constants are the default values. The simulation time is 200 ms.

I saved the model as a .h5 file and after loading the model, I wanted to inspect it's outputs. I made a prediction for an input tensor and I tried to observe the membrane potential values and the spiketrains for the first layer (which was a conv layer).

The membrane potential values seem to be very closely related to the values we get after a normal convolution, with analog/continuous values. For example, the values after convolution which were supposed to be 1, -0.21174717,-0.45101094, 0.8199355 , were 0, -0.423494, -0.90202188, 0.639871 in the membrane potential. The values seemed to have doubled, and the last value, which exceed the threshold (1) ,is obtained after subtracting 1(threshold) from the doubled value. However, the threshold was subtracted twice for 1. (1*2-1-1 =0). I experimented with some other values of the threshold and each time, the membrane potential values were obtained by multiplying the normal convolution values, by some integer (2,3,4 etc), and for values that exceed the threshold, the threshold was subtracted: sometimes once, sometimes multiple times. The spiktrain array had 1s whenever the value exceeded the threshold.

I have 2 basic questions pertaining to these observations:

@rbodo

rbodo commented 1 year ago

Hi, in case you haven't done so yet, please check Sec. 2.1 of this paper. It explains the math behind this rate encoding.

In short, a presynaptic spike causes a value to be added to the membrane potential that's proportional to the synaptic strength (the weight in the convolution kernel). This increase or decrease can happen at every time step in which you get a presynaptic spike, hence the integer-multiples in your observation. If you ANN activation is 0.1, then you'll get a spike every tenth time step, resulting in a spike rate of 0.1 if you run it long enough. So the 'average spike rates' are calculated from the 1s and 0s in the output spike train, not the other way around.

Hope the paper helps clear things up further.