GaussianNaiveBayesStat
Online Gaussian Naive Bayes classifier. Tracks per-class, per-feature running mean and variance via weighted Welford, plus per-class accumulated weight as the prior. Predict-time log-likelihoods assume features are conditionally independent within each class.
Use cases: cheap multiclass classifier with calibrated probabilities, useful as a baseline against SoftmaxRegressionStat or as a fallback for sparse / high-cardinality feature spaces where SGD is slow to converge.
Memory: O(numClasses * featureSize); three flat cells per (class, feature) pair (mean, M2, totalWeights), plus a per-class weight.
Update: O(featureSize) per observation (dense; sparse cost is the same because variance updates need to compare against zero).
Concurrency: Welford-locked under Concurrency.Strict / Concurrency.HighWrite. The per-class Welford state is coupled across cells, so Concurrency.None skips synchronisation; Concurrency.Relaxed runs without the lock and may drift across cells.
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:
Number of features expected in x on each update. Mismatched lengths throw.
Number of classes; the input y must round to [0, numClasses).
Lower bound applied to per-class variances when computing log-likelihoods. Prevents log(0) blow-ups on early or constant-feature data.
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.
Weight-pooled merge: combines per-class running means and M2 using Chan's parallel-Welford formula. Exact under weighted updates.
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.
Record an (x, y) observation with the given weight at the current time.
Convenience overload that wraps x as a DenseVector.
Timestamped convenience overload that wraps x as a DenseVector.
Record an (x, y) observation at timestampNanos with the given weight.
GaussianNaiveBayesStat
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.
featureSize
Number of features expected in x on each update. Mismatched lengths throw.
merge
Weight-pooled merge: combines per-class running means and M2 using Chan's parallel-Welford formula. Exact under weighted updates.
numClasses
Number of classes; the input y must round to [0, numClasses).
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 an (x, y) observation at timestampNanos with the given weight.
varianceFloor
Lower bound applied to per-class variances when computing log-likelihoods. Prevents log(0) blow-ups on early or constant-feature data.