kumulant

ScalarExpr

@Serializable
sealed interface ScalarExpr(source)

Wire-serialisable AST for scalar expressions over the per-update input environment. The library uses these wherever a stat needs to apply a caller-supplied projection / weight / threshold expression that has to round-trip on the wire; weightBy, transform, the per-bin scaler projections, the WithFeedback op, the loss / pinball / quantile configurations.

The input environment

Every evaluation receives:

  • x: Double: the primary scalar input. For series stats it's the observation value; for paired stats it's the x-axis; for regression stats it's unused (use V to access feature vector coordinates).

  • y: Double: the secondary scalar input. Used by paired stats (the y-axis) and regression stats (the response).

  • v: DoubleArray: the full input vector. Used by vector / regression stats; empty otherwise.

  • primary: Result?: the primary stat's snapshot at evaluation time for feedback operators. Center, Scale, Low, High read directly from this; per-coordinate ops receive an com.eignex.kumulant.core.IndexedResult to thread the coordinate index through.

Stats that don't need a particular field pass the default (0.0, empty array, null).

Construction

Compose with the DSL operators in this file rather than constructing AST data classes directly: X * 2.0, (X + Const(1.0)) gt 0.0, IfExpr(X gt 0.0, X, -X). The operators return the public sealed interface and hide the concrete (internal) node types.

Wire format

Polymorphic via skema's $type discriminator. The @SerialName on each concrete node is the wire-format tag; pick stable, unambiguous names if you add new ones.

Inheritors

Functions

Link copied to clipboard
operator fun ScalarExpr.div(rhs: ScalarExpr): ScalarExpr

Build Div of two expressions.

operator fun ScalarExpr.div(rhs: Double): ScalarExpr

Divide this expression by a literal rhs.

Link copied to clipboard
infix fun ScalarExpr.eq(rhs: ScalarExpr): BoolExpr

Exact equality (no tolerance).

infix fun ScalarExpr.eq(rhs: Double): BoolExpr

Exact equality against a literal (no tolerance).

Link copied to clipboard
abstract fun eval(x: Double, y: Double = 0.0, v: DoubleArray = EMPTY_VECTOR, primary: Result? = null): Double

Evaluate this expression against the per-update inputs. See the class KDoc for the input-environment convention.

Link copied to clipboard
infix fun ScalarExpr.ge(rhs: ScalarExpr): BoolExpr

Greater-or-equal comparison.

infix fun ScalarExpr.ge(rhs: Double): BoolExpr

Greater-or-equal against a literal.

Link copied to clipboard
infix fun ScalarExpr.gt(rhs: ScalarExpr): BoolExpr

Strictly-greater-than comparison.

infix fun ScalarExpr.gt(rhs: Double): BoolExpr

Strictly-greater-than against a literal.

Link copied to clipboard
infix fun ScalarExpr.le(rhs: ScalarExpr): BoolExpr

Less-or-equal comparison.

infix fun ScalarExpr.le(rhs: Double): BoolExpr

Less-or-equal against a literal.

Link copied to clipboard
infix fun ScalarExpr.lt(rhs: ScalarExpr): BoolExpr

Strictly-less-than comparison.

infix fun ScalarExpr.lt(rhs: Double): BoolExpr

Strictly-less-than against a literal.

Link copied to clipboard

Build Sub of two expressions.

operator fun ScalarExpr.minus(rhs: Double): ScalarExpr

Subtract a literal rhs from this expression.

Link copied to clipboard
operator fun ScalarExpr.plus(rhs: ScalarExpr): ScalarExpr

Build Add of two expressions.

operator fun ScalarExpr.plus(rhs: Double): ScalarExpr

Add a literal rhs to this expression.

Link copied to clipboard

Build Mul of two expressions.

operator fun ScalarExpr.times(rhs: Double): ScalarExpr

Multiply this expression by a literal rhs.

Link copied to clipboard

Unary minus: wraps in Neg.

eval

abstract fun eval(x: Double, y: Double = 0.0, v: DoubleArray = EMPTY_VECTOR, primary: Result? = null): Double(source)

Evaluate this expression against the per-update inputs. See the class KDoc for the input-environment convention.