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
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
scoresnp.ndarray- required. Spike scores, (trace, time).
refractory_stepsint- keyword-only, default=2. Suppression radius in steps; 0 keeps every maximum.
min_scorefloat- keyword-only, default=-np.inf. Maxima below this score are dropped first; this does not change which higher maxima are kept.
Returns
eventsnp.ndarray- Boolean (trace, time) event array.
spike_events
axobench.metrics.spike_events(scores: np.ndarray, threshold: float, *, refractory_steps: int | None=2) -> np.ndarray
Binary spike events: score peaks at or above the threshold, or every supra-threshold step when refractory_steps is None.
Parameters
scoresnp.ndarray- required. Spike scores, (trace, time).
thresholdfloat- required. Event threshold.
refractory_stepsint | None- keyword-only, default=2. Suppression radius; None disables peak detection.
Returns
eventsnp.ndarray- Boolean (trace, time) event array.
prevalence_matched_threshold
axobench.metrics.prevalence_matched_threshold(scores: np.ndarray, positive_count: int) -> float
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
scoresnp.ndarray- required. Scores of any shape; flattened.
positive_countint- required. Target number of positive timesteps.
Returns
thresholdfloat- 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
Threshold at which spike_events yields positive_count events.
Parameters
scoresnp.ndarray- required. Spike scores, (trace, time).
positive_countint- required. Target number of events.
refractory_stepsint | None- keyword-only, default=2. Suppression radius; None matches timesteps instead.
Returns
thresholdfloat- 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
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_spikesnp.ndarray- required. Predicted events, (trace, time).
target_spikesnp.ndarray- required. Teacher events of the same shape.
tolerance_stepsint- keyword-only, required. Non-negative matching tolerance in steps.
Returns
matchesnp.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]
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_spikesnp.ndarray- required. Predicted events, (trace, time).
target_spikesnp.ndarray- required. Teacher events of the same shape.
tolerance_stepsint- keyword-only, required. Non-negative matching tolerance in steps.
Returns
confusiondict[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]
Event F1 at each timing tolerance, the arithmetic Mean F1, and the trapezoidal F1 area normalized by the tolerance span.
Parameters
spike_scoresnp.ndarray- required. Spike scores, (trace, time).
target_spikesnp.ndarray- required. Teacher spike indicators of the same shape.
thresholdfloat- keyword-only, default=0.0. Event threshold applied to the scores.
tolerances_stepstuple[int, ...] | list[int]- keyword-only, default=(0, 1, 2, 3, 4, 5). Strictly increasing non-negative tolerances.
refractory_stepsint | None- keyword-only, default=2. Suppression radius of spike_events.
Returns
curvedict[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]
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_spikesnp.ndarray- required. Predicted events, (trace, time).
target_spikesnp.ndarray- required. Teacher events of the same shape.
delta_stepsint- keyword-only, default=2. Coincidence tolerance in steps.
Returns
resultdict[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
Rank-based ROC AUC with averaged tied ranks over all flattened entries.
Parameters
scoresnp.ndarray- required. Continuous scores.
labelsnp.ndarray- required. Binary labels; values above 0.5 are positive.
Returns
aucfloat- ROC AUC, or NaN when a class is absent.
spike_auc
axobench.metrics.spike_auc(prediction: np.ndarray, target: np.ndarray) -> float
Timestep ROC AUC of channel 0 of a prediction against channel 0 of a target, the historical NeuronIO spike score.
Parameters
predictionnp.ndarray- required. Array whose channel 0 holds spike scores.
targetnp.ndarray- required. Array whose channel 0 holds spike labels.
Returns
aucfloat- ROC AUC.
soma_rmse
axobench.metrics.soma_rmse(prediction: np.ndarray, target: np.ndarray) -> float
RMSE of channel 1 in the supplied coordinate.
Parameters
predictionnp.ndarray- required. Array whose channel 1 holds soma values.
targetnp.ndarray- required. Array in the same coordinate.
Returns
rmsefloat- Root-mean-square error.