kumulant

GaussianNaiveBayesStat

class GaussianNaiveBayesStat(val featureSize: Int, val numClasses: Int, val varianceFloor: Double = StatDefaults.GAUSSIAN_NAIVE_BAYES_VARIANCE_FLOOR, val concurrency: Concurrency = Concurrency.None) : RegressionStat<GaussianNaiveBayesResult> (source)

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

constructor(featureSize: Int, numClasses: Int, varianceFloor: Double = StatDefaults.GAUSSIAN_NAIVE_BAYES_VARIANCE_FLOOR, concurrency: Concurrency = Concurrency.None)(source)

Properties

concurrency

open override val concurrency: Concurrency(source)

Thread-safety mode fixed at construction. See Concurrency for the shared contract and the implementation's KDoc for its cell and lock strategy.

featureSize

open override val featureSize: Int(source)

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

open override fun create(concurrency: Concurrency? = null): GaussianNaiveBayesStat(source)

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

open override fun merge(values: GaussianNaiveBayesResult, timestampNanos: Long = currentTimeNanos())(source)

Weight-pooled merge: combines per-class running means and M2 using Chan's parallel-Welford formula. Exact under weighted updates.

read

open override fun read(timestampNanos: Long = currentTimeNanos()): GaussianNaiveBayesResult(source)

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

open override fun reset()(source)

Restore the configured baseline, including any prior seed. Preserves the configuration and concurrency.

validateMerge

open override fun validateMerge(values: GaussianNaiveBayesResult)(source)

Validate values for merge without changing accumulator state. Containers validate every child before merging any of them. Successful validation checks compatibility; it does not make a concurrent merge transactional.

Link copied to clipboard
open fun update(x: Vector, y: Double, weight: Double = 1.0)

Record the pair (x, y) with weight at the current monotonic time.

open fun update(x: DoubleArray, y: Double, weight: Double = 1.0)

Convenience overload that wraps x as a DenseVector.

open fun update(x: DoubleArray, y: Double, timestampNanos: Long, weight: Double = 1.0)

Timestamped convenience overload that wraps x as a DenseVector.

open override fun update(x: Vector, y: Double, timestampNanos: Long, weight: Double = 1.0)

Record the pair (x, y) with weight at timestampNanos.

update

open override fun update(x: Vector, y: Double, timestampNanos: Long, weight: Double = 1.0)(source)

Record the pair (x, y) with weight at timestampNanos.