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]

Source

Corrupt teacher spikes and voltage with one defect at a dose; dose 0 returns copies.

Parameters

spikes np.ndarray
required. Binary teacher spikes, (trace, time).
soma_mv np.ndarray
required. Teacher voltage in millivolts, same shape.
defect str
required. A key of DEFECTS.
dose float
required. Defect strength in the unit of DEFECTS.
rng np.random.Generator | None
keyword-only, default=None. Random generator for the random defects; None creates an unseeded one.

Returns

spikes np.ndarray
Corrupted spikes.
soma_mv np.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]]

Source

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

spikes np.ndarray
required. Binary teacher spikes, (trace, time).
soma_mv np.ndarray
required. Teacher voltage in millivolts.
doses Mapping[str, Iterable[float]] | None
default=None. Doses per defect; None uses DEFAULT_DOSES.
seed int
keyword-only, default=0. Base seed.
ignore_start int
keyword-only, default=0. Initial steps excluded after the defect is applied.

Returns

rows list[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]

Source

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_spikes np.ndarray
required. Predicted binary spikes, (trace, time).
pred_soma_mv np.ndarray
required. Predicted voltage in millivolts.
target_spikes np.ndarray
required. Teacher spikes.
target_soma_mv np.ndarray
required. Unclipped teacher voltage in millivolts.

Returns

scores dict[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]

Source

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_spikes np.ndarray
required. Predicted binary spikes.
pred_soma_mv np.ndarray
required. Predicted voltage in millivolts.
target_spikes np.ndarray
required. Teacher spikes.
target_soma_mv np.ndarray
required. Teacher voltage in millivolts.

Returns

scores dict[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

Source

Spike train smoothed with a Gaussian, used as the ranking score of the historical AUC.

Parameters

spikes np.ndarray
required. Binary spikes.
sigma_steps float
default=1.0. Gaussian standard deviation in steps.

Returns

score np.ndarray
Smoothed score, (trace, time).

Search guides, examples, and API signatures.