mod accumulator#

module accumulator#

Streaming statistics accumulator using Welford’s algorithm and TDigest.

Structs and Unions

struct AccumulatorState#

Maps trie path strings to their node accumulators.

Keys are /-joined path strings (e.g., "workflow/agent") because Vec<String> is not Hash. This matches the research recommendation.

nodes: HashMap<String, NodeAccumulators>#

Node accumulators keyed by /-joined path string.

struct NodeAccumulators#

Per-node accumulators for all metric types, keyed by call index.

Mirrors NAT’s _NodeAccumulators structure but uses streaming RunningStats instead of batch MetricsAccumulator.

remaining_calls: HashMap<u32, RunningStats>#

Remaining-calls stats per call index.

interarrival_ms: HashMap<u32, RunningStats>#

Interarrival-time stats per call index.

output_tokens: HashMap<u32, RunningStats>#

Output-tokens stats per call index.

sensitivity: HashMap<u32, RunningStats>#

Sensitivity stats per call index.

all_remaining_calls: RunningStats#

Aggregated remaining-calls stats across all call indices.

all_interarrival_ms: RunningStats#

Aggregated interarrival-time stats across all call indices.

all_output_tokens: RunningStats#

Aggregated output-tokens stats across all call indices.

all_sensitivity: RunningStats#

Aggregated sensitivity stats across all call indices.

struct RunningStats#

Streaming statistics tracker combining Welford’s online algorithm for mean/variance with a TDigest for streaming percentile estimation.

This replaces NAT’s batch MetricsAccumulator which stores all raw samples. RunningStats provides O(1) memory usage with merge() support for incremental trie updates.

count: u64#

Number of samples added.

mean: f64#

Running mean (Welford).

m2: f64#

Sum of squared differences from the mean (Welford M2).

digest: TDigest#

TDigest for streaming percentile estimation.

Uses custom serde to handle NaN min/max in empty digests.

Implementations

impl RunningStats#

Functions

fn add_sample(&mut self, value: f64)#

Adds a single sample, updating both Welford accumulators and TDigest.

Welford’s online algorithm maintains running mean and M2 (sum of squared differences from the mean). TDigest is updated via merge_unsorted which returns a new digest (it consumes self by value).

fn compute_metrics(&self) -> PredictionMetrics#

Computes PredictionMetrics from the current accumulator state.

Returns PredictionMetrics::default() if no samples have been added. Percentiles (p50, p90, p95) are estimated from the TDigest.

fn has_samples(&self) -> bool#

Returns true if any samples have been added.

fn merge(&mut self, other: &RunningStats)#

Merges another RunningStats into this one using parallel Welford merge and TDigest merge_digests.

If other is empty, this is a no-op.

fn new() -> Self#

Creates a new empty RunningStats.

Traits implemented

impl Default for RunningStats#