Spike Loss

class slayerSNN.spikeLoss.spikeLoss(networkDescriptor, slayerClass=<class 'slayerSNN.slayer.spikeLayer'>)[source]

This class defines different spike based loss modules that can be used to optimize the SNN.

NOTE: By default, this class uses the spike kernels from slayer.spikeLayer (snn.layer). In some cases, you may want to explicitly use different spike kernels, for e.g. slayerLoihi.spikeLayer (snn.loihi). In that scenario, you can explicitly pass the class name: slayerClass=snn.loihi

Usage:

>>> error = spikeLoss.spikeLoss(networkDescriptor)
>>> error = spikeLoss.spikeLoss(errorDescriptor, neuronDesc, simulationDesc)
>>> error = spikeLoss.spikeLoss(netParams, slayerClass=slayerLoihi.spikeLayer)
numSpikes(spikeOut, desiredClass, numSpikesScale=1)[source]

Calculates spike loss based on number of spikes within a target region. The target region and desired spike count is specified in error.errorDescriptor['tgtSpikeRegion'] Any spikes outside the target region are penalized with error.spikeTime loss..

e(t) &= 
\begin{cases}
\frac{acutalSpikeCount - desiredSpikeCount}{targetRegionLength} & \text{for }t \in targetRegion\\
\left(\varepsilon * (output - desired)\right)(t) & \text{otherwise}
\end{cases}

E &= \int_0^T e(t)^2 \text{d}t

Arguments:
  • spikeOut (torch.tensor): spike tensor

  • desiredClass (torch.tensor): one-hot encoded desired class tensor. Time dimension should be 1 and rest of the tensor dimensions should be same as spikeOut.

Usage:

>>> loss = error.numSpikes(spikeOut, target)
spikeTime(spikeOut, spikeDesired)[source]

Calculates spike loss based on spike time. The loss is similar to van Rossum distance between output and desired spike train.

E = \int_0^T \left( \varepsilon * (output -desired) \right)(t)^2\ \text{d}t

Arguments:
  • spikeOut (torch.tensor): spike tensor

  • spikeDesired (torch.tensor): desired spike tensor

Usage:

>>> loss = error.spikeTime(spikeOut, spikeDes)