Skip to content

benchmark

Statistics over a sweep's dataset, and the evaluation tasks and metric batteries that compare runs. Everything here needs the eval extra (pip install "mushin-py[eval]"). The Comparing methods guide shows compare_methods and compare in use; the batteries guide shows the batteries and the task registry.

compare_methods

compare_methods(
    ds,
    test="wilcoxon",
    alpha=0.05,
    correction="holm",
    allow_incomplete=False,
)

Pairwise comparison of methods for every metric in ds.

correction (one of available_corrections: "holm" default, "bonferroni", "fdr_bh" for Benjamini-Hochberg FDR, "none" for raw p-values) is applied per metric across the method pairs; the family is one metric's pairs, not the whole battery, so scanning for "significant on any metric" across a large battery still inflates family-wise error. A method whose scores are constant across all seeds (for a metric) has no sampling distribution, so comparisons involving it are masked; p_value, p_corrected and effect_size become NaN and significant is False, rather than reporting a duplicated-point p-value of ~0 and a meaningless ±huge effect size; Holm is then applied over the surviving pairs. Emits a warning when test cannot reach alpha at the dataset's seed count for the family of pairs that correction adjusts (under Holm, the three pairs of three methods need a seventh Wilcoxon seed), and when a method is constant across seeds in every metric.

allow_incomplete (default False): when True, an incomplete sweep is compared anyway (with a warning) instead of raising, computing stats over only the completed cells. Use it for exploratory analysis of a sample= or budget-limited sweep; the result may be under-powered or biased.

Raises:

Type Description
IncompleteSweepError

If ds.attrs["mushin_failures"] or ds.attrs["mushin_skipped"] is a non-empty list: the sweep that produced ds had failed runs (recorded under on_error="nan") or cells that were never run (skipped by a sample= subset or an exhausted max_total_seconds budget), unless allow_incomplete=True. A dataset without those attrs (a plain user dataset or a clean, fully-completed sweep) is unaffected. This is keyed purely on the completeness signals, never on raw NaN values in the data, so a metric that is legitimately NaN for other reasons does not trigger it.

IncompleteSweepError

Bases: RuntimeError

Raised when statistics are requested on a sweep that has failed/missing runs.

compare

compare(
    methods,
    data,
    task="classification",
    *,
    num_classes=None,
    predict_fn=None,
    metrics=None,
    prob_metrics=None,
    test="wilcoxon",
    alpha=0.05,
    correction="holm",
    ignore_index=None,
    device=None,
)

Compare methods on a standard battery and report significance.

Parameters:

Name Type Description Default
methods dict[str, Sequence[Module]]

{method_name: [model_per_seed, ...]}; every model is evaluated on data, giving one score per (method, seed).

required
data Iterable

A re-iterable batch source (e.g. a DataLoader); it is streamed once per model.

required
task str or Task

A registered task name ("classification", "segmentation", "detection", "regression", "retrieval", "image_quality", "audio", or a custom one, listed by list_tasks()) or a Task object.

'classification'
num_classes int or None

Required (when metrics is not provided) only for tasks whose battery needs it ("classification" and "segmentation"), and ignored for the others.

None
predict_fn callable or None

(model, x) -> (preds, probs); defaults to the task's.

None
metrics dict[str, Metric] or None

Replaces the task's battery entirely. A custom battery gets no implicit probability routing, so name the probability-consuming entries in prob_metrics.

None
prob_metrics frozenset[str] or None

Battery entries fed probabilities instead of hard predictions. None means the task's own set when the task's battery is used, and the empty set when a custom metrics= battery is given. Every name must be a key of the battery in use.

None
test str

Statistical test for pairwise method comparison: "wilcoxon" (paired Wilcoxon, the default), "ttest_rel", "welch", "ttest_ind" or "mannwhitney".

'wilcoxon'
alpha float

Significance level for the (multiple-comparison-corrected) comparisons.

0.05
correction str

Multiple-comparison correction applied per metric across method pairs: "holm" (default), "bonferroni", "fdr_bh" (Benjamini-Hochberg FDR), or "none" for raw p-values.

'holm'
ignore_index int or None

Label to exclude from segmentation metrics (e.g. a void/boundary class).

None
device device or None

Evaluation device; defaults to the device of each model's parameters.

None

BenchmarkResult dataclass

Holds benchmark results.

Attributes:

Name Type Description
data Dataset

Dims (method, seed), one data variable per metric.

comparisons DataFrame

Pairwise significance results (see _stats.compare_methods).

alpha float

Significance level used.

summary

summary(reference=None)

Publication-ready table: per method/metric mean and CI, with a "*" marker when the method differs significantly from reference (default: the first method in data).

Tasks

A task bundles a metric battery with the code that produces predictions for it, under a name compare(task=...) accepts.

Task dataclass

A reusable evaluation task, registered under a name that compare(task=...) accepts.

Attributes:

Name Type Description
battery Callable[..., dict[str, Metric]]

Builds the task's metric collection (one of the battery factories).

predict_fn PredictFn

Extracts (predictions, probabilities) from a model and a batch.

prob_metrics frozenset[str]

The metric names that consume probabilities rather than predictions.

requires_num_classes bool

Whether the battery needs num_classes (classification and segmentation do; detection, regression, retrieval and the paired batteries do not).

description str

Shown by list_tasks.

update_fn UpdateFn | None

Replaces the default metric update when the battery takes grouped inputs (retrieval), forwarded even when metrics= overrides the battery.

register_task

register_task(name, task, *, overwrite=False)

Register task under name so compare(task=name) and Study(task=name) can look it up. Set overwrite=True to replace an existing entry.

get_task

get_task(task)

Look up a registered task by name.

list_tasks

list_tasks()

Return {name: description} for every registered task, name-sorted.

Batteries

Each battery returns a dict of named torchmetrics metrics. The detection, image-quality and audio batteries need their own extras (detection, image, audio), as their docstrings say.

classification_battery

classification_battery(num_classes, ignore_index=None)

The standard multiclass classification battery. ignore_index is accepted for a uniform task interface but is not applied here (the battery's AUROC/ECE do not support it).

regression_battery

regression_battery(num_classes=None, ignore_index=None)

Scalar-regression battery. num_classes/ignore_index are accepted for the uniform task interface but unused. This is a SINGLE-TARGET battery: predictions and targets are continuous tensors of shape (N,) or (N, 1). Multi-output targets (N, D>1) are not supported here; pearson/ spearman are built with num_outputs=1 and raise on D>1; use a custom Task with num_outputs=D for multi-output regression.

segmentation_battery

segmentation_battery(num_classes, ignore_index=None)

Semantic-segmentation battery over per-pixel class labels. dice is the macro F1 (the Dice coefficient); all metrics are confusion-matrix based, so streaming evaluation uses O(C^2) memory.

detection_battery

detection_battery(num_classes=None, ignore_index=None)

The bounding-box detection battery: mean-average-precision plus the IoU variants, every scalar output surfaced as its own metric. num_classes and ignore_index are accepted for the uniform task interface but unused (mAP infers classes from the labels). Requires the optional detection extra.

retrieval_battery

retrieval_battery(num_classes=None, ignore_index=None)

Information-retrieval battery over grouped (per-query) predictions. num_classes/ignore_index are accepted for the uniform interface but unused. Batches must yield y = (relevance, indexes); see retrieval_update. relevance must be BINARY (0/1) for retrieval_map/ mrr/precision/recall (they raise on graded values); only ndcg accepts graded relevance. For graded judgments, use a custom Task with just the graded-capable metrics (e.g. RetrievalNormalizedDCG).

image_quality_battery

image_quality_battery(num_classes=None, ignore_index=None)

Paired image-quality battery (generated vs reference image). Requires the optional image extra (LPIPS pulls in torchvision + lpips). num_classes/ ignore_index are accepted for the uniform interface but unused. Images are (N, C, H, W); data_range=1.0 assumes inputs in [0, 1] and LearnedPerceptualImagePatchSimilarity(normalize=True) accepts that range. Note ms_ssim requires H, W > 160 (torchmetrics default 5 scales / kernel 11); for smaller images drop ms_ssim or pass a custom MultiScaleStructuralSimilarityIndexMeasure with fewer betas.

audio_battery

audio_battery(num_classes=None, ignore_index=None)

Speech/audio battery (estimated vs reference waveform). Requires the optional audio extra (STOI needs pystoi). SI-SDR/SI-SNR are core, but the battery is all-or-nothing. num_classes/ignore_index are accepted for the uniform interface but unused. Waveforms are (N, T); STOI assumes a 16 kHz sample rate (override via a custom Task for other rates).

PESQ is intentionally omitted: every pesq release (the latest is 0.0.4, 2022) is source-only and needs a C compiler to install, so it cannot be bundled reliably. With a compiler it builds and runs under NumPy 2; add it via a custom Task if needed.