File size: 1,707 Bytes
ff4becd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Public evaluation entry points for the MacroLens unified API.

Thin wrappers over :func:`whatif_bench.eval.score` and
:func:`whatif_bench.eval.compare_methods`. The eval layer owns all
metric computation, bootstrap-CI logic, and multiple-comparisons
correction; this module exists only so that
``import macrolens as ml; ml.score(...)`` has a stable, lightweight
surface.
"""

from __future__ import annotations

from typing import Any, Literal

from ..eval import compare_methods as _compare_methods
from ..eval import score as _score
from ._types import MetricValue


def score(
    task: str,
    y_true: Any,
    y_pred: Any,
    *,
    cluster_keys: Any = None,
    close_last: Any = None,
    resample: Literal["cluster", "iid"] = "cluster",
    n_boot: int | Literal["adaptive"] = "adaptive",
    alpha: float = 0.05,
    seed: int = 42,
    return_sensitivity: bool = False,
) -> dict[str, MetricValue]:
    """Score a ``(task, y_true, y_pred)`` triple. Defaults to cluster bootstrap."""
    return _score(
        task, y_true, y_pred,
        cluster_keys=cluster_keys,
        close_last=close_last,
        resample=resample,
        n_boot=n_boot,
        alpha=alpha,
        seed=seed,
        return_sensitivity=return_sensitivity,
    )


def compare_methods(
    task: str,
    records: list,
    *,
    correction: Literal["holm", "bh"] = "holm",
    alpha: float = 0.05,
    headline_metric: str | None = None,
):
    """Pairwise compare every method on ``task`` against the best baseline."""
    return _compare_methods(
        task, records,
        correction=correction,
        alpha=alpha,
        headline_metric=headline_metric,
    )


__all__ = ["score", "compare_methods"]