cv_loss

Contents

cv_loss#

class braintools.fit.losses.cv_loss(prediction, target)#

Compute the squared difference of the mean inter-spike-interval CV.

\[L = \left(\langle \mathrm{CV} \rangle_{\mathrm{pred}} - \langle \mathrm{CV} \rangle_{\mathrm{target}}\right)^2,\]

where \(\langle \mathrm{CV} \rangle\) averages cv() over the neurons whose CV is defined (at least 3 spikes); neurons with a nan CV are ignored [1].

Parameters:
  • prediction (Any) – Model spikes.

  • target (Any) – Data spikes; the neuron counts may differ.

Returns:

Scalar loss (dimensionless). nan if every neuron of either input has an undefined CV.

Return type:

Array

Raises:

TypeError – If an input is not a SpikeTrains.

Notes

Works under jax.jit and jax.vmap and is differentiable with respect to the spike times; the ignored neurons contribute neither value nor nan gradient.

References

Examples

>>> import jax.numpy as jnp
>>> from braintools.fit import losses
>>> from braintools.spike import SpikeTrains
>>> regular = jnp.zeros((100, 3)).at[::10].set(1.)    # CV 0
>>> bursty = jnp.zeros((100, 3)).at[jnp.array([0, 2, 6]), :2].set(1.)
>>> pred = SpikeTrains.from_dense(regular, dt=1.)
>>> target = SpikeTrains.from_dense(bursty, dt=1.)    # CV 1/3; neuron 2 is silent
>>> round(float(losses.cv_loss(pred, target)), 6)
0.111111