HalfSpaceTreesStat
Online Half-Space-Trees anomaly detector (Tan, Ting & Liu 2011). An ensemble of pre-built random half-space trees of fixed depth height; each internal node picks a random feature and a random threshold from featureRanges at construction. Trees do not grow; the algorithm tracks two mass profiles per leaf; a reference window and the latest window; and swaps them every windowSize observations. The anomaly score is computed from the reference profile.
Use cases: non-parametric multivariate anomaly detection on streams where the data distribution may shift slowly (reference window keeps the recent profile fresh). Cheap, fully parallel across trees.
Memory: O(numTrees * 2^height); two per-leaf mass arrays plus the immutable tree structure.
Update: O(numTrees * height) per observation (one tree-walk per tree, no growth).
Concurrency: Per-leaf mass updates are striped atomic adds and commute. The periodic window swap (reference <- latest; latest <- 0) takes a single lock fired once every windowSize observations.
Constructors
Properties
The thread-safety contract this stat was constructed with. Each stat picks the cell-encoding and lock strategy that honours this contract for its mathematical structure:
Per-feature value ranges used to draw random split thresholds at tree build time.
Number of input features.
PRNG seed for reproducible tree construction.
Observations per window before the reference profile rotates.
Functions
Spawn a fresh accumulator with the same configuration. Optionally override the Concurrency; useful for materialising a wire spec at a different concurrency level than the source.
Merge folds another snapshot's reference-window masses into this stat's latest window. Tree structures must match exactly; if they don't (e.g. different seeds), the merge throws.
Materialise the current state as an immutable Result. Reads never mutate, so the caller can read as often as it likes without affecting the stream.
Reset the stat to its prior-seeded baseline. Equivalent to constructing a fresh stat with the same configuration, but in place; keeps the same Concurrency and any per-stat tunables.
Convenience overload that wraps vector as a DenseVector.
Timestamped convenience overload that wraps vector as a DenseVector.
Record a vector observation at timestampNanos with the given weight.
HalfSpaceTreesStat
concurrency
The thread-safety contract this stat was constructed with. Each stat picks the cell-encoding and lock strategy that honours this contract for its mathematical structure:
Concurrency.None: single-threaded; no synchronisation. Cheapest path.
Concurrency.Relaxed: lock-free best-effort. Multi-cell stats (Welford-style MeanStat, VarianceStat, MomentsStat) may drift under contention but never throw.
Concurrency.Strict: serialised when needed for full correctness across coupled cells. Sketches always self-serialise; Welford stats lock per update.
Concurrency.HighWrite: optimised for many concurrent writers; JVM uses striped adders for naively additive stats.
Picked at construction; immutable after.
create
Spawn a fresh accumulator with the same configuration. Optionally override the Concurrency; useful for materialising a wire spec at a different concurrency level than the source.
The returned stat is independent: its state starts at the configured baseline, not at the source's current state. Each modality subtype narrows the return type so chaining doesn't lose the modality.
featureRanges
Per-feature value ranges used to draw random split thresholds at tree build time.
featureSize
Number of input features.
height
merge
Merge folds another snapshot's reference-window masses into this stat's latest window. Tree structures must match exactly; if they don't (e.g. different seeds), the merge throws.
numTrees
randomSeed
PRNG seed for reproducible tree construction.
read
Materialise the current state as an immutable Result. Reads never mutate, so the caller can read as often as it likes without affecting the stream.
Snapshot consistency depends on the configured Concurrency. Under Concurrency.Strict / Concurrency.HighWrite a read locks against writers so coupled cells stay consistent. Under Concurrency.Relaxed the cells race and the snapshot may drift by ULPs of the workload under heavy contention; the drift is bounded and the read never throws.
timestampNanos is the read timestamp. Stats that don't care about time silently drop it; stats that do (rates, decay families, recency, windowed wrappers) use it as the ordering signal.
reset
Reset the stat to its prior-seeded baseline. Equivalent to constructing a fresh stat with the same configuration, but in place; keeps the same Concurrency and any per-stat tunables.
update
Record a vector observation at timestampNanos with the given weight.
windowSize
Observations per window before the reference profile rotates.