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

Function mode

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

Source from the content-addressed store, hash-verified

225}
226
227//
228// Skewness and kurtosis use the sums of the 2nd, 3rd and 4th powers of the
229// deviations from the mean, `M2 = Σ(x − x̄)²`, `M3 = Σ(x − x̄)³` and
230// `M4 = Σ(x − x̄)⁴`. These sums are not expanded into raw power sums
231// (`Σx² − (Σx)²/n` and longer forms for `M3` and `M4`): when the data are
232// far from zero compared with their spread, the raw sums are nearly equal
233// and their difference loses all its digits (`[10⁸, 10⁸ + 1, 10⁸ + 3]` gave
234// a skewness of about `1.16·10⁸`).
235//
236// Each datum is first replaced by its deviation from the first datum (the
237// origin). This difference is exact when the two numbers are within a
238// factor of 2 of each other, and otherwise it is a number of the size of
239// the spread. The deviations are then accumulated in one pass with the
240// update of Terriberry and Pébay, which extends Welford's update to the
241// higher moments: each deviation changes the running mean and the running
242// sums through its distance to the running mean, so the rounding errors are
243// relative to the spread of the data, not to its size. A running mean held
244// at the size of the data cannot take small increments
245// (`10¹⁶ + 2/3` is not a double), which is why the origin is subtracted

Callers 1

statistics.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected