# `Aludel.Evals.Sampling`
[🔗](https://github.com/ccarvalho-eng/aludel/blob/main/lib/aludel/evals/sampling.ex#L1)

Configuration and deterministic reduction for repeated test case execution.

Sampling is bounded to protect callers from accidental request amplification.
Attempts remain ordered and are retained in the aggregate result. The latest
attempt matching the reduced outcome supplies representative output and
artifacts, while scores and usage are aggregated across every attempt.

# `option`

```elixir
@type option() :: {:samples, pos_integer()} | {:reducer, reducer_option()}
```

# `reducer`

```elixir
@type reducer() :: :all | :any | :majority | :minimum_pass_rate
```

# `reducer_option`

```elixir
@type reducer_option() :: :all | :any | :majority | {:minimum_pass_rate, number()}
```

# `t`

```elixir
@type t() :: %Aludel.Evals.Sampling{
  minimum_pass_rate: float() | nil,
  reducer: reducer(),
  samples: pos_integer()
}
```

# `aggregate`

```elixir
@spec aggregate([map()], t()) :: map()
```

Aggregates ordered attempt results according to a validated configuration.

The aggregate retains every attempt, reports pass-rate evidence, sums token,
cost, and latency usage, and averages available attempt scores.

# `from_result`

```elixir
@spec from_result(map()) :: {:ok, t()} | {:error, {:invalid_sampling, String.t()}}
```

Restores the sampling configuration stored in a test case result.

Results created before sampling default to one attempt with the `:all`
reducer.

# `new`

```elixir
@spec new([option()]) :: {:ok, t()} | {:error, {:invalid_sampling, String.t()}}
```

Validates sampling options.

`:samples` defaults to `1` and accepts values up to 20. `:reducer`
accepts `:all`, `:any`, `:majority`, or `{:minimum_pass_rate, rate}` where the
rate is between `0.0` and `1.0`.

---

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