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, fromjax.random.keyorjax.random.PRNGKey.trains (
SpikeTrains) – Spike trains to shuffle.
- Returns:
New trains with the same
counts, capacity,t_start,t_stopandoverflow; valid times are sorted per neuron and padding stays+infat the end. Neurons with fewer than 3 spikes are unchanged.- Return type:
- Raises:
TypeError – If
trainsis not aSpikeTrains.
See also
jitter_spikesRandomise spike times locally.
Notes
Each neuron gets its own key (
jax.random.split) and ajax.random.permutationof itsK - 1interval 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 ofeps * t; they never pass the original last spike. Works underjax.jitandjax.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)