Skip to main content

Module allocation_budget

Module allocation_budget 

Source
Expand description

Sequential allocation leak detection using CUSUM and e-process.

This module monitors per-frame allocation counts/bytes as a time series and detects sustained mean-shift regressions with formal guarantees.

§Mathematical Model

§CUSUM (Cumulative Sum Control Chart)

Tracks one-sided cumulative deviation from a reference mean μ₀:

S_t⁺ = max(0, S_{t-1}⁺ + (x_t − μ₀ − k))   // detect upward shift
S_t⁻ = max(0, S_{t-1}⁻ + (μ₀ − k − x_t))   // detect downward shift

where k is the allowance (slack) parameter, typically δ/2 for a target shift of δ. Alert when S_t⁺ ≥ h or S_t⁻ ≥ h.

CUSUM is quick to detect sustained shifts but is not anytime-valid: it controls ARL (average run length) rather than Type I error.

§E-Process (Anytime-Valid Sequential Test)

Maintains a wealth process over centered residuals r_t = x_t − μ₀:

E_0 = 1
E_t = E_{t-1} × exp(λ × r_t − λ² × σ² / 2)

where:

  • σ² is the assumed variance under H₀
  • λ is the betting fraction (adaptive via GRAPA or fixed)

Alert when E_t ≥ 1/α. This provides anytime-valid Type I control: P(∃t: E_t ≥ 1/α | H₀) ≤ α.

§Dual Detection Strategy

DetectorSpeedGuaranteeUse
CUSUMFast (O(δ) frames)ARL-basedQuick alerting
E-processModerateAnytime-valid αFormal confirmation

An alert fires when both detectors agree (reduces false positives) or when the e-process alone exceeds threshold (formal guarantee).

§Failure Modes

ConditionBehaviorRationale
σ² = 0Clamp to σ²_minDivision by zero guard
E_t underflowClamp to E_MINPrevents permanent zero-lock
E_t overflowClamp to E_MAXNumerical stability
No observationsNo state changeIdle is not evidence

Structs§

AllocationBudget
Allocation budget monitor with dual CUSUM + e-process detection.
BudgetAlert
Alert information when a leak/regression is detected.
BudgetConfig
Configuration for the allocation budget monitor.
BudgetEvidence
Evidence ledger entry for diagnostics.
BudgetSummary
Diagnostic summary.
EvidenceContext