# `Nous.Eval.Summary`
[🔗](https://github.com/nyo16/nous/blob/v0.21.1/lib/nous/eval/summary.ex#L1)

Aggregate metrics of one eval run, computed from its samples.

    summary = Nous.Eval.Summary.build(run)
    summary["pass_rate"]["estimate"]

The summary is a plain, JSON-native map: **string keys** at every depth,
values that are strings, numbers, booleans, `nil`, lists and such maps
(intervals are `[lower, upper]` lists, verdicts and statuses are
strings). It is meant to be stored as `Nous.Eval.Run`'s `:summary`; a JSON
round trip gives back a map equal to it under `==` (an integral float may
come back as an integer), and `Nous.Eval.Reporter.JSON` prints it as is.

`build/2` never raises on data: zero samples, all-error runs, k = 1 and
budget-exhausted runs give a summary whose undefined quantities are
`nil`.

## Statistics

The **case** is the unit of analysis (Miller 2024, "Adding Error Bars to
Evals", §3.1). With k samples per case the samples of a case are not
independent, so they are reduced per case or treated as one cluster.

Only `:pass` and `:fail` samples are *scored*. `:error` samples (a scorer
failed) are left out of every pass-rate numerator **and** denominator and
counted in `"error_rate"`; a case whose samples are all `:error` has
status `"error"`, not `"fail"`. Budget-exhausted samples (verdict `nil`)
are counted as `"none"` and are in no rate.

## Keys

  * `"schema"` - `"nous.eval.summary/1"`
  * `"run_id"`, `"task"`, `"status"`, `"k"`, `"seed"`, `"dataset_hash"`
  * `"confidence"` - the two-sided level of every interval (default 0.95)
  * `"totals"`:
    * `"cases"`, `"samples"`
    * `"verdicts"` - `"pass"`, `"fail"`, `"error"`, `"none"` sample counts
    * `"error_rate"` - `:error` samples over samples with a verdict;
      `nil` when no sample has one
    * `"errors_by_kind"` - scorer errors per `Nous.Eval.ScorerError` kind
      (each error counts once; a sample may carry several)
    * `"outcomes"` - samples per agent-run outcome (`"ok"`, `"error"`,
      `"killed"`, `"budget_exhausted"`)
  * `"cases"` - per case, sorted by id: `"id"`, `"samples"`, `"scored"`,
    `"passes"`, `"errors"`, `"pass_rate"` (over scored samples),
    `"pass_at_k"` / `"pass_hat_k"` (unbiased estimators at the run's k;
    `nil` when fewer than k samples were scored), `"case_score"` (mean of
    the samples' gated `case_score`) and `"status"`: `"pass"` (every scored
    sample passed), `"fail"` (none passed), `"mixed"`, `"error"` (only
    `:error` samples) or `"not_run"`
  * `"pass_rate"` - pooled pass rate over scored samples, with
    `"wilson"` (Wilson interval treating the scored samples as
    independent: exact for k = 1, too narrow for k > 1) and `"clustered"`
    (`"se"`/`"ci"`: cluster-robust SE with one cluster per case, Student-t
    interval with `clusters − 1` df; the interval to read when k > 1).
    `nil` intervals need at least one (Wilson) or two (clustered) cases.
  * `"pass_at_k"`, `"pass_hat_k"` - mean over cases with at least k scored
    samples, `"ci"` a t-interval over those per-case values, clipped to
    `[0, 1]`
  * `"case_score"` - mean of per-case mean `case_score`, clipped t-interval
  * `"mde"` - minimum detectable effect on the pass rate at this run size
    (see below)
  * `"scorers"` - per score or scorer name, independent of verdict
    composition: `"samples"`, `"passed"`, `"pass_rate"` (Wilson, pooled),
    `"mean"` (mean value of `:pass`/`:fail`/float scores, with a seeded
    case-level bootstrap interval), `"labels"` (label distribution),
    `"skipped"` and `"errors"` (by kind). Scores are keyed by
    `Nous.Eval.Score` name (`"judge.relevance"`); skips and errors by the
    scorer id that produced them (`"judge"`).
  * `"resources"` - `"cost"` (total, mean per priced sample, priced
    sample count; `nil` totals when no sample has a price),
    `"duration_ms"` (total, mean, p50, p95), `"tokens"` (input, output,
    total, mean total) and `"iterations"` (total, mean). Means are over
    samples that ran (outcome other than `:budget_exhausted`); totals over
    all samples.
  * `"budget"` - `"exhausted"` (run status `:budget_exhausted`),
    `"unrun_samples"` (verdict `nil`) and `"config"` (the run's `:budget`
    map as plain data)
  * `"error_examples"` - up to 20 scorer errors (`"case_id"`, `"index"`,
    `"scorer"`, `"kind"`, `"reason"` truncated to 300 characters). Reasons
    can contain agent output; renderers escape them.
  * `"bootstrap"` - `"seed"`, `"resamples"`, `"streams"`, `"algorithm"`
    of the per-scorer bootstrap, so the summary is reproducible
  * `"simulation"` - only when the run has simulated episodes
    (`Nous.Eval.Simulator`): `"episodes"`, `"terminations"` (episodes per
    termination; `"timeout"` for a killed sample), `"unscoreable"`,
    `"turns"` (`"mean"`, `"max"` messages the user sent), `"simulator"`
    (`"tokens"`, `"cost"`, `"models"` of the simulated user), `"task"`
    (benign cases: `"cases"`, `"episodes"`, `"scored"`, `"passes"`,
    `"pass_rate"`, `"pass_hat_k"` with `"estimate"` over the cases with k
    scored episodes, and `"false_blocks"`: failed episodes whose trace has a
    block or deny guard verdict), `"adversarial"` (`"cases"`,
    `"episodes"`, `"scored"`, `"breaches"`, `"breach_rate"`,
    `"breach_at_k"` with `"estimate"` over `"certified"` cases and the
    `"cannot_certify"` case ids, `"attacker_refused"`) and `"cases"` (per
    case: `"id"`, `"kind"`, `"episodes"`, `"terminations"`,
    `"unscoreable"`, then `"scored"`/`"passes"`/`"pass_hat_k"` for a task
    case or `"breaches"`/`"defended"`/`"breached_at_k"` for an adversarial
    one)

## Minimum detectable effect

`"mde"` answers "how large a pass-rate change could a comparison against
a run of the same size detect": Miller eq. 10,
`δ = (z_{1−α} + z_{power}) · √(2v / n)` for the one-sided gate test at
`α` (default 0.05) and power 0.8 (`Nous.Eval.Stats.Power.mde/3`), with `n`
cases and `v` the sample variance of the per-case pass rates. The `2v`
assumes the other run is uncorrelated with this one, so a paired
comparison usually detects less than `"mde"`: it is conservative. `v` is
floored at the binomial variance `p̃(1 − p̃)/k̄` (`p̃ = (passes + 1) /
(scored + 2)`, `k̄` scored samples per case) so an all-pass run still
reports a finite MDE. `nil` below two cases.

"No significant change" in a comparison only means no change larger than
about the MDE was detected; it is not evidence of no change.

# `t`

```elixir
@type t() :: %{required(String.t()) =&gt; term()}
```

# `build`

```elixir
@spec build(Nous.Eval.Run.t(), keyword()) :: t()
```

Builds the summary of `run`.

Options:

  * `:confidence` - two-sided interval level, default `0.95`
  * `:alpha` - one-sided level of the gate test the MDE is computed for,
    in `(0, 0.5)`, default `0.05`
  * `:power` - power for the MDE, default `0.8`
  * `:seed` - seed of the per-scorer bootstrap; default the run's seed,
    else `0`
  * `:resamples` - bootstrap replicates, default `2000`

Raises `ArgumentError` on an invalid option.

# `schema`

```elixir
@spec schema() :: String.t()
```

The value of the `"schema"` key.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
