MadStat
Streaming median and unscaled median absolute deviation from one raw-value TDigestStat.
Updates accumulate observations without computing deviations. Reading computes the weighted median of centroid locations, then the weighted median of their absolute distances from that center. The sorted locations permit a linear outward scan. Compression can lose within-centroid spread; this estimates the historical MAD, without retaining deviations measured against earlier centers.
Merge combines the complete digest retained by MadResult.digest, then reads recalculate both estimates. A summary-only result contributes unit total weight split between median - mad and median + mad, approximating its missing evidence.
Use cases: robust center and scale for heavy-tailed streams. Use FrugalMadStat for constant-memory adaptive tracking with an equal-weight approximate merge.
Memory: O(compression); one digest and its update buffer.
Update: Inherits TDigestStat's buffered update cost; no snapshot per update. Reading adds an O(k) scan with O(1) working memory for k centroids.
Concurrency: Inherits TDigestStat's concurrency model. Both estimates are calculated from the same detached snapshot.
Constructors
MadStat
Properties
compression
T-digest compression; larger values retain more centroids and finer detail.
concurrency
Thread-safety mode fixed at construction. See Concurrency for the shared contract and the implementation's KDoc for its cell and lock strategy.
Functions
create
Create an independent accumulator at the configured baseline. A null concurrency preserves this accumulator's mode; a non-null value overrides it. Modality subtypes narrow the return type to preserve the input shape.
merge
Fold a compatible snapshot values into this accumulator at timestampNanos. Implementations document whether the combine is exact or approximate and which state the snapshot omits. The source accumulator is unaffected.
Time-dependent statistics, such as windows, place the snapshot at timestampNanos, which must share the clock the caller uses for updates and reads. Time-independent statistics ignore it.
read
Return the current result evaluated at timestampNanos. Time-independent statistics ignore the timestamp. Reading does not add an observation.
Snapshot consistency depends on the implementation's synchronisation. Locks protect coupled state under Concurrency.Strict and Concurrency.HighWrite; independently updated cells and JVM striped adders can still yield a best-effort snapshot. Concurrency.Relaxed permits drift across coupled cells.
reset
Restore the configured baseline, including any prior seed. Preserves the configuration and concurrency.