evalsuite-python 0.7.0__tar.gz → 0.7.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/CHANGELOG.md +37 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/PKG-INFO +44 -40
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/README.md +43 -39
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/Cargo.lock +2 -2
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/Cargo.toml +1 -1
- evalsuite_python-0.7.1/rust/evalsuite-core/src/curve.rs +250 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-core/src/groups.rs +14 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-core/src/lib.rs +4 -0
- evalsuite_python-0.7.1/rust/evalsuite-core/src/permutation.rs +92 -0
- evalsuite_python-0.7.1/rust/evalsuite-core/src/qa.rs +97 -0
- evalsuite_python-0.7.1/rust/evalsuite-core/src/ranks.rs +99 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-core/src/resample.rs +3 -3
- evalsuite_python-0.7.1/rust/evalsuite-core/src/surface.rs +287 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-py/src/lib.rs +242 -1
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/classification/metrics.py +11 -4
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/llmsys/agents.py +6 -1
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/llmsys/safety.py +29 -5
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/stats/_resolve.py +73 -1
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/stats/intervals.py +20 -3
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/qa.py +25 -2
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/reasoning.py +18 -5
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/version.py +1 -1
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/vision/segmentation.py +17 -1
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/test_native.py +145 -1
- evalsuite_python-0.7.0/rust/evalsuite-core/src/curve.rs +0 -118
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/CONTRIBUTING.md +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/LICENSE +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/LICENSE-APACHE +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/pyproject.toml +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-core/Cargo.toml +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-core/README.md +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-core/src/agreement.rs +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-core/src/coco.rs +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-core/src/hash.rs +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-core/src/meteor.rs +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-core/src/ter.rs +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-core/src/text.rs +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/rust/evalsuite-py/Cargo.toml +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/__main__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/_bench_metrics.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/_lazy.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/_native.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/api.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/benchmarks.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/calibration.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/classification/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/classification/_common.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/cli/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/cli/main.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/clinical/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/clinical/metrics.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/clinical/report.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/core/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/core/context.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/core/exceptions.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/core/export.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/core/registry.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/core/result.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/core/types.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/core/validation.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/llmsys/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/llmsys/_common.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/llmsys/code.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/llmsys/efficiency.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/llmsys/longcontext.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/llmsys/multilingual.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/llmsys/robustness.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/llmsys/uncertainty.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/plot.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/py.typed +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/regression/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/regression/metrics.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/reporting.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/stats/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/stats/compare.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/stats/effect.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/stats/hypothesis.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/stats/paired.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/stats/results.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/_common.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/factuality.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/generation.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/judge.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/rag.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/report.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/retrieval.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/semantic.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/spice.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/text/structured.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/vision/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/src/evalsuite/vision/detection.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/classification/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/classification/test_against_sklearn.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/clinical/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/clinical/test_outputs.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/clinical/test_v020.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/conftest.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/integration/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/integration/test_qa.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/integration/test_readme_examples.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/integration/test_repo_hygiene.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/llmsys/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/llmsys/test_code_longcontext_efficiency.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/llmsys/test_edges.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/llmsys/test_fast_text.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/llmsys/test_hardening.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/llmsys/test_safety_robustness.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/llmsys/test_uncertainty_agents_multilingual.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/output/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/output/test_benchmarks.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/output/test_cli.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/output/test_plot.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/output/test_reporting.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/regression/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/regression/test_against_sklearn.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/stats/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/stats/test_branches.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/stats/test_compare.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/stats/test_fast_paths.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/stats/test_reference.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/text/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/text/test_against_references.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/text/test_text_edges.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/text/test_v040.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/unit/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/unit/test_core.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/unit/test_edges.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/vision/__init__.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/vision/test_detection.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/vision/test_edges.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/vision/test_outputs.py +0 -0
- {evalsuite_python-0.7.0 → evalsuite_python-0.7.1}/tests/vision/test_segmentation.py +0 -0
|
@@ -6,6 +6,43 @@ All notable changes to this project are documented here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.7.1] - 2026-11-25
|
|
10
|
+
|
|
11
|
+
More statistics, vision and QA work in the compiled core. Every default result is unchanged (bit-identical to
|
|
12
|
+
the Python fallback, checked by `tests/test_native.py`); the new `resampling="native"` option of
|
|
13
|
+
`weat_effect_size` is opt-in.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- **Bootstrap of ROC AUC and average precision** (`bootstrap_ci`, `paired_bootstrap_test`, `compare`): every
|
|
17
|
+
resample's curve in one parallel compiled call. With unit weights a resample is one linear pass over the data's
|
|
18
|
+
presorted order with multiplicities (counts are exact integers, so no re-sort); with weights each resample is
|
|
19
|
+
gathered and stably sorted. The BCa jackknife reuses one presort for every left-out block. A 2,000-resample BCa
|
|
20
|
+
interval on 100,000 observations: 28.9 s → 5.9 s (4.0 s with `resampling="native"`, 2 cores).
|
|
21
|
+
- **DeLong test and DeLong AUC intervals**: one sort per model yields all three mid-rankings (exact
|
|
22
|
+
half-integers) instead of three SciPy `rankdata` calls: 3×.
|
|
23
|
+
- **QA metrics**: SQuAD answer normalisation, exact match and token F1 in the core for ASCII text (Unicode text
|
|
24
|
+
keeps Python's case mapping): `token_f1` 6.3×, `exact_match` 2.4×, and `majority_vote_accuracy` normalises in
|
|
25
|
+
one batch.
|
|
26
|
+
- **Hausdorff distance / HD95 / average symmetric surface distance**: surfaces extracted in parallel and exact
|
|
27
|
+
nearest-surface distances from a dense-bitmap shell search with an exact k-d tree fallback, using the same
|
|
28
|
+
arithmetic as the direct comparison: 1.2–6× faster on 2-D and 3-D masks, identical results.
|
|
29
|
+
- **Calibration** (`calibration_curve`, `expected_calibration_error`, and the metrics built on them): bin search
|
|
30
|
+
and the three weighted bin sums in one pass: 4.4× at 1,000,000 samples.
|
|
31
|
+
- **WEAT permutation test**: exact enumeration of the splits in the core (53×, identical p-values), and
|
|
32
|
+
opt-in `resampling="native"` for the random splits (26×; seeded and thread-count independent, a different
|
|
33
|
+
random stream from NumPy's).
|
|
34
|
+
- Tool-call metrics reuse one JSON encoder for their call keys (byte-identical keys, 1.3×).
|
|
35
|
+
- Parity tests for every new kernel, and the thread-count invariance test now covers the new parallel paths.
|
|
36
|
+
|
|
37
|
+
### Not ported
|
|
38
|
+
- No concordance / C-index metric exists in EvalSuite, so there was nothing to port (adding one is a feature,
|
|
39
|
+
not a port).
|
|
40
|
+
- Turning words into ids for the text metrics: a compiled interner gave no gain, because the Python 3.9 stable
|
|
41
|
+
ABI the wheels target has to copy every string, which costs as much as Python's dict lookup.
|
|
42
|
+
- EvalSuite has no fairness module; the multilingual per-language split is a dictionary lookup.
|
|
43
|
+
- Multiple-testing corrections (`adjust_pvalues`): a compiled sort was slower than NumPy 2's SIMD sort at
|
|
44
|
+
10,000–100,000 p-values and only marginally faster at 1,000,000, so the NumPy code stays.
|
|
45
|
+
|
|
9
46
|
## [0.7.0] - 2026-11-24
|
|
10
47
|
|
|
11
48
|
More of EvalSuite runs in the compiled Rust core. Every result is unchanged: each new kernel is bit-identical to
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: evalsuite-python
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.1
|
|
4
4
|
Classifier: Development Status :: 5 - Production/Stable
|
|
5
5
|
Classifier: Intended Audience :: Science/Research
|
|
6
6
|
Classifier: Intended Audience :: Healthcare Industry
|
|
@@ -85,11 +85,13 @@ Project-URL: Source, https://github.com/mkcs28/evalsuite-python
|
|
|
85
85
|
EvalSuite brings classification, regression, clinical, statistical, segmentation and object-detection
|
|
86
86
|
evaluation into one consistent, validated, documented framework.
|
|
87
87
|
|
|
88
|
-
> **Status: stable (0.7.
|
|
88
|
+
> **Status: stable (0.7.1).** Every item on the 0.1.0–0.5.0 roadmaps is implemented and verified, including SPICE.
|
|
89
89
|
> **0.6 adds a compiled Rust core**: same API and identical results, with text metrics, COCO evaluation and
|
|
90
90
|
> bootstrap resampling several times faster and multithreaded (prebuilt wheels for Linux, macOS and Windows).
|
|
91
91
|
> **0.7.0** moves ROC AUC / average precision (and so `evaluate()`), the LLM-systems consistency metrics,
|
|
92
92
|
> groundedness, citation coverage, toxicity, exposure and Elo into the core.
|
|
93
|
+
> **0.7.1** adds bootstrapped ROC AUC / AP (4–5× faster intervals), DeLong, QA exact match / F1,
|
|
94
|
+
> Hausdorff / surface distances, calibration and the WEAT permutation test.
|
|
93
95
|
> **LLM systems arrive in 0.5.0**: safety, robustness, calibration and uncertainty, agents and tool use,
|
|
94
96
|
> multilingual, code generation, long context and summarization, and inference efficiency and cost.
|
|
95
97
|
|
|
@@ -113,10 +115,10 @@ is needed. Anywhere else pip falls back to a pure-Python wheel that gives exactl
|
|
|
113
115
|
|
|
114
116
|
The core runs independent examples (sentences, images, classes, resamples) in parallel on all CPU cores; set
|
|
115
117
|
`EVALSUITE_NUM_THREADS` to cap the number of threads. Results never depend on the thread count: sums are always
|
|
116
|
-
taken in example order. Bootstrap functions (`bootstrap_ci`, `paired_bootstrap_test`, `compare`)
|
|
117
|
-
`resampling="native"` to draw
|
|
118
|
-
`random_state` and faster on large inputs, but a different random stream from
|
|
119
|
-
interval endpoints differ slightly (statistically equivalent).
|
|
118
|
+
taken in example order. Bootstrap functions (`bootstrap_ci`, `paired_bootstrap_test`, `compare`) and
|
|
119
|
+
`weat_effect_size` accept `resampling="native"` to draw resamples (or permutations) in the core (seeded
|
|
120
|
+
xoshiro256++): reproducible with `random_state` and faster on large inputs, but a different random stream from
|
|
121
|
+
the default NumPy one, so interval endpoints and p-values differ slightly (statistically equivalent).
|
|
120
122
|
|
|
121
123
|
## Why EvalSuite
|
|
122
124
|
|
|
@@ -358,55 +360,57 @@ Input files can be CSV, TSV, Parquet or JSON. Output format follows `--format` o
|
|
|
358
360
|
|
|
359
361
|
## Performance
|
|
360
362
|
|
|
361
|
-
Benchmarked against reference implementations on the same data (fastest of 5 runs; EvalSuite 0.7.
|
|
363
|
+
Benchmarked against reference implementations on the same data (fastest of 5 runs; EvalSuite 0.7.1, Python 3.13,
|
|
362
364
|
NumPy 2.5, Linux x86_64). **Overall: 81 of 81 rows agree with the reference** (largest
|
|
363
|
-
difference 2.5e-14),
|
|
364
|
-
and
|
|
365
|
-
27 cases and three sizes is **4.
|
|
365
|
+
difference 2.5e-14), 80 are faster (the other, the maintainability index, runs Python's own `ast` parser
|
|
366
|
+
like radon and lands at 0.89× on this run), and the geometric-mean speed-up across all
|
|
367
|
+
27 cases and three sizes is **4.30×**. At 1,000,000 samples (pixels for
|
|
366
368
|
segmentation; 1,000 images for detection and 50 for Hausdorff; 10,000 examples for the LLM cases), in
|
|
367
369
|
alphabetical order:
|
|
368
370
|
|
|
369
371
|
| Case | Reference | EvalSuite (ms) | Reference (ms) | Speed-up |
|
|
370
372
|
| --- | --- | ---: | ---: | ---: |
|
|
371
|
-
| 10 classes: macro F1 | scikit-learn |
|
|
372
|
-
| agreement: Krippendorff's alpha, interval (4 raters × 10000 items) | krippendorff | 1.
|
|
373
|
-
| binary: 8 label metrics via evaluate() | scikit-learn |
|
|
374
|
-
| binary: ROC AUC | scikit-learn |
|
|
375
|
-
| calibration: slope and intercept | statsmodels |
|
|
376
|
-
| clinical: diagnostic report (7 CIs) | statsmodels |
|
|
377
|
-
| clinical: sensitivity, specificity, LR+, LR− | scikit-learn |
|
|
378
|
-
| decision curve: 99 thresholds | NumPy loop |
|
|
379
|
-
| detection: COCO evaluation (1000 images) | pycocotools |
|
|
380
|
-
| multiple testing: Hochberg (n p-values) | statsmodels |
|
|
381
|
-
| regression: MAE, MSE, RMSE, R² via evaluate() | scikit-learn |
|
|
382
|
-
| retrieval: MRR, MAP@20, NDCG@10 (10000 queries) | ranx |
|
|
383
|
-
| segmentation: Dice and IoU per class (n = pixels) | scikit-learn |
|
|
384
|
-
| segmentation: Hausdorff distance (50 images) | SciPy |
|
|
385
|
-
| statistics: Cramér's V (5×5 table) | SciPy | 0.0 | 0.2 | **12.
|
|
386
|
-
| statistics: Mann–Whitney U | SciPy |
|
|
387
|
-
| statistics: Welch t-test | SciPy |
|
|
388
|
-
| structured: JSON Schema compliance (10000 documents) | jsonschema |
|
|
389
|
-
| systems: CodeBLEU n-gram terms (1000 programs) | codebleu |
|
|
390
|
-
| systems: confidence AUROC (n answers) | scikit-learn |
|
|
391
|
-
| systems: distribution-shift drop, Welch CI (n scores) | SciPy | 8.
|
|
392
|
-
| systems: invalid tool calls vs JSON Schema (10000 tasks) | jsonschema |
|
|
393
|
-
| systems: latency p50 / p95 / p99 (n requests) | NumPy |
|
|
394
|
-
| systems: maintainability index (1000 programs) | radon |
|
|
395
|
-
| text: corpus BLEU and chrF (10000 sentences) | sacreBLEU |
|
|
396
|
-
| text: METEOR, exact and stem matches (10000 sentences) | NLTK |
|
|
397
|
-
| text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score |
|
|
373
|
+
| 10 classes: macro F1 | scikit-learn | 9.2 | 106.2 | **11.5×** |
|
|
374
|
+
| agreement: Krippendorff's alpha, interval (4 raters × 10000 items) | krippendorff | 1.7 | 3.6 | **2.1×** |
|
|
375
|
+
| binary: 8 label metrics via evaluate() | scikit-learn | 10.0 | 932.8 | **93.4×** |
|
|
376
|
+
| binary: ROC AUC | scikit-learn | 86.2 | 305.1 | **3.5×** |
|
|
377
|
+
| calibration: slope and intercept | statsmodels | 209.6 | 1146.2 | **5.5×** |
|
|
378
|
+
| clinical: diagnostic report (7 CIs) | statsmodels | 5.2 | 5.9 | **1.1×** |
|
|
379
|
+
| clinical: sensitivity, specificity, LR+, LR− | scikit-learn | 20.9 | 381.9 | **18.3×** |
|
|
380
|
+
| decision curve: 99 thresholds | NumPy loop | 145.7 | 190.2 | **1.3×** |
|
|
381
|
+
| detection: COCO evaluation (1000 images) | pycocotools | 37.2 | 731.1 | **19.7×** |
|
|
382
|
+
| multiple testing: Hochberg (n p-values) | statsmodels | 74.3 | 79.7 | **1.1×** |
|
|
383
|
+
| regression: MAE, MSE, RMSE, R² via evaluate() | scikit-learn | 7.9 | 13.4 | **1.7×** |
|
|
384
|
+
| retrieval: MRR, MAP@20, NDCG@10 (10000 queries) | ranx | 156.1 | 583.6 | **3.7×** |
|
|
385
|
+
| segmentation: Dice and IoU per class (n = pixels) | scikit-learn | 36.1 | 248.7 | **6.9×** |
|
|
386
|
+
| segmentation: Hausdorff distance (50 images) | SciPy | 4.6 | 16.6 | **3.6×** |
|
|
387
|
+
| statistics: Cramér's V (5×5 table) | SciPy | 0.0 | 0.2 | **12.4×** |
|
|
388
|
+
| statistics: Mann–Whitney U | SciPy | 135.5 | 303.6 | **2.2×** |
|
|
389
|
+
| statistics: Welch t-test | SciPy | 7.1 | 10.4 | **1.5×** |
|
|
390
|
+
| structured: JSON Schema compliance (10000 documents) | jsonschema | 103.6 | 211.7 | **2.0×** |
|
|
391
|
+
| systems: CodeBLEU n-gram terms (1000 programs) | codebleu | 334.9 | 592.4 | **1.8×** |
|
|
392
|
+
| systems: confidence AUROC (n answers) | scikit-learn | 162.4 | 265.7 | **1.6×** |
|
|
393
|
+
| systems: distribution-shift drop, Welch CI (n scores) | SciPy | 8.4 | 9.6 | **1.1×** |
|
|
394
|
+
| systems: invalid tool calls vs JSON Schema (10000 tasks) | jsonschema | 108.1 | 252.4 | **2.3×** |
|
|
395
|
+
| systems: latency p50 / p95 / p99 (n requests) | NumPy | 13.2 | 15.0 | **1.1×** |
|
|
396
|
+
| systems: maintainability index (1000 programs) | radon | 100.8 | 89.5 | 0.89× |
|
|
397
|
+
| text: corpus BLEU and chrF (10000 sentences) | sacreBLEU | 206.2 | 2405.2 | **11.7×** |
|
|
398
|
+
| text: METEOR, exact and stem matches (10000 sentences) | NLTK | 72.2 | 404.0 | **5.6×** |
|
|
399
|
+
| text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score | 179.5 | 678.9 | **3.8×** |
|
|
398
400
|
|
|
399
401
|
**Every metric is benchmarked too** (`evalsuite benchmark --suite metrics`): all 225 registered metrics and
|
|
400
402
|
statistics functions at 10,000 and 100,000 samples. 86 are compared with a reference library, 118 with an
|
|
401
403
|
independent textbook formula and 21 (learned, judge-dependent or randomised) are timed alone; **all 204
|
|
402
|
-
comparisons agree**, and against the libraries the geometric-mean speed-up is **6.
|
|
404
|
+
comparisons agree**, and against the libraries the geometric-mean speed-up is **6.64×** (171 of 172
|
|
403
405
|
measurements faster). Per-metric table in BENCHMARKS.md.
|
|
404
406
|
|
|
405
407
|
**Nearly every workload is faster than its reference.** The text metrics (BLEU, chrF, TER, ROUGE, METEOR, CIDEr,
|
|
406
408
|
CodeBLEU's n-gram terms, distinct-n), the whole COCO evaluation (IoU, score sort, matching, accumulation),
|
|
407
409
|
ROC AUC and average precision (one sort per column, shared by both inside `evaluate()`), the LLM-systems
|
|
408
|
-
consistency, groundedness, citation, toxicity and exposure metrics, Elo ratings
|
|
409
|
-
|
|
410
|
+
consistency, groundedness, citation, toxicity and exposure metrics, Elo ratings, bootstrap resampling (including
|
|
411
|
+
whole bootstrap and jackknife runs of ROC AUC / AP), DeLong, QA exact match and F1,
|
|
412
|
+
Hausdorff and surface distances, calibration bins and the WEAT permutation test run in the compiled,
|
|
413
|
+
multithreaded Rust core; bootstrap intervals, paired bootstrap tests and
|
|
410
414
|
`compare()` evaluate confusion-matrix metrics from counts of each resample's (true, predicted) pairs instead of
|
|
411
415
|
copies of the data. `evaluate()` validates inputs once and builds the confusion
|
|
412
416
|
matrix once for all metrics, and integer labels are encoded without sorting. The rank tests rank the data once
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
EvalSuite brings classification, regression, clinical, statistical, segmentation and object-detection
|
|
11
11
|
evaluation into one consistent, validated, documented framework.
|
|
12
12
|
|
|
13
|
-
> **Status: stable (0.7.
|
|
13
|
+
> **Status: stable (0.7.1).** Every item on the 0.1.0–0.5.0 roadmaps is implemented and verified, including SPICE.
|
|
14
14
|
> **0.6 adds a compiled Rust core**: same API and identical results, with text metrics, COCO evaluation and
|
|
15
15
|
> bootstrap resampling several times faster and multithreaded (prebuilt wheels for Linux, macOS and Windows).
|
|
16
16
|
> **0.7.0** moves ROC AUC / average precision (and so `evaluate()`), the LLM-systems consistency metrics,
|
|
17
17
|
> groundedness, citation coverage, toxicity, exposure and Elo into the core.
|
|
18
|
+
> **0.7.1** adds bootstrapped ROC AUC / AP (4–5× faster intervals), DeLong, QA exact match / F1,
|
|
19
|
+
> Hausdorff / surface distances, calibration and the WEAT permutation test.
|
|
18
20
|
> **LLM systems arrive in 0.5.0**: safety, robustness, calibration and uncertainty, agents and tool use,
|
|
19
21
|
> multilingual, code generation, long context and summarization, and inference efficiency and cost.
|
|
20
22
|
|
|
@@ -38,10 +40,10 @@ is needed. Anywhere else pip falls back to a pure-Python wheel that gives exactl
|
|
|
38
40
|
|
|
39
41
|
The core runs independent examples (sentences, images, classes, resamples) in parallel on all CPU cores; set
|
|
40
42
|
`EVALSUITE_NUM_THREADS` to cap the number of threads. Results never depend on the thread count: sums are always
|
|
41
|
-
taken in example order. Bootstrap functions (`bootstrap_ci`, `paired_bootstrap_test`, `compare`)
|
|
42
|
-
`resampling="native"` to draw
|
|
43
|
-
`random_state` and faster on large inputs, but a different random stream from
|
|
44
|
-
interval endpoints differ slightly (statistically equivalent).
|
|
43
|
+
taken in example order. Bootstrap functions (`bootstrap_ci`, `paired_bootstrap_test`, `compare`) and
|
|
44
|
+
`weat_effect_size` accept `resampling="native"` to draw resamples (or permutations) in the core (seeded
|
|
45
|
+
xoshiro256++): reproducible with `random_state` and faster on large inputs, but a different random stream from
|
|
46
|
+
the default NumPy one, so interval endpoints and p-values differ slightly (statistically equivalent).
|
|
45
47
|
|
|
46
48
|
## Why EvalSuite
|
|
47
49
|
|
|
@@ -283,55 +285,57 @@ Input files can be CSV, TSV, Parquet or JSON. Output format follows `--format` o
|
|
|
283
285
|
|
|
284
286
|
## Performance
|
|
285
287
|
|
|
286
|
-
Benchmarked against reference implementations on the same data (fastest of 5 runs; EvalSuite 0.7.
|
|
288
|
+
Benchmarked against reference implementations on the same data (fastest of 5 runs; EvalSuite 0.7.1, Python 3.13,
|
|
287
289
|
NumPy 2.5, Linux x86_64). **Overall: 81 of 81 rows agree with the reference** (largest
|
|
288
|
-
difference 2.5e-14),
|
|
289
|
-
and
|
|
290
|
-
27 cases and three sizes is **4.
|
|
290
|
+
difference 2.5e-14), 80 are faster (the other, the maintainability index, runs Python's own `ast` parser
|
|
291
|
+
like radon and lands at 0.89× on this run), and the geometric-mean speed-up across all
|
|
292
|
+
27 cases and three sizes is **4.30×**. At 1,000,000 samples (pixels for
|
|
291
293
|
segmentation; 1,000 images for detection and 50 for Hausdorff; 10,000 examples for the LLM cases), in
|
|
292
294
|
alphabetical order:
|
|
293
295
|
|
|
294
296
|
| Case | Reference | EvalSuite (ms) | Reference (ms) | Speed-up |
|
|
295
297
|
| --- | --- | ---: | ---: | ---: |
|
|
296
|
-
| 10 classes: macro F1 | scikit-learn |
|
|
297
|
-
| agreement: Krippendorff's alpha, interval (4 raters × 10000 items) | krippendorff | 1.
|
|
298
|
-
| binary: 8 label metrics via evaluate() | scikit-learn |
|
|
299
|
-
| binary: ROC AUC | scikit-learn |
|
|
300
|
-
| calibration: slope and intercept | statsmodels |
|
|
301
|
-
| clinical: diagnostic report (7 CIs) | statsmodels |
|
|
302
|
-
| clinical: sensitivity, specificity, LR+, LR− | scikit-learn |
|
|
303
|
-
| decision curve: 99 thresholds | NumPy loop |
|
|
304
|
-
| detection: COCO evaluation (1000 images) | pycocotools |
|
|
305
|
-
| multiple testing: Hochberg (n p-values) | statsmodels |
|
|
306
|
-
| regression: MAE, MSE, RMSE, R² via evaluate() | scikit-learn |
|
|
307
|
-
| retrieval: MRR, MAP@20, NDCG@10 (10000 queries) | ranx |
|
|
308
|
-
| segmentation: Dice and IoU per class (n = pixels) | scikit-learn |
|
|
309
|
-
| segmentation: Hausdorff distance (50 images) | SciPy |
|
|
310
|
-
| statistics: Cramér's V (5×5 table) | SciPy | 0.0 | 0.2 | **12.
|
|
311
|
-
| statistics: Mann–Whitney U | SciPy |
|
|
312
|
-
| statistics: Welch t-test | SciPy |
|
|
313
|
-
| structured: JSON Schema compliance (10000 documents) | jsonschema |
|
|
314
|
-
| systems: CodeBLEU n-gram terms (1000 programs) | codebleu |
|
|
315
|
-
| systems: confidence AUROC (n answers) | scikit-learn |
|
|
316
|
-
| systems: distribution-shift drop, Welch CI (n scores) | SciPy | 8.
|
|
317
|
-
| systems: invalid tool calls vs JSON Schema (10000 tasks) | jsonschema |
|
|
318
|
-
| systems: latency p50 / p95 / p99 (n requests) | NumPy |
|
|
319
|
-
| systems: maintainability index (1000 programs) | radon |
|
|
320
|
-
| text: corpus BLEU and chrF (10000 sentences) | sacreBLEU |
|
|
321
|
-
| text: METEOR, exact and stem matches (10000 sentences) | NLTK |
|
|
322
|
-
| text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score |
|
|
298
|
+
| 10 classes: macro F1 | scikit-learn | 9.2 | 106.2 | **11.5×** |
|
|
299
|
+
| agreement: Krippendorff's alpha, interval (4 raters × 10000 items) | krippendorff | 1.7 | 3.6 | **2.1×** |
|
|
300
|
+
| binary: 8 label metrics via evaluate() | scikit-learn | 10.0 | 932.8 | **93.4×** |
|
|
301
|
+
| binary: ROC AUC | scikit-learn | 86.2 | 305.1 | **3.5×** |
|
|
302
|
+
| calibration: slope and intercept | statsmodels | 209.6 | 1146.2 | **5.5×** |
|
|
303
|
+
| clinical: diagnostic report (7 CIs) | statsmodels | 5.2 | 5.9 | **1.1×** |
|
|
304
|
+
| clinical: sensitivity, specificity, LR+, LR− | scikit-learn | 20.9 | 381.9 | **18.3×** |
|
|
305
|
+
| decision curve: 99 thresholds | NumPy loop | 145.7 | 190.2 | **1.3×** |
|
|
306
|
+
| detection: COCO evaluation (1000 images) | pycocotools | 37.2 | 731.1 | **19.7×** |
|
|
307
|
+
| multiple testing: Hochberg (n p-values) | statsmodels | 74.3 | 79.7 | **1.1×** |
|
|
308
|
+
| regression: MAE, MSE, RMSE, R² via evaluate() | scikit-learn | 7.9 | 13.4 | **1.7×** |
|
|
309
|
+
| retrieval: MRR, MAP@20, NDCG@10 (10000 queries) | ranx | 156.1 | 583.6 | **3.7×** |
|
|
310
|
+
| segmentation: Dice and IoU per class (n = pixels) | scikit-learn | 36.1 | 248.7 | **6.9×** |
|
|
311
|
+
| segmentation: Hausdorff distance (50 images) | SciPy | 4.6 | 16.6 | **3.6×** |
|
|
312
|
+
| statistics: Cramér's V (5×5 table) | SciPy | 0.0 | 0.2 | **12.4×** |
|
|
313
|
+
| statistics: Mann–Whitney U | SciPy | 135.5 | 303.6 | **2.2×** |
|
|
314
|
+
| statistics: Welch t-test | SciPy | 7.1 | 10.4 | **1.5×** |
|
|
315
|
+
| structured: JSON Schema compliance (10000 documents) | jsonschema | 103.6 | 211.7 | **2.0×** |
|
|
316
|
+
| systems: CodeBLEU n-gram terms (1000 programs) | codebleu | 334.9 | 592.4 | **1.8×** |
|
|
317
|
+
| systems: confidence AUROC (n answers) | scikit-learn | 162.4 | 265.7 | **1.6×** |
|
|
318
|
+
| systems: distribution-shift drop, Welch CI (n scores) | SciPy | 8.4 | 9.6 | **1.1×** |
|
|
319
|
+
| systems: invalid tool calls vs JSON Schema (10000 tasks) | jsonschema | 108.1 | 252.4 | **2.3×** |
|
|
320
|
+
| systems: latency p50 / p95 / p99 (n requests) | NumPy | 13.2 | 15.0 | **1.1×** |
|
|
321
|
+
| systems: maintainability index (1000 programs) | radon | 100.8 | 89.5 | 0.89× |
|
|
322
|
+
| text: corpus BLEU and chrF (10000 sentences) | sacreBLEU | 206.2 | 2405.2 | **11.7×** |
|
|
323
|
+
| text: METEOR, exact and stem matches (10000 sentences) | NLTK | 72.2 | 404.0 | **5.6×** |
|
|
324
|
+
| text: ROUGE-1, ROUGE-2, ROUGE-L (10000 sentences) | rouge-score | 179.5 | 678.9 | **3.8×** |
|
|
323
325
|
|
|
324
326
|
**Every metric is benchmarked too** (`evalsuite benchmark --suite metrics`): all 225 registered metrics and
|
|
325
327
|
statistics functions at 10,000 and 100,000 samples. 86 are compared with a reference library, 118 with an
|
|
326
328
|
independent textbook formula and 21 (learned, judge-dependent or randomised) are timed alone; **all 204
|
|
327
|
-
comparisons agree**, and against the libraries the geometric-mean speed-up is **6.
|
|
329
|
+
comparisons agree**, and against the libraries the geometric-mean speed-up is **6.64×** (171 of 172
|
|
328
330
|
measurements faster). Per-metric table in BENCHMARKS.md.
|
|
329
331
|
|
|
330
332
|
**Nearly every workload is faster than its reference.** The text metrics (BLEU, chrF, TER, ROUGE, METEOR, CIDEr,
|
|
331
333
|
CodeBLEU's n-gram terms, distinct-n), the whole COCO evaluation (IoU, score sort, matching, accumulation),
|
|
332
334
|
ROC AUC and average precision (one sort per column, shared by both inside `evaluate()`), the LLM-systems
|
|
333
|
-
consistency, groundedness, citation, toxicity and exposure metrics, Elo ratings
|
|
334
|
-
|
|
335
|
+
consistency, groundedness, citation, toxicity and exposure metrics, Elo ratings, bootstrap resampling (including
|
|
336
|
+
whole bootstrap and jackknife runs of ROC AUC / AP), DeLong, QA exact match and F1,
|
|
337
|
+
Hausdorff and surface distances, calibration bins and the WEAT permutation test run in the compiled,
|
|
338
|
+
multithreaded Rust core; bootstrap intervals, paired bootstrap tests and
|
|
335
339
|
`compare()` evaluate confusion-matrix metrics from counts of each resample's (true, predicted) pairs instead of
|
|
336
340
|
copies of the data. `evaluate()` validates inputs once and builds the confusion
|
|
337
341
|
matrix once for all metrics, and integer labels are encoded without sorting. The rank tests rank the data once
|
|
@@ -35,14 +35,14 @@ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
|
|
|
35
35
|
|
|
36
36
|
[[package]]
|
|
37
37
|
name = "evalsuite-core"
|
|
38
|
-
version = "0.7.
|
|
38
|
+
version = "0.7.1"
|
|
39
39
|
dependencies = [
|
|
40
40
|
"rayon",
|
|
41
41
|
]
|
|
42
42
|
|
|
43
43
|
[[package]]
|
|
44
44
|
name = "evalsuite-py"
|
|
45
|
-
version = "0.7.
|
|
45
|
+
version = "0.7.1"
|
|
46
46
|
dependencies = [
|
|
47
47
|
"evalsuite-core",
|
|
48
48
|
"pyo3",
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
//! ROC AUC and average precision from one stable descending sort, bit for bit as EvalSuite's NumPy reference
|
|
2
|
+
//! (`_binary_curve`, `_binary_auc`, `_binary_ap` in `classification/metrics.py`).
|
|
3
|
+
|
|
4
|
+
/// NumPy's float64 `add.reduce` over a contiguous 1-D array: `pairwise_sum_DOUBLE` (8 accumulators per block
|
|
5
|
+
/// of up to 128, halves split on multiples of 8), added to the zero identity.
|
|
6
|
+
pub fn np_sum(a: &[f64]) -> f64 {
|
|
7
|
+
0.0 + pairwise(a)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
fn pairwise(a: &[f64]) -> f64 {
|
|
11
|
+
let n = a.len();
|
|
12
|
+
if n < 8 {
|
|
13
|
+
let mut res = -0.0f64;
|
|
14
|
+
for &x in a {
|
|
15
|
+
res += x;
|
|
16
|
+
}
|
|
17
|
+
res
|
|
18
|
+
} else if n <= 128 {
|
|
19
|
+
let mut r = [0.0f64; 8];
|
|
20
|
+
r.copy_from_slice(&a[..8]);
|
|
21
|
+
let mut i = 8;
|
|
22
|
+
while i < n - (n % 8) {
|
|
23
|
+
for j in 0..8 {
|
|
24
|
+
r[j] += a[i + j];
|
|
25
|
+
}
|
|
26
|
+
i += 8;
|
|
27
|
+
}
|
|
28
|
+
let mut res = ((r[0] + r[1]) + (r[2] + r[3])) + ((r[4] + r[5]) + (r[6] + r[7]));
|
|
29
|
+
while i < n {
|
|
30
|
+
res += a[i];
|
|
31
|
+
i += 1;
|
|
32
|
+
}
|
|
33
|
+
res
|
|
34
|
+
} else {
|
|
35
|
+
let mut n2 = n / 2;
|
|
36
|
+
n2 -= n2 % 8;
|
|
37
|
+
pairwise(&a[..n2]) + pairwise(&a[n2..])
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// Summary of one binary curve: (ROC AUC, average precision, total positive weight, total negative weight).
|
|
42
|
+
/// AUC is NaN when either total is zero and AP when there is no positive weight (the caller raises).
|
|
43
|
+
pub fn curve_scores(y: &[f64], score: &[f64], w: &[f64]) -> (f64, f64, f64, f64) {
|
|
44
|
+
let n = score.len();
|
|
45
|
+
if n == 0 {
|
|
46
|
+
return (f64::NAN, f64::NAN, 0.0, 0.0);
|
|
47
|
+
}
|
|
48
|
+
// np.argsort(-score, kind="mergesort"): stable, descending; -0.0 and 0.0 compare equal.
|
|
49
|
+
let order = descending_order(score);
|
|
50
|
+
let mut tps = Vec::new();
|
|
51
|
+
let mut fps = Vec::new();
|
|
52
|
+
let (mut tp, mut fp) = (0.0f64, 0.0f64);
|
|
53
|
+
for (pos, &i) in order.iter().enumerate() {
|
|
54
|
+
// y * w and (1 - y) * w, accumulated sequentially as np.cumsum.
|
|
55
|
+
tp += y[i] * w[i];
|
|
56
|
+
fp += (1.0 - y[i]) * w[i];
|
|
57
|
+
let last = pos + 1 == n;
|
|
58
|
+
if last || score[i] - score[order[pos + 1]] != 0.0 {
|
|
59
|
+
tps.push(tp);
|
|
60
|
+
fps.push(fp);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
finish(&tps, &fps)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// AUC and AP from the cumulative (tp, fp) at each distinct threshold, best first.
|
|
67
|
+
fn finish(tps: &[f64], fps: &[f64]) -> (f64, f64, f64, f64) {
|
|
68
|
+
let (tp_all, fp_all) = (*tps.last().unwrap(), *fps.last().unwrap());
|
|
69
|
+
let m = tps.len();
|
|
70
|
+
let auc = if tp_all == 0.0 || fp_all == 0.0 {
|
|
71
|
+
f64::NAN
|
|
72
|
+
} else {
|
|
73
|
+
// trapezoid(tpr, fpr) with fpr, tpr = r_[0, fps / fps[-1]], r_[0, tps / tps[-1]].
|
|
74
|
+
let mut terms = Vec::with_capacity(m);
|
|
75
|
+
let (mut x0, mut y0) = (0.0f64, 0.0f64);
|
|
76
|
+
for k in 0..m {
|
|
77
|
+
let (x1, y1) = (fps[k] / fp_all, tps[k] / tp_all);
|
|
78
|
+
terms.push((x1 - x0) * (y1 + y0) / 2.0);
|
|
79
|
+
x0 = x1;
|
|
80
|
+
y0 = y1;
|
|
81
|
+
}
|
|
82
|
+
np_sum(&terms)
|
|
83
|
+
};
|
|
84
|
+
let ap = if tp_all == 0.0 {
|
|
85
|
+
f64::NAN
|
|
86
|
+
} else {
|
|
87
|
+
// sum(diff(r_[0, rec]) * prec), rec = tps / tps[-1], prec = tps / (tps + fps).
|
|
88
|
+
let mut terms = Vec::with_capacity(m);
|
|
89
|
+
let mut r0 = 0.0f64;
|
|
90
|
+
for k in 0..m {
|
|
91
|
+
let r1 = tps[k] / tp_all;
|
|
92
|
+
terms.push((r1 - r0) * (tps[k] / (tps[k] + fps[k])));
|
|
93
|
+
r0 = r1;
|
|
94
|
+
}
|
|
95
|
+
np_sum(&terms)
|
|
96
|
+
};
|
|
97
|
+
(auc, ap, tp_all, fp_all)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/// The stable descending order of `score`, as `np.argsort(-score, kind="mergesort")`.
|
|
101
|
+
pub fn descending_order(score: &[f64]) -> Vec<usize> {
|
|
102
|
+
let mut order: Vec<usize> = (0..score.len()).collect();
|
|
103
|
+
order.sort_by(|&a, &b| {
|
|
104
|
+
(-score[a])
|
|
105
|
+
.partial_cmp(&-score[b])
|
|
106
|
+
.unwrap_or(std::cmp::Ordering::Equal)
|
|
107
|
+
});
|
|
108
|
+
order
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// Curve scores of every bootstrap resample (`indices` is `rows × n`, row-major, each index in `0..y.len()`),
|
|
112
|
+
/// in parallel. With `w = None` (unit weights) the per-threshold counts are exact integers, so each resample
|
|
113
|
+
/// is one linear pass over the full data's presorted order with multiplicities, giving the same curve as
|
|
114
|
+
/// sorting the resample; with weights each resample is gathered and sorted (stable), exactly as NumPy.
|
|
115
|
+
pub fn bootstrap_curves(
|
|
116
|
+
y: &[f64],
|
|
117
|
+
score: &[f64],
|
|
118
|
+
w: Option<&[f64]>,
|
|
119
|
+
indices: &[i64],
|
|
120
|
+
rows: usize,
|
|
121
|
+
) -> Vec<(f64, f64, f64, f64)> {
|
|
122
|
+
use rayon::prelude::*;
|
|
123
|
+
|
|
124
|
+
let n = indices.len().checked_div(rows).unwrap_or(0);
|
|
125
|
+
if n == 0 {
|
|
126
|
+
return vec![(f64::NAN, f64::NAN, 0.0, 0.0); rows];
|
|
127
|
+
}
|
|
128
|
+
match w {
|
|
129
|
+
Some(w) => indices
|
|
130
|
+
.par_chunks(n)
|
|
131
|
+
.map(|idx| {
|
|
132
|
+
let gy: Vec<f64> = idx.iter().map(|&i| y[i as usize]).collect();
|
|
133
|
+
let gs: Vec<f64> = idx.iter().map(|&i| score[i as usize]).collect();
|
|
134
|
+
let gw: Vec<f64> = idx.iter().map(|&i| w[i as usize]).collect();
|
|
135
|
+
curve_scores(&gy, &gs, &gw)
|
|
136
|
+
})
|
|
137
|
+
.collect(),
|
|
138
|
+
None => {
|
|
139
|
+
let order = descending_order(score);
|
|
140
|
+
indices
|
|
141
|
+
.par_chunks(n)
|
|
142
|
+
.map_init(
|
|
143
|
+
|| vec![0u32; y.len()],
|
|
144
|
+
|counts, idx| {
|
|
145
|
+
counts.iter_mut().for_each(|c| *c = 0);
|
|
146
|
+
for &i in idx {
|
|
147
|
+
counts[i as usize] += 1;
|
|
148
|
+
}
|
|
149
|
+
let (mut tps, mut fps) = (Vec::new(), Vec::new());
|
|
150
|
+
let (mut tp, mut fp) = (0.0f64, 0.0f64);
|
|
151
|
+
let mut prev: Option<f64> = None;
|
|
152
|
+
for &i in &order {
|
|
153
|
+
let c = counts[i];
|
|
154
|
+
if c == 0 {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if let Some(p) = prev {
|
|
158
|
+
if p - score[i] != 0.0 {
|
|
159
|
+
tps.push(tp);
|
|
160
|
+
fps.push(fp);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
let c = f64::from(c);
|
|
164
|
+
tp += c * y[i];
|
|
165
|
+
fp += c * (1.0 - y[i]);
|
|
166
|
+
prev = Some(score[i]);
|
|
167
|
+
}
|
|
168
|
+
tps.push(tp);
|
|
169
|
+
fps.push(fp);
|
|
170
|
+
finish(&tps, &fps)
|
|
171
|
+
},
|
|
172
|
+
)
|
|
173
|
+
.collect()
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/// Leave-one-group-out curve scores: `group_of[i]` is the block of observation `i` (`0..groups`); result `g`
|
|
179
|
+
/// is the curve of every observation outside block `g`. A stable sort of a subset keeps the full data's order,
|
|
180
|
+
/// so one presort serves every block, with or without weights. Blocks in parallel.
|
|
181
|
+
pub fn leave_group_out_curves(
|
|
182
|
+
y: &[f64],
|
|
183
|
+
score: &[f64],
|
|
184
|
+
w: Option<&[f64]>,
|
|
185
|
+
group_of: &[u32],
|
|
186
|
+
groups: usize,
|
|
187
|
+
) -> Vec<(f64, f64, f64, f64)> {
|
|
188
|
+
use rayon::prelude::*;
|
|
189
|
+
|
|
190
|
+
let order = descending_order(score);
|
|
191
|
+
(0..groups)
|
|
192
|
+
.into_par_iter()
|
|
193
|
+
.map(|g| {
|
|
194
|
+
let (mut tps, mut fps) = (Vec::new(), Vec::new());
|
|
195
|
+
let (mut tp, mut fp) = (0.0f64, 0.0f64);
|
|
196
|
+
let mut prev: Option<f64> = None;
|
|
197
|
+
for &i in &order {
|
|
198
|
+
if group_of[i] as usize == g {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if let Some(p) = prev {
|
|
202
|
+
if p - score[i] != 0.0 {
|
|
203
|
+
tps.push(tp);
|
|
204
|
+
fps.push(fp);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
let wi = w.map_or(1.0, |w| w[i]);
|
|
208
|
+
tp += y[i] * wi;
|
|
209
|
+
fp += (1.0 - y[i]) * wi;
|
|
210
|
+
prev = Some(score[i]);
|
|
211
|
+
}
|
|
212
|
+
if prev.is_none() {
|
|
213
|
+
return (f64::NAN, f64::NAN, 0.0, 0.0);
|
|
214
|
+
}
|
|
215
|
+
tps.push(tp);
|
|
216
|
+
fps.push(fp);
|
|
217
|
+
finish(&tps, &fps)
|
|
218
|
+
})
|
|
219
|
+
.collect()
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
#[cfg(test)]
|
|
223
|
+
mod tests {
|
|
224
|
+
#[test]
|
|
225
|
+
fn perfect_and_reversed() {
|
|
226
|
+
let y = [1.0, 1.0, 0.0, 0.0];
|
|
227
|
+
let w = [1.0; 4];
|
|
228
|
+
let (auc, ap, tp, fp) = super::curve_scores(&y, &[0.9, 0.8, 0.2, 0.1], &w);
|
|
229
|
+
assert_eq!((auc, ap, tp, fp), (1.0, 1.0, 2.0, 2.0));
|
|
230
|
+
let (auc, _, _, _) = super::curve_scores(&y, &[0.1, 0.2, 0.8, 0.9], &w);
|
|
231
|
+
assert_eq!(auc, 0.0);
|
|
232
|
+
let (auc, _, _, _) = super::curve_scores(&y, &[0.5; 4], &w);
|
|
233
|
+
assert_eq!(auc, 0.5);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
#[test]
|
|
237
|
+
fn bootstrap_counts_match_gathering() {
|
|
238
|
+
let y = [1.0, 0.0, 1.0, 0.0, 1.0, 0.0];
|
|
239
|
+
let s = [0.9, 0.9, 0.4, 0.3, 0.3, 0.1];
|
|
240
|
+
let idx = [0i64, 1, 1, 3, 4, 4, 5, 2, 2, 2, 0, 3];
|
|
241
|
+
let a = super::bootstrap_curves(&y, &s, None, &idx, 2);
|
|
242
|
+
let b = super::bootstrap_curves(&y, &s, Some(&[1.0; 6]), &idx, 2);
|
|
243
|
+
assert_eq!(a, b);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
#[test]
|
|
247
|
+
fn sum_small() {
|
|
248
|
+
assert_eq!(super::np_sum(&[1.0, 2.0, 3.0]), 6.0);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -80,6 +80,20 @@ pub fn row_stats(row: &[f64]) -> (f64, f64, f64, u64) {
|
|
|
80
80
|
(crate::curve::np_sum(row), lo, hi, pos)
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/// Calibration bins in one pass: each probability's bin is `searchsorted(inner_edges, p, side="right")`, and
|
|
84
|
+
/// per bin the sums of `w`, `w·y` and `w·p` are accumulated in input order (as `np.bincount` with weights).
|
|
85
|
+
pub fn calibration_bins(y: &[f64], p: &[f64], w: &[f64], inner_edges: &[f64]) -> [Vec<f64>; 3] {
|
|
86
|
+
let k = inner_edges.len() + 2;
|
|
87
|
+
let (mut bw, mut bt, mut bp) = (vec![0.0f64; k], vec![0.0f64; k], vec![0.0f64; k]);
|
|
88
|
+
for i in 0..p.len() {
|
|
89
|
+
let b = inner_edges.partition_point(|&e| e <= p[i]);
|
|
90
|
+
bw[b] += w[i];
|
|
91
|
+
bt[b] += w[i] * y[i];
|
|
92
|
+
bp[b] += w[i] * p[i];
|
|
93
|
+
}
|
|
94
|
+
[bw, bt, bp]
|
|
95
|
+
}
|
|
96
|
+
|
|
83
97
|
#[cfg(test)]
|
|
84
98
|
mod tests {
|
|
85
99
|
use super::*;
|