gizai:ml/linear
linear models.
import * as Linear from "gizai:ml/linear";Types
Sgd
type Sgd = { loss: string; rate: string; alpha: f64; l2: bool; eta0: f64; power: f64; cost: f64; epsilon: f64; maxIter: i64; tol: f64; patience: i64; }Stochastic gradient descent as scikit-learn's _plain_sgd. loss: squared_error, hinge, perceptron, epsilon_insensitive; rate: optimal, invscaling, constant, pa1 (passive-aggressive). y is ±1 for classification.
loss:stringrate:stringalpha:f64l2:booleta0:f64power:f64cost:f64epsilon:f64maxIter:i64tol:f64patience:i64
SgdState
type SgdState = { w: Vec<f64>; b: f64; scale: f64; t: f64; init: f64; }One SGD model as it learns: the weights (times scale), the intercept, the step count and the start of the optimal
rate.
w:Vec<f64>b:f64scale:f64t:f64init:f64
Functions
ridge
function ridge(x: Vec<f64>, n: i64, d: i64, y: Vec<f64>, t: i64, alpha: f64, center: bool): Vec<f64>Least squares (ridge when alpha > 0) of t targets: the minimum-norm solution, as LAPACK's lstsq gives it.
Effects: fail.
enetFit
function enetFit(x: Vec<f64>, n: i64, d: i64, y: Vec<f64>, t: i64, alpha: f64, l1: f64, maxIter: i64, tol: f64): Vec<f64>Elastic net coefficients (d by t, row-major) for the t targets of the centered data, one coordinate descent per target.
Effects: fail.
omp
function omp(x: Vec<f64>, n: i64, d: i64, y: Vec<f64>, t: i64, atoms: i64): Vec<f64>Orthogonal matching pursuit: the atom most correlated with the residual, then least squares on the chosen atoms.
Effects: fail.
bayesianRidge
function bayesianRidge(x: Vec<f64>, n: i64, d: i64, y: Vec<f64>, maxIter: i64, tol: f64, a1: f64, a2: f64, l1: f64, l2: f64): Vec<f64>Bayesian ridge regression (scikit-learn's evidence maximization in the eigenbasis of XᵀX).
Effects: fail.
ard
function ard(x: Vec<f64>, n: i64, d: i64, y: Vec<f64>, maxIter: i64, tol: f64, threshold: f64, a1: f64, a2: f64, l1: f64, l2: f64): Vec<f64>Automatic relevance determination (scikit-learn's ARDRegression).
Effects: fail.
sgdState
function sgdState(s: Sgd, d: i64): SgdStateThe starting state of SGD model s over d features: zero weights and its first learning rate.
Effects: fail.
sgdPass
function sgdPass(s: Sgd, st: mut SgdState, x: Vec<f64>, d: i64, y: Vec<f64>, order: Vec<i64>): f64One pass of SGD over rows order of x: the sum of their losses.
Effects: fail.
sgdWeights
function sgdWeights(st: SgdState, d: i64): Vec<f64>The d weights of state st, scaled, followed by its intercept.
Effects: fail.
sgd
function sgd(x: Vec<f64>, n: i64, d: i64, y: Vec<f64>, s: Sgd, rng: mut Random): Vec<f64>The weights then intercept that SGD model s learns from the n by d rows x and targets y, in rng's order.
Effects: fail.
ransac
function ransac(x: Vec<f64>, n: i64, d: i64, y: Vec<f64>, t: i64, trials0: i64, rng: mut Random): Vec<f64> throws stringRANSAC around least squares: the consensus of the most inliers within the median absolute deviation of y.
Effects: fail.
theilSen
function theilSen(x: Vec<f64>, n: i64, d: i64, y: Vec<f64>, population: i64, maxIter: i64, tol: f64, rng: mut Random): Vec<f64>Theil-Sen: the spatial median (modified Weiszfeld) of the exact fits of subsets of d + 1 rows.
Effects: fail.