AxoBench API

Spike event metrics

Signatures, parameters, return values, and source for spike event metrics.

Overview

Spike events, thresholds, one-to-one event matching, and F1 over timing tolerances, together with the coincidence factor and the historical timestep AUC and voltage RMSE. Spike arrays are (trace, time) or (time,); values above 0.5 count as events.

Source revision: 496e0c1a2dfd. Export index.

spike_event_peaks

axobench.metrics.spike_event_peaks(scores: np.ndarray, *, refractory_steps: int=2, min_score: float=-np.inf) -> np.ndarray

Source

Candidate spike events: local maxima of each trace’s score, kept greedily from the highest score down with other maxima within refractory_steps suppressed. A step is a maximum if it exceeds the previous step and is not below the next.

Parameters

scores np.ndarray
required. Spike scores, (trace, time).
refractory_steps int
keyword-only, default=2. Suppression radius in steps; 0 keeps every maximum.
min_score float
keyword-only, default=-np.inf. Maxima below this score are dropped first; this does not change which higher maxima are kept.

Returns

events np.ndarray
Boolean (trace, time) event array.

spike_events

axobench.metrics.spike_events(scores: np.ndarray, threshold: float, *, refractory_steps: int | None=2) -> np.ndarray

Source

Binary spike events: score peaks at or above the threshold, or every supra-threshold step when refractory_steps is None.

Parameters

scores np.ndarray
required. Spike scores, (trace, time).
threshold float
required. Event threshold.
refractory_steps int | None
keyword-only, default=2. Suppression radius; None disables peak detection.

Returns

events np.ndarray
Boolean (trace, time) event array.

prevalence_matched_threshold

axobench.metrics.prevalence_matched_threshold(scores: np.ndarray, positive_count: int) -> float

Source

Threshold at which the number of timesteps scoring at or above it reaches positive_count: the positive_count-th highest score. The evaluator calibrates with this function.

Parameters

scores np.ndarray
required. Scores of any shape; flattened.
positive_count int
required. Target number of positive timesteps.

Returns

threshold float
The threshold; +inf for a non-positive count and -inf when the count covers every score.

event_count_matched_threshold

axobench.metrics.event_count_matched_threshold(scores: np.ndarray, positive_count: int, *, refractory_steps: int | None=2) -> float

Source

Threshold at which spike_events yields positive_count events.

Parameters

scores np.ndarray
required. Spike scores, (trace, time).
positive_count int
required. Target number of events.
refractory_steps int | None
keyword-only, default=2. Suppression radius; None matches timesteps instead.

Returns

threshold float
The height of the positive_count-th highest score peak.

spike_event_matches

axobench.metrics.spike_event_matches(predicted_spikes: np.ndarray, target_spikes: np.ndarray, *, tolerance_steps: int) -> np.ndarray

Source

One-to-one event matches under a symmetric timing tolerance. Within each trace, events are paired in time order when they lie within the tolerance, and each event is matched at most once.

Parameters

predicted_spikes np.ndarray
required. Predicted events, (trace, time).
target_spikes np.ndarray
required. Teacher events of the same shape.
tolerance_steps int
keyword-only, required. Non-negative matching tolerance in steps.

Returns

matches np.ndarray
Integer (matches, 3) array of trace, predicted step, and teacher step.

spike_event_confusion

axobench.metrics.spike_event_confusion(predicted_spikes: np.ndarray, target_spikes: np.ndarray, *, tolerance_steps: int) -> dict[str, int]

Source

One-to-one event confusion under a symmetric timing tolerance. Within each trace, events are paired in time order when they lie within the tolerance; counts are summed over traces.

Parameters

predicted_spikes np.ndarray
required. Predicted events, (trace, time).
target_spikes np.ndarray
required. Teacher events of the same shape.
tolerance_steps int
keyword-only, required. Non-negative matching tolerance in steps.

Returns

confusion dict[str, int]
tp, fp, and fn.

spike_f1_curve

axobench.metrics.spike_f1_curve(spike_scores: np.ndarray, target_spikes: np.ndarray, *, threshold: float=0.0, tolerances_steps: tuple[int, ...] | list[int]=(0, 1, 2, 3, 4, 5), refractory_steps: int | None=2) -> dict[str, Any]

Source

Event F1 at each timing tolerance, the arithmetic Mean F1, and the trapezoidal F1 area normalized by the tolerance span.

Parameters

spike_scores np.ndarray
required. Spike scores, (trace, time).
target_spikes np.ndarray
required. Teacher spike indicators of the same shape.
threshold float
keyword-only, default=0.0. Event threshold applied to the scores.
tolerances_steps tuple[int, ...] | list[int]
keyword-only, default=(0, 1, 2, 3, 4, 5). Strictly increasing non-negative tolerances.
refractory_steps int | None
keyword-only, default=2. Suppression radius of spike_events.

Returns

curve dict[str, Any]
threshold, refractory_steps, t_min_steps, t_max_steps, mean_f1, f1_area, and rows with precision, recall, f1, tp, fp, and fn per tolerance.

coincidence_factor

axobench.metrics.coincidence_factor(predicted_spikes: np.ndarray, target_spikes: np.ndarray, *, delta_steps: int=2) -> dict[str, float | int]

Source

Coincidence factor Gamma (Kistler et al. 1997; Jolivet et al. 2008): coincidences within the tolerance minus those expected from a Poisson train at the predicted rate, normalized so that a perfect prediction scores 1 and chance about 0.

Parameters

predicted_spikes np.ndarray
required. Predicted events, (trace, time).
target_spikes np.ndarray
required. Teacher events of the same shape.
delta_steps int
keyword-only, default=2. Coincidence tolerance in steps.

Returns

result dict[str, float | int]
gamma, coincidences, expected_coincidences, predicted_spikes, target_spikes, and delta_steps.

binary_auc

axobench.metrics.binary_auc(scores: np.ndarray, labels: np.ndarray) -> float

Source

Rank-based ROC AUC with averaged tied ranks over all flattened entries.

Parameters

scores np.ndarray
required. Continuous scores.
labels np.ndarray
required. Binary labels; values above 0.5 are positive.

Returns

auc float
ROC AUC, or NaN when a class is absent.

spike_auc

axobench.metrics.spike_auc(prediction: np.ndarray, target: np.ndarray) -> float

Source

Timestep ROC AUC of channel 0 of a prediction against channel 0 of a target, the historical NeuronIO spike score.

Parameters

prediction np.ndarray
required. Array whose channel 0 holds spike scores.
target np.ndarray
required. Array whose channel 0 holds spike labels.

Returns

auc float
ROC AUC.

soma_rmse

axobench.metrics.soma_rmse(prediction: np.ndarray, target: np.ndarray) -> float

Source

RMSE of channel 1 in the supplied coordinate.

Parameters

prediction np.ndarray
required. Array whose channel 1 holds soma values.
target np.ndarray
required. Array in the same coordinate.

Returns

rmse float
Root-mean-square error.

Search guides, examples, and API signatures.