SoftmaxRegressionStat
Online multinomial logistic regression by stochastic gradient descent on the softmax cross-entropy loss. Generalises com.eignex.kumulant.stat.regression.glm.StochasticRegressionStat with Link.Logit from binary to K-way classification.
Update step per observation (true class c = y.toInt()):
p[k] = softmax(W[k] . x + b[k])
grad[k]i = (p[k] - 1[k == c]) * x[i] // per-coordinate gradient
W[k]i += optimizer.computeDelta(k, i, grad[k]i, weight)
b[k] += biasOptimizer.computeDelta(k, p[k] - 1[k == c], weight)One OptimizerSpec is materialised per class for the weight matrix; bias is a single optimizer over numClasses slots.
Use cases: K-way online classification with calibrated probabilities; the discriminative counterpart to GaussianNaiveBayesStat.
Memory: O(numClasses * featureSize) for weights + per-optimizer aux state, plus a pooled length-numClasses logit buffer held for the life of the stat under every level but Concurrency.Relaxed.
Update: O(numClasses * nnz(x)) per observation.
Concurrency: Welford-locked; the optimizer aux state honours the same Concurrency passed in. The per-observation logit scratch is owned per stat and guarded by that lock, so a Concurrency.None stat updated from two threads can fail inside the linear-algebra layer rather than only drift. Concurrency.Relaxed holds no scratch and allocates per update, because its lock is a no-op and racing writers there must drift rather than throw.
Constructors
SoftmaxRegressionStat
Properties
biasOptimizer
Bias optimizer, materialised once over numClasses slots. Defaults to optimizer.
concurrency
Thread-safety mode fixed at construction. See Concurrency for the shared contract and the implementation's KDoc for its cell and lock strategy.
crossEntropy
Live view of the accumulated weighted cross-entropy.
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).
optimizer
Per-class weight-matrix optimizer; one instance is materialised per class.
step
totalWeights
Live view of the cumulative observation weight folded in.
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.
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.