ridge

std.linalg.ridge · Level L3

Ridge regression: the coefficients β minimizing ‖X·β − y‖² + λ‖β‖², from the regularized normal equations. λ > 0 keeps them solvable for any X.

β = (XᵀX + λI)⁻¹·Xᵀy

Signature

ridge(X: f64[n, p], y: f64[n], lam: f64[]) → f64[p]

Structure

The function as NOVA stores it: one box per input, operation and output, and arrows that carry values. A double border marks another library function this one runs — called once, or by Scan once per element; select it to open that function.

Xf64[n, p]lamf64[]yf64[n]TransposeXtReshapeycMatMulGMatMulXty_cIotaeye_rIotaeye_cReshapeXtyEqualeyeMultiplyregAddMSolvebetabetaf64[p]
  • input
  • operation
  • constant
  • call
  • output

Verification

  • Signature proven by NOVA’s shape solver, for every size.
  • Equal to the reference np.linalg.solve(X.T @ X + lam * np.eye(p), X.T @ y) in exact rational arithmetic, on all 40 test cases.
  • All 140 float64 results inside the running error bound; the closest uses 10% of it.
  • Interpreter and NumPy backend return bit-identical results.
Accuracy in detail
correctly rounded (the float64 nearest the exact value)
32%
bit-equal to the NumPy formula in float64
100%
largest error, in units in the last place
637

Large ulp counts appear where a result is zero or tiny next to the numbers it is computed from (after cancellation, for example), so one unit in the last place is tiny too; the absolute error is still inside the bound.

Identity

Calls
—
Called by
—
sha256:4d7026da2f9de6e9d6ab993d3a4536da95907dd27332e3df94de354eea3e9d87

The semantic hash of the graph. It changes when the program changes, and never when only its documentation does.