spike_train_synchrony#
- class braintools.analysis.spike.spike_train_synchrony(spike_matrix, window_size, dt=None)#
Calculate spike train synchrony using the SPIKE-synchronization measure.
This measure quantifies the degree of synchronization between multiple spike trains by counting coincident events within sliding time windows and normalizing by the total number of possible coincidences [1].
The synchrony index is the average over neuron pairs of a symmetric coincidence ratio:
\[S = \frac{1}{N_{pairs}} \sum_{i < j} \frac{C_{i \to j} + C_{j \to i}}{N_i + N_j}\]where \(C_{i \to j}\) is the number of spikes in train \(i\) that have at least one spike of train \(j\) within half the coincidence window, and \(N_i\) is the number of spikes in train \(i\). Counting coincidences in both directions and normalizing by the total spike count guarantees \(S \in [0, 1]\). Pairs with a silent neuron are left out of the average.
- Parameters:
spike_matrix (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Spike matrix with shape(n_time_steps, n_neurons)where non-zero values indicate spike occurrences.window_size (
float) – Full width of the coincidence-detection window. Two spikes are coincident when they are at mostwindow_size / 2apart. Must use the same time unit asdt.dt (
float|None) – Time step between successive samples. If None, uses the default frombrainstate.environ.get_dt(). A plain float is assumed to be in milliseconds (thebrainstateconvention), so it must be expressed in the same unit aswindow_size/max_isi/tau; abrainunit.Quantityis converted automatically.
- Returns:
Spike train synchrony index, a 0-d array between 0 (no synchrony) and 1 (perfect synchrony). 0 when fewer than two neurons, or no pair of active neurons, are present.
- Return type:
jax.Array
Notes
The coincidences of all pairs are counted at once: a cumulative sum marks the samples within
window_size / 2of a spike of each neuron, a matrix product counts, for every ordered pair, the spikes of one neuron on the marked samples of the other, and the pair ratios are evaluated with avmapover theN (N - 1) / 2upper-triangle pairs. Memory isO(T N + N^2).window_sizeanddtmust be concrete; the spike matrix may be traced, so the function works underjax.jitandjax.vmap(e.g. over trials). It is not differentiable (it counts spikes).Before version 0.4 this function returned a Python
float;float(s)still works on the 0-d array.Examples
>>> import jax.numpy as jnp >>> import braintools as braintools >>> # Create synchronized spikes >>> spikes = jnp.zeros((100, 5)) >>> spikes = spikes.at[20:25, :].set(1) # Synchronized burst >>> synchrony = braintools.analysis.spike.spike_train_synchrony(spikes, window_size=10.0, dt=1.0) >>> print(f"Synchrony: {synchrony:.3f}") Synchrony: 1.000
References