Expand description
Expected-cost validation ordering with Bayesian online learning.
This module provides a validation pipeline that orders validators by expected cost, using Beta-posterior failure probabilities and early exit.
§Mathematical Model
Each validator i has:
- cost
c_i: measured execution time (running exponential average) - failure probability
p_i = α_i / (α_i + β_i): Beta posterior mean
The optimal ordering minimises expected total cost under early-exit
(stop on first failure). By the classic optimal search theorem
(Blackwell 1953), the minimum-expected-cost ordering sorts validators
by decreasing p_i / c_i (highest “bang per buck” first).
E[cost(π)] = Σ_k c_{π_k} × Π_{j<k} (1 − p_{π_j})§Online Learning
After each validation run the pipeline updates its Beta posteriors:
- Failure observed:
α_i += 1 - Success observed:
β_i += 1
Cost estimates use an exponential moving average with configurable
smoothing factor γ ∈ (0,1].
§Evidence Ledger
Every ordering decision is recorded in an evidence ledger so that the ranking is fully explainable. Each entry contains:
- validator id, p_i, c_i, score = p_i / c_i, rank
§Failure Modes
| Condition | Behavior | Rationale |
|---|---|---|
c_i = 0 | Clamp to c_min (1μs) | Division by zero guard |
α + β = 0 | Use prior (1, 1) | Uniform prior assumption |
| All validators pass | Full cost incurred | No early exit possible |
| No validators | Return success, zero cost | Vacuously valid |
§Determinism
Given identical history (same sequence of update calls), the ordering is fully deterministic. Ties are broken by validator index (stable sort).
Structs§
- Ledger
Entry - A single entry in the evidence ledger recording an ordering decision.
- Pipeline
Config - Configuration for the validation pipeline.
- Pipeline
Result - Result of running the full pipeline.
- Pipeline
Summary - Diagnostic summary of pipeline state.
- Validation
Outcome - Result of running one validation.
- Validation
Pipeline - Expected-cost validation pipeline with Bayesian ordering.
- Validator
Stats - Per-validator statistics tracked by the pipeline.