sparx.spiketrains
Statistics of and distances between spike trains, for comparing networks that cannot match spike for spike.
Spikes are [steps, neurons] arrays of 0 and 1 (or booleans) at step dt
ms. These read a finished run (a sparx.graph.simulate record, a reference
simulator’s output) and have no gradient. The module imports NumPy alone,
so the fixture tools (tools/make_brunel_fixtures.py,
tools/make_brian2_benchmarks.py) load this file in a NEST or Brian2
environment without JAX or sparx, and the statistics they record for the
reference are the code the tests apply to sparx.
Van Rossum’s distance (sparx.losses.van_rossum) also compares spike
trains. It lives in sparx.losses because it is written in JAX to train a
network by its gradient, as sparx.objectives.ActivityFitObjective does; here it would make
the tools above load JAX. The split is by use: a differentiable training
target is a loss, a measurement of a finished run is here.
Contents
Section titled “Contents”| Name | |
|---|---|
coincidence_factor | Each neuron’s coincidence factor Γ, how well its spikes in spikes predict those in reference, both [steps, neurons] at step dt ms, with a precision of window ms. |
cv_isi | The coefficient of variation of each neuron’s interspike intervals, for neurons with at least minimum intervals; 1 for a Poisson process, 0 for a clock. |
population_fano | The Fano factor of the population’s spike count in windows of window ms. |
rates_hz | Each neuron’s mean rate in Hz, over a run of dt ms steps. |
spike_steps | Each neuron’s spike steps. |
victor_purpura | Victor and Purpura’s (J. Neurophysiol. 1996) distance between two spike trains (times in ms). |
coincidence_factor
Section titled “coincidence_factor”def coincidence_factor(spikes: np.ndarray, reference: np.ndarray, dt: float, window: float) -> np.ndarrayEach neuron’s coincidence factor Γ, how well its spikes in spikes predict those in reference,
both [steps, neurons] at step dt ms, with a precision of window ms.
Γ = (N_coinc - 2 nu Δ N_ref) / (½ (N + N_ref) (1 - 2 nu Δ))N_coinc counts the reference’s spikes with one of the neuron’s within
Δ, window rounded to steps, and nu = N / duration is the rate of
the neuron in spikes, so 2 nu Δ N_ref is what a Poisson train of that
rate meets by chance. Γ is 1 for the same spikes, 0 on average for a
Poisson train, and below 0 for fewer coincidences than chance. This is
Jolivet and Gerstner’s (J. Physiol. Paris 2004, eq. 13) form of Kistler
et al.’s (Neural Comput. 1997) measure, the score of spike-time
prediction in Jolivet et al.’s (J. Neurosci. Methods 2008) benchmark.
brian2modelfitting’s get_gamma_factor counts the same coincidences
and takes nu from the reference; the two agree where the counts do.
A neuron silent in both trains has none (NaN).
cv_isi
Section titled “cv_isi”def cv_isi(spikes: np.ndarray, minimum: int = 3) -> np.ndarrayThe coefficient of variation of each neuron’s interspike intervals, for neurons with at least
minimum intervals; 1 for a Poisson process, 0 for a clock.
population_fano
Section titled “population_fano”def population_fano(spikes: np.ndarray, dt: float, window: float = 1.0) -> floatThe Fano factor of the population’s spike count in windows of window ms.
Near 1 when neurons fire independently (Brunel’s asynchronous states), far above 1 when they fire together (his synchronous states).
rates_hz
Section titled “rates_hz”def rates_hz(spikes: np.ndarray, dt: float) -> np.ndarrayEach neuron’s mean rate in Hz, over a run of dt ms steps.
sparx.rates.firing_rates reads a different quantity during training,
each layer’s mean rate in spikes per step from the sown collection.
spike_steps
Section titled “spike_steps”def spike_steps(spikes: np.ndarray) -> list[np.ndarray]Each neuron’s spike steps.
victor_purpura
Section titled “victor_purpura”def victor_purpura(times_a: np.ndarray, times_b: np.ndarray, cost: float) -> floatVictor and Purpura’s (J. Neurophysiol. 1996) distance between two spike trains (times in ms).
The cheapest way to turn one train into the other, at 1 to add or remove
a spike and cost per ms to move one: cost = 0 counts the difference
in spike counts, a large cost counts unmatched spikes. Computed by
their dynamic program, O(len(a) len(b)); not differentiable.