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

Function populationVariance

src/compute-engine/numerics/statistics.ts:70–81  ·  view source on GitHub ↗
(values: Iterable<number>)

Source from the content-addressed store, hash-verified

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`
72 * itself can overflow while the variance fits (the population variance of
73 * `[1e154, −1e154]` is `1e308`). From the first update that would overflow
74 * on, the update runs on the data divided by `scale`,
75 * the largest magnitude seen (the mean and `M2` are converted to those
76 * units, and again when a larger magnitude comes). `scale` is returned
77 * with `M2` (0 when the data never left the first branch), and the caller
78 * divides `M2` by the count before it multiplies by `scale²`, which gives
79 * `+∞` only when the variance itself is past the largest number. Data whose deviations do not overflow never leaves the first
80 * branch, so its result is the same as before, bit for bit.
81 */
82function welford(values: Iterable<number>): {
83 n: number;
84 m2: number;

Callers 2

statistics.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected