Benchmarks API¶
Dataset catalog¶
anomalybench.benchmarks.catalog ¶
Dataset catalog metadata and selection utilities.
DatasetSpec ¶
Bases: TypedDict
Structured dataset entry returned by load_all_datasets.
get_dataset_functions
cached
¶
Return mapping of canonical dataset names to loader callables.
load_catalog
cached
¶
Load the dataset metadata catalog from disk.
get_dataset_metadata ¶
Return metadata for name from the catalog.
list_available_datasets ¶
Return the canonical dataset names discovered in the loaders.
resolve_dataset_names ¶
Resolve selectors into canonical dataset names.
The selectors argument accepts strings (dataset names or tag:<name>),
dictionaries with include/exclude/limit keys, metadata filters,
or iterables of those forms. None returns None to signal "all
datasets".
Loading¶
anomalybench.benchmarks.load_all_datasets ¶
Dataset loading helpers used throughout the benchmarking utilities.
load_all_datasets ¶
Load benchmark datasets by canonical name.
Raw loaders may use historical label conventions. Dataset metadata declares
source_anomaly_label and this function converts every loaded benchmark
to the public evaluation contract 1 = anomaly before returning it.
Parameters¶
names:
Optional sequence of canonical dataset identifiers (for example,
"iris"). None loads every available dataset.
Metrics¶
anomalybench.benchmarks.metrics ¶
Metric utilities for benchmark evaluation.
DEFAULT_SCORE_ORIENTATION
module-attribute
¶
Orientation applied to scores that carry no orientation metadata.
MetricConfig
dataclass
¶
Normalized benchmark metric configuration.
resolve_metric_config ¶
Normalize CLI/YAML metric configuration.
canonicalize_anomaly_scores ¶
Return scores where larger values consistently mean more anomalous.
Raw detector score semantics are preserved by detector score methods.
Benchmark evaluation uses orientation metadata carried by
BaseDetector.detect_anomalies to put heterogeneous detectors onto a
common ranking direction before computing ranking- or threshold-based
metrics.
evaluate_metrics ¶
evaluate_metrics(y_true: Any, scores: Any, *, runtime_seconds: float, config: MetricConfig | None = None) -> dict[str, float | None]
Evaluate configured benchmark metrics using canonical anomaly scores.
precision_at_k ¶
Return precision among the top-k highest scores.
recall_at_k ¶
Return recall among the top-k highest scores.
best_f1_score ¶
Return the best F1 score across precision-recall thresholds.
Reproducibility¶
anomalybench.benchmarks.reproducibility ¶
Reproducibility helpers for benchmark runs.
stable_hash ¶
Return a short SHA-256 hash for a JSON-serializable value.
package_version ¶
Return the project version without requiring an installed package.
normalize_run_id ¶
Return a user-supplied or deterministic benchmark run identifier.
seed_runtime ¶
Seed common Python and NumPy RNGs when a benchmark seed is provided.
apply_seed_to_detector_entries ¶
apply_seed_to_detector_entries(detector_entries: list[dict[str, Any]], seed: int | None) -> list[dict[str, Any]]
Add supported seed parameters to detector entries when absent.
benchmark_config_hash ¶
benchmark_config_hash(dataset_keys: list[str], detector_entries: list[dict[str, Any]], random_seed: int | None, n_jobs: int | None, metric_config: dict[str, Any] | None = None) -> str
Return the stable hash for the effective benchmark configuration.
build_manifest ¶
build_manifest(*, run_id: str, timestamp: str, config_hash: str, dataset_keys: list[str], detector_entries: list[dict[str, Any]], random_seed: int | None, n_jobs: int | None, output_directory: str | None, dataset_integrity: list[dict[str, Any]], metric_config: dict[str, Any] | None = None, dataset_metadata: list[dict[str, Any]] | None = None) -> dict[str, Any]
Build the reproducibility manifest for a benchmark run.
build_report ¶
Build a versioned benchmark report payload.
write_json ¶
Write a reproducibility payload as pretty JSON.
collect_dataset_integrity ¶
Collect integrity metadata for bundled files used by selected datasets.