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
GaussianNaiveBayesStat
Properties
concurrency
Thread-safety mode fixed at construction. See Concurrency for the shared contract and the implementation's KDoc for its cell and lock strategy.
featureSize
Number of features expected in x on each update. Mismatched lengths throw.
numClasses
Number of classes; the input y must round to [0, numClasses).
varianceFloor
Lower bound applied to per-class variances when computing log-likelihoods. Prevents log(0) blow-ups on early or constant-feature data.
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
Weight-pooled merge: combines per-class running means and M2 using Chan's parallel-Welford formula. Exact under weighted updates.
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.
validateMerge
Convenience overload that wraps x as a DenseVector.
Timestamped convenience overload that wraps x as a DenseVector.
Record the pair (x, y) with weight at timestampNanos.