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 ¶
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 |
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]]
|
|
required |
data
|
Iterable
|
A re-iterable batch source (e.g. a |
required |
task
|
str or Task
|
A registered task name ( |
'classification'
|
num_classes
|
int or None
|
Required (when |
None
|
predict_fn
|
callable or None
|
|
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
|
None
|
prob_metrics
|
frozenset[str] or None
|
Battery entries fed probabilities instead of hard predictions. |
None
|
test
|
str
|
Statistical test for pairwise method comparison: |
'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'
|
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 |
comparisons |
DataFrame
|
Pairwise significance results (see |
alpha |
float
|
Significance level used. |
summary ¶
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 |
prob_metrics |
frozenset[str]
|
The metric names that consume probabilities rather than predictions. |
requires_num_classes |
bool
|
Whether the battery needs |
description |
str
|
Shown by |
update_fn |
UpdateFn | None
|
Replaces the default metric update when the battery takes grouped
inputs (retrieval), forwarded even when |
register_task ¶
Register task under name so compare(task=name) and
Study(task=name) can look it up. Set overwrite=True to replace an
existing entry.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.