StochasticRegressionStat
Online generalised linear regression by stochastic gradient descent on the canonical Link's negative log-likelihood plus optional Penalty. The cheapest of the multivariate regressors; point estimates only, no posterior, fast updates.
The per-coordinate update rule is owned by optimizer (Sgd / com.eignex.kumulant.schema.optimizer.Adam). The bias has its own biasOptimizer schedule because the intercept usually wants a different cadence than the coefficients.
Penalty.L1 and Penalty.L2 require optimizer (and biasOptimizer) to be Sgd; the lazy-update tricks they rely on (Bottou-style multiplicative scaling for L2; cumulative truncated gradient for L1) are SGD-specific. With a non-Sgd optimizer the penalty must be Penalty.None; folding L1/L2 into Adam-class updates is left for a future refactor.
Use cases: high-throughput online regression where point estimates suffice and the per-update cost must stay small. Reach for DiagonalRegressionStat when uncertainty is needed; for BayesianRegressionStat when the full posterior is needed.
Memory: O(featureSize); weights vector, bias, plus optimizer aux state.
Update: O(nnz(x)) per observation under Penalty.None; the L1/L2 paths add lazy-update bookkeeping with the same asymptotic cost.
Concurrency: Welford-coupled per-slot atomic under Concurrency.Relaxed (HOGWILD-style asynchronous SGD), serialised under Concurrency.Strict / Concurrency.HighWrite.
Samples
val sgd = StochasticRegressionStat(featureSize = 3)
sgd.update(doubleArrayOf(0.5, 1.0, -0.2), y = 1.5)
val r = sgd.read()
println(r.weights)Constructors
StochasticRegressionStat
Properties
bias
biasOptimizer
Update rule for the bias scalar. 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.
featureSize
Number of features expected in x on each update. Mismatched lengths throw.
link
Canonical GLM link function; Link.Identity gives ordinary least-squares SGD.
optimizer
Per-coordinate update rule for the weight vector.
penalty
sse
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
Sample-weighted blend of weights and bias. SGD has no second-moment information, so this is an approximation; for principled merges use BayesianRegressionStat. Step counts add, and the learning-rate schedules continue from the combined step; adaptive optimizer accumulators are not in the snapshot and stay local.
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.