Skip to main content

Module conformal_alert

Module conformal_alert 

Source
Expand description

Conformal alert threshold calibration with anytime-valid e-process control.

This module provides change-point detection for action timeline events using:

  1. Conformal thresholding - Distribution-free threshold calibration
  2. E-process layer - Anytime-valid FPR control via test martingales
  3. Evidence ledger - Explainable alert decisions with full provenance

§Mathematical Model

§Conformal Thresholding (Primary)

Given calibration residuals R = {r_1, …, r_n}, the conformal threshold is:

q = quantile_{(1-alpha)(n+1)/n}(R)

This is the (n+1) rule: we pretend the new observation is one of (n+1) equally likely positions, ensuring finite-sample coverage P(r_{n+1} <= q) >= 1-alpha.

§E-Process Layer (Anytime-Valid)

For early stopping without FPR inflation, we maintain an e-process:

e_t = exp(lambda * (z_t - mu_0) - lambda^2 * sigma_0^2 / 2)
E_t = prod_{s=1}^{t} e_s

where z_t = (r_t - mean) / std is the standardized residual. Alert when E_t > 1/alpha.

§Key Invariants

  1. Coverage guarantee: P(FP) <= alpha under H_0 for conformal threshold
  2. Anytime-valid: E_t is a supermartingale, so P(exists t: E_t >= 1/alpha) <= alpha
  3. Non-negative wealth: E_t >= 0 always (floored at epsilon)
  4. Calibration monotonicity: Threshold is non-decreasing in calibration set size

§Failure Modes

ConditionBehaviorRationale
n < min_calibrationUse fallback thresholdInsufficient data
sigma = 0Use epsilon floorDegenerate data
E_t underflowFloor at E_MINPrevent permanent zero-lock
All residuals identicalWide thresholdNo variance to detect

§Usage

use ftui_runtime::conformal_alert::{ConformalAlert, AlertConfig};

let mut alerter = ConformalAlert::new(AlertConfig::default());

// Calibration phase: feed baseline residuals
for baseline_value in baseline_data {
    alerter.calibrate(baseline_value);
}

// Detection phase: check new observations
let decision = alerter.observe(new_value);
if decision.is_alert() {
    println!("Alert: {}", decision.evidence_summary());
}

Structs§

AlertConfig
Configuration for conformal alert calibration.
AlertDecision
Decision returned after observing a new value.
AlertEvidence
Evidence ledger entry for a single observation.
AlertStats
Aggregate statistics for the alerter.
ConformalAlert
Conformal alert threshold calibrator with e-process control.

Enums§

AlertReason
Reason for alert decision.