bamsumit / slayerPytorch

PyTorch implementation of SLAYER for training Spiking Neural Networks
GNU General Public License v3.0
306 stars 91 forks source link

binningMode = 'SUM' does not work as it's supposed to #95

Open ronichester opened 1 year ago

ronichester commented 1 year ago

in spikeFileIO.py, the following lines have the same effect as binningMode = 'OR' :

elif binningMode.upper() == 'SUM':
                emptyTensor[pEvent[validInd], 
                            yEvent[validInd],
                            xEvent[validInd],
                            tEvent[validInd]] += 1/samplingTime

That is because += 1 in this case does not work, I believe it's a bug in your code. The idea is to sum the number of spikes on the same pixel in the same time window, but the way it's written it does not sum; i did many tests myself. In order to work as expected, the code should be something like this:

elif binningMode.upper() == 'SUM':
    for p,y,x,t in zip(pEvent[validInd], yEvent[validInd], xEvent[validInd], tEvent[validInd]):
                    emptyTensor[p,y,x,t] += 1/samplingTime

This implementation is terribly NOT efficient (up to the point it is unfeasible) but it works as expected. I can't think of a clever way to use the np.array characteristics to make it work efficiently; any ideas?

The point is, in my opinion, the way the code is written now, binning mode OR = binning mode SUM, and I am sure it was not supposed to be this way.

Cheers,

bamsumit commented 1 year ago

Hi @ronichester, yes it looks like a bug. Your snippet is correct. Will you be willing to issue a fix?