braintools.analysis.stats.shuffle_isi

Contents

braintools.analysis.stats.shuffle_isi#

braintools.analysis.stats.shuffle_isi(key, trains)#

Randomly permute the inter-spike intervals of every neuron.

The intervals of each neuron are shuffled and the spike times are rebuilt from its first spike, so the first and last spikes, the spike count and the ISI distribution are preserved while the serial order of the intervals (and the alignment between neurons) is destroyed [1]. Statistics recomputed on many shuffled copies give the null distribution of a significance test (the copies are called surrogate data in the literature).

Parameters:
  • key (Array) – PRNG key, from jax.random.key or jax.random.PRNGKey.

  • trains (SpikeTrains) – Spike trains to shuffle.

Returns:

New trains with the same counts, capacity, t_start, t_stop and overflow; valid times are sorted per neuron and padding stays +inf at the end. Neurons with fewer than 3 spikes are unchanged.

Return type:

SpikeTrains

Raises:

TypeError – If trains is not a SpikeTrains.

See also

jitter_spikes

Randomise spike times locally.

Notes

Each neuron gets its own key (jax.random.split) and a jax.random.permutation of its K - 1 interval slots; a stable sort then moves the valid intervals to the front, which leaves the padding at the end. The times are rebuilt with a cumulative sum, so they carry float round-off of the order of eps * t; they never pass the original last spike. Works under jax.jit and jax.vmap (vmapping over keys gives independent copies). Not intended for differentiation.

References

Examples

>>> import jax
>>> import jax.numpy as jnp
>>> from braintools.spike import SpikeTrains
>>> from braintools.analysis.stats import shuffle_isi
>>> raster = jnp.zeros((20, 1)).at[jnp.array([0, 1, 3, 7, 15]), 0].set(1.)
>>> st = SpikeTrains.from_dense(raster, dt=1.)
>>> shuffled = shuffle_isi(jax.random.key(0), st)
>>> sorted(jnp.diff(shuffled.times[0]).tolist())
[1.0, 2.0, 4.0, 8.0]
>>> float(shuffled.times[0, 0]), float(shuffled.times[0, -1])
(0.0, 15.0)