kumulant

DiagonalRegressionStat

class DiagonalRegressionStat(val featureSize: Int, val priorPrecision: Double = StatDefaults.DIAGONAL_REGRESSION_PRIOR_PRECISION, val learningRate: ScalarExpr = StatDefaults.diagonalLearningRate(), val penalty: Penalty = StatDefaults.regressionPenalty, val link: Link = StatDefaults.regressionLink, val concurrency: Concurrency = Concurrency.None) : RegressionStat<DiagonalRegressionResult> (source)

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) / biasPrecision

where 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_i on 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

constructor(featureSize: Int, priorPrecision: Double = StatDefaults.DIAGONAL_REGRESSION_PRIOR_PRECISION, learningRate: ScalarExpr = StatDefaults.diagonalLearningRate(), penalty: Penalty = StatDefaults.regressionPenalty, link: Link = StatDefaults.regressionLink, 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.

learningRate

Per-step learning-rate schedule applied to coefficient updates.

penalty

Regularisation applied during the gradient step; defaults to plain Newton-SGD.

priorPrecision

Initial per-coordinate precision (inverse variance) seeded into every weight.

Functions

create

open override fun create(concurrency: Concurrency? = null): DiagonalRegressionStat(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: DiagonalRegressionResult, timestampNanos: Long = currentTimeNanos())(source)

Coefficient-wise precision-weighted combine (the standard formula for independent normals). Cross-feature correlations are dropped, consistent with the diagonal model.

read

open override fun read(timestampNanos: Long = currentTimeNanos()): DiagonalRegressionResult(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: DiagonalRegressionResult)(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.