braintools.analysis.spike.fano_factor#
- braintools.analysis.spike.fano_factor(x, bin_size=None, axis=0, *, n_bins=None)#
Compute the Fano factor, the variance-to-mean ratio of spike counts.
\[F = \frac{\operatorname{Var}[n]}{\operatorname{E}[n]},\]with the population variance (
ddof=0) [1].If
xis aSpikeTrains, it is binned withbin()into whole bins of widthbin_sizestarting att_start, and the ratio is taken across the bins, separately for every neuron. A partial bin at the end of the recording is dropped, because its lower count would inflate the variance.Otherwise
xis an array of spike counts, and the ratio is taken alongaxis(typically trials).
- Parameters:
x (
Any) – Spike trains, or spike counts with the trials onaxis.bin_size (
Any) – Bin width; required for aSpikeTrains, and must be None for a count array. A plain number is in milliseconds.axis (
int) – Axis of the count array along which the ratio is computed. Ignored for aSpikeTrains.n_bins (
int|None) – Number of bins for aSpikeTrains. Defaults to the number of whole bins,floor(duration / bin_size)(a duration that is a multiple ofbin_sizeup to float round-off keeps its last bin). The default needs concretet_startandt_stop; passn_binsexplicitly when the trains are traced (e.g. an argument of ajax.jit-compiled function). An explicit value is used as given, so bins pastt_stop(partial or empty) are included.
- Returns:
For a
SpikeTrains, shape(N,); for a count array, the shape ofxwithoutaxis.nanwhere the mean count is 0, and for aSpikeTrainsshorter than one bin.- Return type:
Array- Raises:
ValueError – If
bin_sizeis missing for aSpikeTrainsor given for a count array, ifbin_sizeis not positive, or ifn_binsis missing for tracedt_start/t_stop.TypeError – If the count array is a Quantity with a physical unit.
See also
braintools.spike.SpikeTrains.binThe binning used for spike trains.
cvThe analogous statistic of the intervals.
Notes
For a Poisson process the Fano factor is 1 for every bin width. The count-array path matches
elephant.statistics.fanofactorapplied to one spike train per trial (which computescounts.var() / counts.mean()). Works underjax.jitandjax.vmap; the count-array path is differentiable with respect to the counts.References
Examples
>>> import brainunit as u >>> import jax.numpy as jnp >>> from braintools.spike import SpikeTrains >>> from braintools.analysis.spike import fano_factor >>> raster = jnp.zeros((8, 2)).at[jnp.array([0, 1, 2, 4]), 0].set(1).at[::2, 1].set(1) >>> st = SpikeTrains.from_dense(raster, dt=1. * u.ms) >>> fano_factor(st, bin_size=2. * u.ms) Array([0.5, 0. ], dtype=float32) >>> >>> fano_factor(jnp.array([[3., 1.], [5., 1.], [4., 1.]]), axis=0) Array([0.16666667, 0. ], dtype=float32)