DiagonalRegressionStat
Generalised linear regression with a factorised Gaussian posterior - each coefficient gets its own running precision, but cross-coefficient correlations are dropped.
Update rule (Newton-style with diagonal Hessian, canonical Link):
eta = bias + Sum w_i * x_i
mu = link.invMean(eta)
curvature = link.curvature(eta)
precision_i += weight * curvature * x_i^2
w_i -= eta_t(step) * weight * grad_i / precision_i
biasPrecision += weight * curvature
bias += eta_t(step) * weight * (y - mu) / biasPrecisionwhere grad_i = (mu - y) * x_i plus any penalty-specific term. Reduces to the Gaussian / MSE case when link = Link.Identity (then curvature = 1, mu = eta).
Posterior samples are independent per coordinate: w_i ~ N(weights[i], 1/precision[i]).
Sparse-aware: precision and weight updates only fire where x_i != 0 (matching the diagonal-Hessian semantics; coordinates absent from this observation contribute no curvature). Penalty handling:
Penalty.None: no regularisation.
Penalty.L2:
grad_i += lambda * w_ion touched coords (coordinate-descent style).Penalty.L1: proximal soft-thresholding on touched coords after the gradient step, threshold scaled by
eta * weight * lambda / precision_i.
Use cases: high-dimensional online regression where marginal posteriors suffice (per-coordinate uncertainty without joint covariance); sparse feature spaces, click-prediction style models. Reach for BayesianRegressionStat when feature correlations matter; for StochasticRegressionStat when SGD's even-cheaper per-update cost is required.
Memory: O(featureSize); weights + per-coord precisions + bias pair.
Update: O(nnz(x)) per observation; sparse-aware over the touched coordinates of x rather than the full feature width.
Concurrency: Body serialised by an internal lock under any concurrent Concurrency level (no-op under Concurrency.None). Exact under every level up to floating-point reorder ULPs.
Constructors
DiagonalRegressionStat
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.
learningRate
Per-step learning-rate schedule applied to coefficient updates.
link
Canonical GLM link; Link.Identity is the classical Gaussian factorised posterior.
penalty
priorPrecision
Initial per-coordinate precision (inverse variance) seeded into every weight.
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
Coefficient-wise precision-weighted combine (the standard formula for independent normals). Cross-feature correlations are dropped, consistent with the diagonal model.
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.