correlation_index

correlation_index#

class braintools.metric.correlation_index(spike_matrix, window_size, dt=None)#

Calculate correlation index for spike train synchrony.

The correlation index measures the strength of pairwise correlations in spike trains by computing correlation coefficients between binned spike counts.

The index is computed as:

\[CI = \frac{1}{N(N-1)} \sum_{i \neq j} \rho_{ij}\]

where \(\rho_{ij}\) is the Pearson correlation coefficient between the binned spike counts of neurons i and j.

Parameters:
  • spike_matrix (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Spike matrix with shape (n_time_steps, n_neurons).

  • window_size (float) – Size of time windows for binning spikes (in time units).

  • dt (float) – Time step between successive samples. If None, uses brainstate default.

Returns:

Correlation index representing average pairwise correlation. Values range from -1 to 1, where positive values indicate synchrony.

Return type:

float

Examples

>>> import jax.numpy as jnp
>>> import braintools as braintools
>>> # Create correlated spike trains
>>> spikes = (jnp.random.random((1000, 10)) < 0.1).astype(float)
>>> # Add some correlation by copying spikes between neurons
>>> spikes = spikes.at[:, 1].set(spikes[:, 0] * 0.7 + spikes[:, 1] * 0.3)
>>> ci = braintools.metric.correlation_index(spikes, window_size=50.0)
>>> print(f"Correlation index: {ci:.3f}")