victor_purpura_distance#
- class braintools.metric.victor_purpura_distance(spike_times_1, spike_times_2, cost_factor=1.0)#
Calculate Victor-Purpura distance between two spike trains.
The Victor-Purpura distance quantifies the dissimilarity between two spike trains by computing the minimum cost to transform one spike train into another through spike insertions, deletions, and temporal shifts.
The distance is computed as:
\[D_{VP} = \min \sum_{ops} c_{op}\]where the cost of moving a spike by time \(\Delta t\) is \(q|\Delta t|\), insertion/deletion costs are 1, and \(q\) is the cost factor.
- Parameters:
spike_times_1 (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – First spike train as array of spike times.spike_times_2 (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Second spike train as array of spike times.cost_factor (
float) – Cost factor \(q\) for temporal shifts. Higher values penalize temporal differences more heavily.
- Returns:
Victor-Purpura distance between the two spike trains.
- Return type:
Notes
This function runs on host (concrete) arrays: it fills a dynamic-programming table with Python loops and
lenand returns a Pythonfloat, so it is notjit/vmap/grad-compatible.cost_factorand the spike times must use consistent units (the distance has units ofcost_factor * time + count).Examples
>>> import jax.numpy as jnp >>> import braintools >>> spikes1 = jnp.array([1.0, 2.0, 3.0]) >>> spikes2 = jnp.array([1.1, 2.1, 3.1]) >>> d = braintools.metric.victor_purpura_distance(spikes1, spikes2, cost_factor=10.0) >>> bool(d >= 0.0) True
References