Skip to main content

Module voi_sampling

Module voi_sampling 

Source
Expand description

Value-of-Information (VOI) Sampling Policy for expensive measurements.

This module decides when to sample costly latency/cost measurements so overhead stays low while guarantees remain intact.

§Mathematical Model

We treat “violation” observations as Bernoulli random variables:

X_t ∈ {0,1},  X_t = 1  ⇔  measurement violates SLA threshold

We maintain a Beta prior/posterior over the violation probability p:

p ~ Beta(α, β)
α ← α + X_t
β ← β + (1 − X_t)

The posterior variance is:

Var[p] = αβ / ((α+β)^2 (α+β+1))

§Expected VOI (Variance Reduction)

The expected variance after one more sample is:

E[Var[p] | one sample] =
  p̂ · Var[Beta(α+1,β)] + (1−p̂) · Var[Beta(α,β+1)]

where p̂ = α / (α+β) is the posterior mean.

The value of information (VOI) is the expected reduction:

VOI = Var[p] − E[Var[p] | one sample]  ≥ 0

§Anytime-Valid Safety (E-Process Layer)

We optionally track an e-process over the same Bernoulli stream to keep decisions anytime-valid. Sampling decisions depend only on past data, so the e-process remains valid under adaptive sampling:

W_0 = 1
W_t = W_{t-1} × (1 + λ (X_t − μ₀))

where μ₀ is the baseline violation rate under H₀ and λ is a betting fraction (clamped for stability).

§Decision Rule (Explainable)

We compute a scalar score:

score = VOI × value_scale × (1 + boundary_weight × boundary_score)
boundary_score = 1 / (1 + |log W − log W*|)

where W* = 1/α is the e-value threshold.

Then:

  1. If max_interval exceeded ⇒ sample (forced).
  2. If min_interval not met ⇒ skip (guard).
  3. Else sample iff score ≥ cost.

This yields a deterministic, explainable policy that preferentially samples when uncertainty is high and evidence is near the decision boundary.

§Perf JSONL Schema

The microbench emits JSONL lines per decision:

{"test":"voi_sampling","case":"decision","idx":N,"elapsed_ns":N,"sample":true,"violated":false,"e_value":1.23}

§Key Invariants

  1. Deterministic: same inputs → same decisions.
  2. VOI non-negative: expected variance reduction ≥ 0.
  3. Anytime-valid: e-process remains valid under adaptive sampling.
  4. Bounded silence: max-interval forces periodic sampling.

§Failure Modes

ConditionBehaviorRationale
α,β ≤ 0Clamp to εAvoid invalid Beta
μ₀ ≤ 0 or ≥ 1Clamp to (ε, 1−ε)Avoid degenerate e-process
λ out of rangeClamp to valid rangePrevent negative wealth
cost ≤ 0Clamp to εAvoid divide-by-zero in evidence
max_interval = 0DisabledExplicit opt-out

§Usage

use ftui_runtime::voi_sampling::{VoiConfig, VoiSampler};
use std::time::Instant;

let mut sampler = VoiSampler::new(VoiConfig::default());
let decision = sampler.decide(Instant::now());
if decision.should_sample {
    let violated = false; // measure and evaluate
    sampler.observe(violated);
}

Structs§

VoiConfig
Configuration for the VOI sampling policy.
VoiDecision
Sampling decision with full evidence.
VoiObservation
Observation result after a sample is taken.
VoiSampler
VOI-driven sampler with Beta-Bernoulli posterior and e-process control.
VoiSamplerSnapshot
Snapshot of VOI sampler state for debug overlays.
VoiSummary
Summary statistics for VOI sampling.

Enums§

VoiLogEntry
Log entry for VOI sampling.