AxoBench API
Defect injection
Signatures, parameters, return values, and source for defect injection.
Overview
Controlled defects injected into teacher traces, for testing whether a metric responds to a known error as it should. Spike-timing defects move the action-potential waveform with the spike; voltage defects leave the spike train exact. Import from axobench.benchmark.defect_injection. See test metric sensitivity.
Source revision: 496e0c1a2dfd. Export index.
Constants
DEFECTS = {'spike_jitter', 'spike_deletion', 'spike_insertion', 'global_lag', 'ap_clip', 'ap_smoothing', 'voltage_lowpass', 'voltage_offset', 'voltage_gain', 'post_spike'}- Defect names and the unit of their dose. Source
DEFAULT_DOSES = {'spike_jitter', 'spike_deletion', 'spike_insertion', 'global_lag', 'ap_clip', 'ap_smoothing', 'voltage_lowpass', 'voltage_offset', 'voltage_gain', 'post_spike'}- Doses scored by defect_dose_rows when none are given. Source
inject_defect
axobench.benchmark.defect_injection.inject_defect(spikes: np.ndarray, soma_mv: np.ndarray, defect: str, dose: float, *, rng: np.random.Generator | None=None) -> tuple[np.ndarray, np.ndarray]
Corrupt teacher spikes and voltage with one defect at a dose; dose 0 returns copies.
Parameters
spikesnp.ndarray- required. Binary teacher spikes, (trace, time).
soma_mvnp.ndarray- required. Teacher voltage in millivolts, same shape.
defectstr- required. A key of DEFECTS.
dosefloat- required. Defect strength in the unit of DEFECTS.
rngnp.random.Generator | None- keyword-only, default=None. Random generator for the random defects; None creates an unseeded one.
Returns
spikesnp.ndarray- Corrupted spikes.
soma_mvnp.ndarray- Corrupted voltage.
defect_dose_rows
axobench.benchmark.defect_injection.defect_dose_rows(spikes: np.ndarray, soma_mv: np.ndarray, doses: Mapping[str, Iterable[float]] | None=None, *, seed: int=0, ignore_start: int=0) -> list[dict[str, Any]]
Score every defect at every dose against the uncorrupted teacher with both the historical NeuronIO scores and the AxoBench scores. Each defect’s generator is seeded from seed and the defect name.
Parameters
spikesnp.ndarray- required. Binary teacher spikes, (trace, time).
soma_mvnp.ndarray- required. Teacher voltage in millivolts.
dosesMapping[str, Iterable[float]] | None- default=None. Doses per defect; None uses DEFAULT_DOSES.
seedint- keyword-only, default=0. Base seed.
ignore_startint- keyword-only, default=0. Initial steps excluded after the defect is applied.
Returns
rowslist[dict[str, Any]]- defect, dose, spike counts, historical_scores fields, and axobench_scores fields per defect and dose.
axobench_scores
axobench.benchmark.defect_injection.axobench_scores(pred_spikes: np.ndarray, pred_soma_mv: np.ndarray, target_spikes: np.ndarray, target_soma_mv: np.ndarray) -> dict[str, Any]
AxoBench scores of a prediction against unclipped teacher voltage and spikes: Voltage and Dynamics SERA with skill against the per-trace teacher mean, subthreshold RMSE and skill, the F1 curve at 0 to 5 steps with Mean F1, and the coincidence factor at 2 steps. Predicted spikes are used as events directly.
Parameters
pred_spikesnp.ndarray- required. Predicted binary spikes, (trace, time).
pred_soma_mvnp.ndarray- required. Predicted voltage in millivolts.
target_spikesnp.ndarray- required. Teacher spikes.
target_soma_mvnp.ndarray- required. Unclipped teacher voltage in millivolts.
Returns
scoresdict[str, Any]- voltage_sera, voltage_skill, dynamics_sera, dynamics_skill, subthreshold_rmse_mv, subthreshold_skill, f1_curve, mean_f1, and gamma_2.
historical_scores
axobench.benchmark.defect_injection.historical_scores(pred_spikes: np.ndarray, pred_soma_mv: np.ndarray, target_spikes: np.ndarray, target_soma_mv: np.ndarray) -> dict[str, float]
NeuronIO-protocol scores: timestep AUC of the Gaussian-smoothed predicted spike train, and the RMSE of voltages clipped at -55 mV with and without rescaling the prediction to the target’s mean and standard deviation.
Parameters
pred_spikesnp.ndarray- required. Predicted binary spikes.
pred_soma_mvnp.ndarray- required. Predicted voltage in millivolts.
target_spikesnp.ndarray- required. Teacher spikes.
target_soma_mvnp.ndarray- required. Teacher voltage in millivolts.
Returns
scoresdict[str, float]- auc, clipped_rmse_aligned_mv, and clipped_rmse_mv.
smoothed_spike_score
axobench.benchmark.defect_injection.smoothed_spike_score(spikes: np.ndarray, sigma_steps: float=1.0) -> np.ndarray
Spike train smoothed with a Gaussian, used as the ranking score of the historical AUC.
Parameters
spikesnp.ndarray- required. Binary spikes.
sigma_stepsfloat- default=1.0. Gaussian standard deviation in steps.
Returns
scorenp.ndarray- Smoothed score, (trace, time).