MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / bigVariance

Function bigVariance

src/compute-engine/numerics/statistics.ts:55–68  ·  view source on GitHub ↗
(values: Iterable<BigDecimal>)

Source from the content-addressed store, hash-verified

53//
54// Variance is accumulated with Welford's update — one pass, constant memory,
55// numerically stable: each value updates the running mean and the running
56// sum of squared deviations `M2` through its deviation from the mean BEFORE
57// and AFTER the update, so no two nearly equal quantities are ever
58// subtracted. The former one-pass form `Σx² − (Σx)²/n` did exactly that when
59// the data sit far from zero (`[10⁸ + 1, 10⁸ + 2, 10⁸ + 3]` has variance 1
60// and sums near 3·10¹⁶, and answered 0 at machine precision). The stream is
61// consumed once, so a lazy iterable is never buffered. Same shape for the
62// `BigDecimal` twin, so the two precisions agree on which inputs they can
63// resolve.
64//
65
66/**
67 * Welford's running mean and sum of squared deviations over a stream.
68 *
69 * The deviation `x − mean` of two finite numbers of opposite signs can
70 * overflow (`1e308 − (−1e308)`), and the update then gave an infinite mean
71 * and a NEGATIVE `M2`: the variance of `[1e308, −1e308]` was `−∞`. `M2`

Callers 2

statistics.tsFile · 0.90
bigStandardDeviationFunction · 0.85

Calls 4

addMethod · 0.65
mulMethod · 0.65
divMethod · 0.65
subMethod · 0.65

Tested by

no test coverage detected