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

Function covImpl

src/compute-engine/numerics/statistics.ts:304–322  ·  view source on GitHub ↗
(
  xsI: Iterable<number>,
  ysI: Iterable<number>,
  population: boolean
)

Source from the content-addressed store, hash-verified

302 if (unit === undefined) unit = e;
303 else if (e > unit) {
304 const k = unit - e;
305 mean = scaleByPowerOfTwo(mean, k);
306 m2 = scaleByPowerOfTwo(m2, 2 * k);
307 m3 = scaleByPowerOfTwo(m3, 3 * k);
308 m4 = scaleByPowerOfTwo(m4, 4 * k);
309 unit = e;
310 }
311 }
312 const u = unit === undefined ? 0 : scaleByPowerOfTwo(y, shift - unit);
313 const before = n;
314 n += 1;
315 const delta = u - mean;
316 const deltaN = delta / n;
317 const deltaN2 = deltaN * deltaN;
318 const term = delta * deltaN * before;
319 mean += deltaN;
320 // `M4` uses the values of `M2` and `M3` before this update, and `M3`
321 // uses the value of `M2` before this update.
322 m4 +=
323 term * deltaN2 * (n * n - 3 * n + 3) + 6 * deltaN2 * m2 - 4 * deltaN * m3;
324 m3 += term * deltaN * (n - 2) - 3 * deltaN * m2;
325 m2 += term;

Callers 2

covarianceFunction · 0.85
populationCovarianceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected