gizlang:stats
descriptive statistics over f64 samples: moments, order statistics and the sort they share; streaming moments, variance and least squares (the SQL aggregates and their merges).
import * as Stats from "gizlang:stats";Types
VarianceState
type VarianceState = { mean: f64; m2: f64; }A running mean and the sum of squared differences (Welford's method).
mean:f64m2:f64
OlsFit
type OlsFit = { coefficients: Vec<f64>; units: Vec<f64>; }The fit of a least-squares regression: the coefficients and the unit of each.
coefficients:Vec<f64>units:Vec<f64>
OlsInference
type OlsInference = { rss: f64; degreesOfFreedom: i64; sigma: Option<f64>; covariance: Vec<Vec<f64>>; standardErrors: Vec<f64>; }The inference of a least-squares fit: residual sum of squares, degrees of freedom, sigma, covariance and standard errors.
rss:f64degreesOfFreedom:i64sigma:_gizlang_sdk_core.Option<f64>covariance:Vec<Vec<f64>>standardErrors:Vec<f64>
Functions
mean
function mean(xs: Vec<f64>): f64The mean of xs.
Effects: fail.
variance
function variance(xs: Vec<f64>, ddof: i64): f64The variance with ddof degrees of freedom removed (0: population, 1: sample).
Effects: fail.
argsort
function argsort(keys: Vec<f64>): Vec<i64>The indices of keys in ascending order of their keys; equal keys keep their order (a merge sort).
Effects: fail.
sortIndices
function sortIndices(keys: Vec<f64>, idx: mut Vec<i64>): voidSorts idx in place by ascending keys[idx[i]], stable.
Effects: fail.
sortedValues
function sortedValues(xs: Vec<f64>): Vec<f64>The values in ascending order: the merge sort of sortIndices on the values themselves (no index to follow), so equal and unordered (NaN) values land where argsort puts them.
Effects: fail.
quantileSorted
function quantileSorted(sorted: Vec<f64>, q: f64): f64The q-quantile (0 ≤ q ≤ 1) of sorted values by linear interpolation between the closest ranks (NumPy's default).
Effects: fail.
median
function median(xs: Vec<f64>): f64The median: the middle value, or the mean of the two middle values.
Effects: fail.
weightedMedian
function weightedMedian(xs: Vec<f64>, weights: Vec<f64>): f64The smallest value whose cumulative weight reaches half of the total weight (scikit-learn's weighted median).
Effects: fail.
nearestHistogramRank
function nearestHistogramRank(probability: f64, count: i64): i64Exact ceil(probability * count), with zero selecting the first observation. Preconditions: probability is finite in [0, 1], count is positive signed i64. Splitting the 128-bit product preserves ranks above f64's exact integer range.
Effects: fail.
histogramBucket
function histogramBucket(counts: Vec<i64>, probability: f64, count: i64): Option<i64>Locate a nearest-rank histogram bucket; populations are validated by the caller.
Effects: fail.
validateMomentMatrix
function validateMomentMatrix(co: Vec<f64>, dimensions: i64, count: i64): bool throws stringValidate retained means and centered products without storage or SQL state.
Effects: fail.
transitionMomentMatrix
function transitionMomentMatrix(co: mut Vec<f64>, count: i64, values: Vec<f64>, weight: i64): i64 throws stringSigned repeated-observation update. A refused downdate leaves the prior matrix intact.
Effects: fail.
interpolate
function interpolate(left: f64, right: f64, fraction: f64): f64Linear interpolation avoids overflowing the difference of opposite extremes.
stepVariance
function stepVariance(mean: f64, m2: f64, value: f64, count: i64): VarianceStateWelford update; count includes this observation.
mergeVariance
function mergeVariance(mean: f64, m2: f64, count: i64, laterMean: f64, laterM2: f64, laterCount: i64): VarianceStateChan merge retaining the scalar fold's exact arithmetic order.
Effects: fail.
stepMomentMatrix
function stepMomentMatrix(co: mut Vec<f64>, a: Vec<f64>, count: i64): voidMeans followed by the row-major centered-product matrix. count includes row.
Effects: fail.
mergeMomentMatrix
function mergeMomentMatrix(co: mut Vec<f64>, count: i64, later: Vec<f64>, laterCount: i64, scaled: bool): voidChan combination. scaled=true normalizes populations before products; false preserves ordered SQL folds' inherited floating operation order.
Effects: fail.
boundedCorrelation
function boundedCorrelation(cross: f64, left: f64, right: f64): f64Centered products on an exact line can differ by rounding ulps.
stepOlsFactor
function stepOlsFactor(co: mut Vec<f64>, a: Vec<f64>, count: i64): boolComplete numerical row; count includes it. True records nonfinite input. State holds d means followed by the d-by-d triangular design/RHS factor.
Effects: fail.
mergeOlsFactor
function mergeOlsFactor(co: mut Vec<f64>, count: i64, later: Vec<f64>, laterCount: i64): voidStack factors and the centered-mean correction without raw row replay.
Effects: fail.
qrSolve
function qrSolve(co: Vec<f64>, d: i64, units: Vec<f64>, rhs: Vec<f64>): Vec<f64> throws stringSolve in exact power-of-two column units with compensated term order. Wider temporaries use exponent-aware compensation instead of a global RHS scale.
Effects: fail.
olsInference
function olsInference(co: Vec<f64>, count: i64, fit: OlsFit): OlsInference throws stringResidual uncertainty from the same centered square-root fit, independent of result formatting.
Effects: fail.
fitOls
function fitOls(co: Vec<f64>, count: i64, overflow: bool): Option<OlsFit> throws stringIntercept-first least squares. None means too few rows or deficient rank.
Effects: fail.
Constants
OLS_RANK_SQUARED_TOLERANCE
const OLS_RANK_SQUARED_TOLERANCE = 0.000000000001The squared tolerance under which a column of a least-squares fit is counted as dependent.
MOMENT_ROUNDOFF_ULPS
const MOMENT_ROUNDOFF_ULPS = 64.0The roundoff, in units in the last place, that a moment calculation allows for.