@ac-kit/math-stats 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +82 -0
- package/README.md +43 -4
- package/dist/_histogram-rules.d.ts +15 -0
- package/dist/_histogram-rules.d.ts.map +1 -0
- package/dist/_histogram-rules.js +208 -0
- package/dist/_histogram-rules.js.map +1 -0
- package/dist/hierarchical-cluster.d.ts.map +1 -1
- package/dist/hierarchical-cluster.js +10 -5
- package/dist/hierarchical-cluster.js.map +1 -1
- package/dist/histogram-edges.d.ts +92 -0
- package/dist/histogram-edges.d.ts.map +1 -0
- package/dist/histogram-edges.js +325 -0
- package/dist/histogram-edges.js.map +1 -0
- package/dist/histogram.d.ts +55 -21
- package/dist/histogram.d.ts.map +1 -1
- package/dist/histogram.js +56 -83
- package/dist/histogram.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/kmeans.d.ts.map +1 -1
- package/dist/kmeans.js +11 -6
- package/dist/kmeans.js.map +1 -1
- package/dist/kmedoids.js +2 -1
- package/dist/kmedoids.js.map +1 -1
- package/dist/quantile.d.ts +23 -3
- package/dist/quantile.d.ts.map +1 -1
- package/dist/quantile.js +58 -13
- package/dist/quantile.js.map +1 -1
- package/dist/running-statistics.d.ts +103 -0
- package/dist/running-statistics.d.ts.map +1 -0
- package/dist/running-statistics.js +283 -0
- package/dist/running-statistics.js.map +1 -0
- package/package.json +8 -8
package/dist/histogram.js
CHANGED
|
@@ -1,127 +1,96 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { quantile } from "./quantile.js";
|
|
1
|
+
import { bisectRightNumbers } from "@ac-kit/algo";
|
|
2
|
+
import { describeValue } from "@ac-kit/core";
|
|
3
|
+
import { ruleWidth_ } from "./_histogram-rules.js";
|
|
5
4
|
/**
|
|
6
5
|
* The width of a histogram bin by a rule of thumb, over the finite values of
|
|
7
6
|
* `values` (infinities and `NaN` are ignored), with `n` the count of those:
|
|
8
7
|
*
|
|
9
8
|
* - `"sturges"`: `range / (log2(n) + 1)` (Sturges, 1926), the bin count growing
|
|
10
9
|
* with the logarithm of the size; suits near-normal samples.
|
|
10
|
+
* - `"doane"`: `range / (1 + log2(n) + log2(1 + |g₁| / σ_g₁))` (Doane, 1976),
|
|
11
|
+
* Sturges' with more bins for a skewed sample, `g₁` the sample skewness and
|
|
12
|
+
* `σ_g₁ = √(6 (n − 2) / ((n + 1)(n + 3)))`; needs three values.
|
|
13
|
+
* - `"rice"`: `range / (2 · n^(1/3))`.
|
|
14
|
+
* - `"sqrt"`: `range / √n`, Excel's and many tools' default.
|
|
11
15
|
* - `"scott"`: `(24·√π / n)^(1/3) · σ` (Scott, 1979), the width minimising the
|
|
12
16
|
* integrated squared error for a normal density, with `σ` the population
|
|
13
17
|
* standard deviation.
|
|
14
18
|
* - `"freedman-diaconis"`: `2 · IQR · n^(-1/3)` (Freedman and Diaconis, 1981),
|
|
15
19
|
* with the interquartile range by linear interpolation; robust to outliers.
|
|
20
|
+
* - `"stone"`: `range / k` for the bin count `k` in `1 … max(100, ⌊√n⌋)` that
|
|
21
|
+
* minimises the leave-one-out estimate of the integrated squared error
|
|
22
|
+
* (Stone, 1984), the first such count on a tie.
|
|
23
|
+
* - `"auto"`: NumPy's default, the Freedman–Diaconis width raised to at least
|
|
24
|
+
* half the square-root rule's (so a near-zero interquartile range cannot ask
|
|
25
|
+
* for a great many bins), then capped by Sturges'.
|
|
16
26
|
*
|
|
17
|
-
* These are the definitions of NumPy's `histogram_bin_edges` (`'
|
|
18
|
-
*
|
|
27
|
+
* These are the definitions of NumPy's `histogram_bin_edges` (`'fd'` for
|
|
28
|
+
* Freedman–Diaconis), checked against NumPy 2.5.
|
|
19
29
|
*
|
|
20
|
-
* `NaN` for fewer than two finite values, for zero spread
|
|
21
|
-
* deviation or interquartile range being zero, which a
|
|
22
|
-
* of mostly equal values can have despite a non-zero
|
|
23
|
-
* underflows to zero and for an unknown rule
|
|
30
|
+
* `NaN` for fewer than two finite values (three for Doane's), for zero spread
|
|
31
|
+
* (range, standard deviation or interquartile range being zero, which a
|
|
32
|
+
* Freedman–Diaconis sample of mostly equal values can have despite a non-zero
|
|
33
|
+
* range), for a width that underflows to zero and for an unknown rule: where
|
|
34
|
+
* NumPy's estimator answers 0.
|
|
24
35
|
*
|
|
25
36
|
* The spread is measured without overflow or underflow over the whole double
|
|
26
37
|
* range: the range and the interquartile range from the values themselves, the
|
|
27
|
-
* standard deviation on the sample scaled near 1 by a power of
|
|
28
|
-
* is the representable result, rounded; `Infinity` only when it
|
|
29
|
-
* `Number.MAX_VALUE`, which Scott's
|
|
30
|
-
* the double range, and
|
|
38
|
+
* standard deviation and skewness on the sample scaled near 1 by a power of
|
|
39
|
+
* two. The width is the representable result, rounded; `Infinity` only when it
|
|
40
|
+
* exceeds `Number.MAX_VALUE`, which Scott's, Freedman–Diaconis' and Stone's
|
|
41
|
+
* (whose best may be one bin) can on a spread near the double range, and the
|
|
42
|
+
* other range-based rules never do.
|
|
31
43
|
*
|
|
32
|
-
* Time O(n) for
|
|
33
|
-
* O(n
|
|
44
|
+
* Time O(n) for the range-based rules (Sturges, Doane, Rice, square root) and
|
|
45
|
+
* Scott's, O(n log n) for Freedman–Diaconis' and `"auto"`, O(n · max(100, √n))
|
|
46
|
+
* for Stone's. Memory O(1) for Sturges', Rice's and the square-root rule; O(n)
|
|
47
|
+
* otherwise, a filtered copy.
|
|
34
48
|
*
|
|
35
49
|
* @example
|
|
36
50
|
* histogramBinWidth([1, 2, 3, 4, 5, 6, 7, 8], "sturges"); // 7 / 4
|
|
37
51
|
*
|
|
38
|
-
* @param values - The sample, in any order. Not
|
|
52
|
+
* @param values - The sample, in any order; a typed array is read as is. Not
|
|
53
|
+
* modified.
|
|
39
54
|
* @param rule - The rule to apply.
|
|
40
55
|
* @returns The bin width, positive, `Infinity` past the largest double, or
|
|
41
56
|
* `NaN`.
|
|
42
|
-
* @see {@link
|
|
57
|
+
* @see {@link histogramEdges} for the edges of bins of that width.
|
|
58
|
+
* @see {@link histogram} to count a sample into bins.
|
|
43
59
|
*/
|
|
44
60
|
export function histogramBinWidth(values, rule) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
61
|
+
let low = Infinity;
|
|
62
|
+
let high = -Infinity;
|
|
63
|
+
for (let index = 0; index < values.length; index++) {
|
|
64
|
+
const value = values[index];
|
|
65
|
+
// `value - value === 0` holds for finite numbers only.
|
|
66
|
+
if (value - value === 0) {
|
|
67
|
+
low = Math.min(low, value);
|
|
68
|
+
high = Math.max(high, value);
|
|
49
69
|
}
|
|
50
70
|
}
|
|
51
|
-
|
|
52
|
-
if (count < 2) {
|
|
53
|
-
return Number.NaN;
|
|
54
|
-
}
|
|
55
|
-
switch (rule) {
|
|
56
|
-
case "sturges": {
|
|
57
|
-
let low = finite[0];
|
|
58
|
-
let high = low;
|
|
59
|
-
for (const value of finite) {
|
|
60
|
-
low = Math.min(low, value);
|
|
61
|
-
high = Math.max(high, value);
|
|
62
|
-
}
|
|
63
|
-
return positiveOrNaN_(differenceOver_(high, low, Math.log2(count) + 1));
|
|
64
|
-
}
|
|
65
|
-
case "scott": {
|
|
66
|
-
// `populationStandardDeviation` overflows on raw values past about
|
|
67
|
-
// 1e154 (its squares) and 1e308 (its sum), so the sample is first
|
|
68
|
-
// brought near 1 by a power of two, exact. A value that rounds there
|
|
69
|
-
// moves by under 2⁻¹⁰⁷⁴ of that scale, far below the deviation of any
|
|
70
|
-
// sample whose largest value lies near 1.
|
|
71
|
-
let largest = 0;
|
|
72
|
-
for (const value of finite) {
|
|
73
|
-
largest = Math.max(largest, Math.abs(value));
|
|
74
|
-
}
|
|
75
|
-
if (largest === 0) {
|
|
76
|
-
return Number.NaN;
|
|
77
|
-
}
|
|
78
|
-
const exponent = Math.floor(Math.log2(largest));
|
|
79
|
-
for (let index = 0; index < count; index++) {
|
|
80
|
-
finite[index] = scaleByPowerOfTwo(finite[index], -exponent);
|
|
81
|
-
}
|
|
82
|
-
const width = ((24 * Math.sqrt(Math.PI)) / count) ** (1 / 3) *
|
|
83
|
-
populationStandardDeviation(finite);
|
|
84
|
-
return positiveOrNaN_(scaleByPowerOfTwo(width, exponent));
|
|
85
|
-
}
|
|
86
|
-
case "freedman-diaconis": {
|
|
87
|
-
const sorted = Float64Array.from(finite).sort();
|
|
88
|
-
return positiveOrNaN_(differenceOver_(quantile(sorted, 0.75), quantile(sorted, 0.25), count ** (1 / 3) / 2));
|
|
89
|
-
}
|
|
90
|
-
default:
|
|
91
|
-
return Number.NaN;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// `(high − low) / divisor`, with `high ≥ low`, rounded once unless the
|
|
95
|
-
// difference overflows; then the halves, exact at that magnitude, are
|
|
96
|
-
// subtracted instead.
|
|
97
|
-
function differenceOver_(high, low, divisor) {
|
|
98
|
-
const difference = high - low;
|
|
99
|
-
if (difference !== Infinity) {
|
|
100
|
-
return difference / divisor;
|
|
101
|
-
}
|
|
102
|
-
return (high / 2 - low / 2) / (divisor / 2);
|
|
103
|
-
}
|
|
104
|
-
function positiveOrNaN_(width) {
|
|
105
|
-
return width > 0 ? width : Number.NaN;
|
|
71
|
+
return low > high ? Number.NaN : ruleWidth_(values, rule, low, high);
|
|
106
72
|
}
|
|
107
73
|
/**
|
|
108
74
|
* Counts `values` into the bins that `edges` cut: bin 0 holds the values below
|
|
109
75
|
* `edges[0]`, bin `i` those at or above `edges[i - 1]` and below `edges[i]`,
|
|
110
|
-
* and the last bin those at or above the last edge
|
|
111
|
-
* the first or the last bin; a
|
|
76
|
+
* and the last bin those at or above the last edge (above it with
|
|
77
|
+
* `lastClosed`). An infinite value falls in the first or the last bin; a
|
|
78
|
+
* not-a-number value is not counted.
|
|
112
79
|
*
|
|
113
80
|
* Time O(k + n log k) for `n` values and `k` edges; memory O(k) for the counts.
|
|
114
81
|
*
|
|
115
82
|
* @example
|
|
116
83
|
* histogram([-5, 0, 9, 10, 19, 20, 500], [0, 10, 20]); // [1, 2, 2, 2]
|
|
84
|
+
* histogram([-5, 0, 9, 10, 19, 20, 500], [0, 10, 20], { lastClosed: true }); // [1, 2, 3, 1]
|
|
117
85
|
*
|
|
118
86
|
* @param values - The sample, in any order; read once.
|
|
119
|
-
* @param edges - The bin boundaries: at least one, finite, strictly ascending
|
|
87
|
+
* @param edges - The bin boundaries: at least one, finite, strictly ascending;
|
|
88
|
+
* a typed array is read as is.
|
|
120
89
|
* @returns `edges.length + 1` counts.
|
|
121
90
|
* @throws {RangeError} When `edges` is empty, holds a value that is not finite
|
|
122
91
|
* or is not strictly ascending.
|
|
123
92
|
*/
|
|
124
|
-
export function histogram(values, edges) {
|
|
93
|
+
export function histogram(values, edges, options = {}) {
|
|
125
94
|
if (edges.length === 0) {
|
|
126
95
|
throw new RangeError("edges must not be empty");
|
|
127
96
|
}
|
|
@@ -132,11 +101,15 @@ export function histogram(values, edges) {
|
|
|
132
101
|
}
|
|
133
102
|
}
|
|
134
103
|
const counts = new Array(edges.length + 1).fill(0);
|
|
104
|
+
const last = edges[edges.length - 1];
|
|
105
|
+
const lastClosed = options.lastClosed === true && edges.length > 1;
|
|
135
106
|
for (const value of values) {
|
|
136
|
-
if (
|
|
107
|
+
if (value !== value) {
|
|
137
108
|
continue;
|
|
138
109
|
}
|
|
139
|
-
const bin =
|
|
110
|
+
const bin = lastClosed && value === last
|
|
111
|
+
? edges.length - 1
|
|
112
|
+
: bisectRightNumbers(edges, value);
|
|
140
113
|
counts[bin]++;
|
|
141
114
|
}
|
|
142
115
|
return counts;
|
package/dist/histogram.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"histogram.js","sourceRoot":"","sources":["../src/histogram.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"histogram.js","sourceRoot":"","sources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AAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACnD,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAE,CAAC;QAE3B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,CAAE,CAAC,CAAC,EAAE,CAAC;YAC1E,MAAM,IAAI,UAAU,CACnB,oDAAoD,aAAa,CAAC,IAAI,CAAC,aAAa,KAAK,EAAE,CAC3F,CAAC;QACH,CAAC;IACF,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,KAAK,CAAS,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3D,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC;IACtC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAEnE,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC5B,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACrB,SAAS;QACV,CAAC;QAED,MAAM,GAAG,GACR,UAAU,IAAI,KAAK,KAAK,IAAI;YAC3B,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;YAClB,CAAC,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACrC,MAAM,CAAC,GAAG,CAAE,EAAE,CAAC;IAChB,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from "./gamma-distribution.js";
|
|
|
17
17
|
export * from "./geometric-distribution.js";
|
|
18
18
|
export * from "./hartigan-dip.js";
|
|
19
19
|
export * from "./hierarchical-cluster.js";
|
|
20
|
+
export * from "./histogram-edges.js";
|
|
20
21
|
export * from "./histogram.js";
|
|
21
22
|
export * from "./hypergeometric-distribution.js";
|
|
22
23
|
export * from "./kmeans.js";
|
|
@@ -31,6 +32,7 @@ export * from "./poisson-distribution.js";
|
|
|
31
32
|
export * from "./quantile.js";
|
|
32
33
|
export * from "./random-effects.js";
|
|
33
34
|
export * from "./regression.js";
|
|
35
|
+
export * from "./running-statistics.js";
|
|
34
36
|
export * from "./satterthwaite-degrees-of-freedom.js";
|
|
35
37
|
export * from "./sliding-median.js";
|
|
36
38
|
export * from "./student-t-distribution.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kCAAkC,CAAC;AACjD,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cA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;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uCAAuC,CAAC;AACtD,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export * from "./gamma-distribution.js";
|
|
|
17
17
|
export * from "./geometric-distribution.js";
|
|
18
18
|
export * from "./hartigan-dip.js";
|
|
19
19
|
export * from "./hierarchical-cluster.js";
|
|
20
|
+
export * from "./histogram-edges.js";
|
|
20
21
|
export * from "./histogram.js";
|
|
21
22
|
export * from "./hypergeometric-distribution.js";
|
|
22
23
|
export * from "./kmeans.js";
|
|
@@ -31,6 +32,7 @@ export * from "./poisson-distribution.js";
|
|
|
31
32
|
export * from "./quantile.js";
|
|
32
33
|
export * from "./random-effects.js";
|
|
33
34
|
export * from "./regression.js";
|
|
35
|
+
export * from "./running-statistics.js";
|
|
34
36
|
export * from "./satterthwaite-degrees-of-freedom.js";
|
|
35
37
|
export * from "./sliding-median.js";
|
|
36
38
|
export * from "./student-t-distribution.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,6BAA6B,CAAC;AAC5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,EAAE,CAAC,CAAC;IACrB,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC,CAAC;AAQF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACvB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,EACjB,OAAO,CAAC,EAAE,aAAa,GACrB,aAAa,CAAC,CAAC,CAAC,EAAE,CAwEpB"}
|
package/dist/kmeans.js
CHANGED
|
@@ -26,8 +26,9 @@ const DEFAULT_OPTIONS_ = {
|
|
|
26
26
|
* assigned indices.
|
|
27
27
|
*/
|
|
28
28
|
export function kmeans(n, k, ops, options) {
|
|
29
|
-
if (n === 0)
|
|
29
|
+
if (n === 0) {
|
|
30
30
|
return [];
|
|
31
|
+
}
|
|
31
32
|
const opts = {
|
|
32
33
|
maxIterations: options?.maxIterations ?? DEFAULT_OPTIONS_.maxIterations,
|
|
33
34
|
convergenceThreshold: options?.convergenceThreshold ?? DEFAULT_OPTIONS_.convergenceThreshold,
|
|
@@ -55,16 +56,19 @@ export function kmeans(n, k, ops, options) {
|
|
|
55
56
|
let maxMove = 0;
|
|
56
57
|
for (let c = 0; c < actualK; c++) {
|
|
57
58
|
const group = assignments[c];
|
|
58
|
-
if (group.length === 0)
|
|
59
|
-
continue;
|
|
59
|
+
if (group.length === 0) {
|
|
60
|
+
continue;
|
|
61
|
+
} // keep centroid in place
|
|
60
62
|
const prev = ops.clone(centroids[c]);
|
|
61
63
|
centroids[c] = ops.computeCentroid(group);
|
|
62
64
|
const move = ops.centroidDistance(centroids[c], prev);
|
|
63
|
-
if (move > maxMove)
|
|
65
|
+
if (move > maxMove) {
|
|
64
66
|
maxMove = move;
|
|
67
|
+
}
|
|
65
68
|
}
|
|
66
|
-
if (maxMove < opts.convergenceThreshold)
|
|
69
|
+
if (maxMove < opts.convergenceThreshold) {
|
|
67
70
|
break;
|
|
71
|
+
}
|
|
68
72
|
}
|
|
69
73
|
// Final assignment pass to get definitive cluster membership after convergence.
|
|
70
74
|
const finalGroups = Array.from({ length: actualK }, () => []);
|
|
@@ -95,8 +99,9 @@ function kmeansppInit_(n, k, ops, rand) {
|
|
|
95
99
|
let minSq = Infinity;
|
|
96
100
|
for (const c of centroids) {
|
|
97
101
|
const sq = ops.squaredDistance(i, c);
|
|
98
|
-
if (sq < minSq)
|
|
102
|
+
if (sq < minSq) {
|
|
99
103
|
minSq = sq;
|
|
104
|
+
}
|
|
100
105
|
}
|
|
101
106
|
const weighted = minSq * (ops.pointWeight?.(i) ?? 1);
|
|
102
107
|
distances.push(weighted);
|
package/dist/kmeans.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kmeans.js","sourceRoot":"","sources":["../src/kmeans.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAoEpD,MAAM,gBAAgB,GAA4B;IACjD,aAAa,EAAE,GAAG;IAClB,oBAAoB,EAAE,MAAM;IAC5B,MAAM,EAAE,IAAI;CACZ,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,MAAM,CACrB,CAAS,EACT,CAAS,EACT,GAAiB,EACjB,OAAuB;IAEvB,IAAI,CAAC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"kmeans.js","sourceRoot":"","sources":["../src/kmeans.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAoEpD,MAAM,gBAAgB,GAA4B;IACjD,aAAa,EAAE,GAAG;IAClB,oBAAoB,EAAE,MAAM;IAC5B,MAAM,EAAE,IAAI;CACZ,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,MAAM,CACrB,CAAS,EACT,CAAS,EACT,GAAiB,EACjB,OAAuB;IAEvB,IAAI,CAAC,KAAK,C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 @@ function medoidFn_(ops) {
|
|
|
33
33
|
const vi = ops.pointValue(i);
|
|
34
34
|
let total = 0;
|
|
35
35
|
for (const j of indices) {
|
|
36
|
-
if (j !== i)
|
|
36
|
+
if (j !== i) {
|
|
37
37
|
total += ops.centroidDistance(vi, ops.pointValue(j));
|
|
38
|
+
}
|
|
38
39
|
}
|
|
39
40
|
if (total < minTotal) {
|
|
40
41
|
minTotal = total;
|
package/dist/kmedoids.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kmedoids.js","sourceRoot":"","sources":["../src/kmedoids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA2C,MAAM,aAAa,CAAC;AAQ9E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,QAAQ,CACvB,CAAS,EACT,CAAS,EACT,GAAmB,EACnB,OAAuB;IAEvB,OAAO,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,GAAG,EAAE,eAAe,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;AAC3E,CAAC;AAED;;;GAGG;AACH,SAAS,SAAS,CAAI,GAAmB;IACxC,OAAO,CAAC,OAAO,EAAE,EAAE;QAClB,IAAI,QAAQ,GAAG,QAAQ,CAAC;QACxB,IAAI,OAAO,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;QAE1B,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACzB,MAAM,EAAE,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC7B,IAAI,KAAK,GAAG,CAAC,CAAC;YACd,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;gBACzB,IAAI,CAAC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"kmedoids.js","sourceRoot":"","sources":["../src/kmedoids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA2C,MAAM,aAAa,CAAC;AAQ9E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,QAAQ,CACvB,CAAS,EACT,CAAS,EACT,GAAmB,EACnB,OAAuB;IAEvB,OAAO,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,GAAG,EAAE,eAAe,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;AAC3E,CAAC;AAED;;;GAGG;AACH,SAAS,SAAS,CAAI,GAAmB;IACxC,OAAO,CAAC,OAAO,EAAE,EAAE;QAClB,IAAI,QAAQ,GAAG,QAAQ,CAAC;QACxB,IAAI,OAAO,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;QAE1B,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACzB,MAAM,EAAE,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC7B,IAAI,KAAK,GAAG,CAAC,CAAC;YACd,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;gBACzB,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;oBACb,KAAK,IAAI,GAAG,CAAC,gBAAgB,CAAC,EAAE,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;gBACtD,CAAC;YACF,CAAC;YACD,IAAI,KAAK,GAAG,QAAQ,EAAE,CAAC;gBACtB,QAAQ,GAAG,KAAK,CAAC;gBACjB,OAAO,GAAG,CAAC,CAAC;YACb,CAAC;QACF,CAAC;QAED,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC;AACH,CAAC"}
|
package/dist/quantile.d.ts
CHANGED
|
@@ -4,10 +4,30 @@
|
|
|
4
4
|
* Exact at the sample's values and free of overflow between them, even when two
|
|
5
5
|
* neighbours are further apart than `Number.MAX_VALUE`.
|
|
6
6
|
*
|
|
7
|
-
* @param sorted Values in ascending order, any array-like (a
|
|
8
|
-
* included). Not modified, not re-checked.
|
|
7
|
+
* @param sorted Values in ascending order within the range, any array-like (a
|
|
8
|
+
* typed array included). Not modified, not re-checked.
|
|
9
9
|
* @param fraction Quantile to compute, in `[0, 1]`.
|
|
10
|
+
* @param from First position of the sample in `sorted`: one group's slice of a
|
|
11
|
+
* scratch buffer reads in place, without a `subarray` view. Default `0`.
|
|
12
|
+
* @param to End position, excluded. Default `sorted.length`.
|
|
10
13
|
* @returns The quantile, or `NaN` for an empty sample.
|
|
14
|
+
* @throws {RangeError} When `from` and `to` are not integers with `0 ≤ from ≤
|
|
15
|
+
* to ≤ sorted.length`.
|
|
11
16
|
*/
|
|
12
|
-
export declare function quantile(sorted: ArrayLike<number>, fraction: number): number;
|
|
17
|
+
export declare function quantile(sorted: ArrayLike<number>, fraction: number, from?: number, to?: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* Writes {@link quantile} to `target[index]`, which allocates nothing: a double
|
|
20
|
+
* returned by a call the engine does not inline is boxed, one written to an
|
|
21
|
+
* array is not. One sorted scratch buffer can so fill an output column group by
|
|
22
|
+
* group.
|
|
23
|
+
*
|
|
24
|
+
* @param target A `Float64Array`, or a `number[]` of doubles.
|
|
25
|
+
* @param index The position written.
|
|
26
|
+
* @param sorted As for {@link quantile}.
|
|
27
|
+
* @param fraction As for {@link quantile}.
|
|
28
|
+
* @param from As for {@link quantile}.
|
|
29
|
+
* @param to As for {@link quantile}.
|
|
30
|
+
* @throws {RangeError} As {@link quantile}.
|
|
31
|
+
*/
|
|
32
|
+
export declare function writeQuantile(target: Float64Array | number[], index: number, sorted: ArrayLike<number>, fraction: number, from?: number, to?: number): void;
|
|
13
33
|
//# sourceMappingURL=quantile.d.ts.map
|
package/dist/quantile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quantile.d.ts","sourceRoot":"","sources":["../src/quantile.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quantile.d.ts","sourceRoot":"","sources":["../src/quantile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CACvB,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EACzB,QAAQ,EAAE,MAAM,EAChB,IAAI,SAAI,EACR,EAAE,GAAE,MAAsB,GACxB,MAAM,CAIR;AAwBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,YAAY,GAAG,MAAM,EAAE,EAC/B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EACzB,QAAQ,EAAE,MAAM,EAChB,IAAI,SAAI,EACR,EAAE,GAAE,MAAsB,GACxB,IAAI,CAGN"}
|
package/dist/quantile.js
CHANGED
|
@@ -4,26 +4,69 @@
|
|
|
4
4
|
* Exact at the sample's values and free of overflow between them, even when two
|
|
5
5
|
* neighbours are further apart than `Number.MAX_VALUE`.
|
|
6
6
|
*
|
|
7
|
-
* @param sorted Values in ascending order, any array-like (a
|
|
8
|
-
* included). Not modified, not re-checked.
|
|
7
|
+
* @param sorted Values in ascending order within the range, any array-like (a
|
|
8
|
+
* typed array included). Not modified, not re-checked.
|
|
9
9
|
* @param fraction Quantile to compute, in `[0, 1]`.
|
|
10
|
+
* @param from First position of the sample in `sorted`: one group's slice of a
|
|
11
|
+
* scratch buffer reads in place, without a `subarray` view. Default `0`.
|
|
12
|
+
* @param to End position, excluded. Default `sorted.length`.
|
|
10
13
|
* @returns The quantile, or `NaN` for an empty sample.
|
|
14
|
+
* @throws {RangeError} When `from` and `to` are not integers with `0 ≤ from ≤
|
|
15
|
+
* to ≤ sorted.length`.
|
|
11
16
|
*/
|
|
12
|
-
export function quantile(sorted, fraction) {
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
export function quantile(sorted, fraction, from = 0, to = sorted.length) {
|
|
18
|
+
assertRange_("quantile", sorted, from, to);
|
|
19
|
+
write_(RESULT_, 0, sorted, fraction, from, to);
|
|
20
|
+
return RESULT_[0];
|
|
21
|
+
}
|
|
22
|
+
/** Where {@link quantile} reads its result back. */
|
|
23
|
+
const RESULT_ = new Float64Array(1);
|
|
24
|
+
function assertRange_(name, sorted, from, to) {
|
|
25
|
+
if (!Number.isInteger(from) ||
|
|
26
|
+
!Number.isInteger(to) ||
|
|
27
|
+
from < 0 ||
|
|
28
|
+
from > to ||
|
|
29
|
+
to > sorted.length) {
|
|
30
|
+
throw new RangeError(`${name}: [${from}, ${to}) is not a range of [0, ${sorted.length})`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Writes {@link quantile} to `target[index]`, which allocates nothing: a double
|
|
35
|
+
* returned by a call the engine does not inline is boxed, one written to an
|
|
36
|
+
* array is not. One sorted scratch buffer can so fill an output column group by
|
|
37
|
+
* group.
|
|
38
|
+
*
|
|
39
|
+
* @param target A `Float64Array`, or a `number[]` of doubles.
|
|
40
|
+
* @param index The position written.
|
|
41
|
+
* @param sorted As for {@link quantile}.
|
|
42
|
+
* @param fraction As for {@link quantile}.
|
|
43
|
+
* @param from As for {@link quantile}.
|
|
44
|
+
* @param to As for {@link quantile}.
|
|
45
|
+
* @throws {RangeError} As {@link quantile}.
|
|
46
|
+
*/
|
|
47
|
+
export function writeQuantile(target, index, sorted, fraction, from = 0, to = sorted.length) {
|
|
48
|
+
assertRange_("writeQuantile", sorted, from, to);
|
|
49
|
+
write_(target, index, sorted, fraction, from, to);
|
|
50
|
+
}
|
|
51
|
+
function write_(target, index, sorted, fraction, from, to) {
|
|
52
|
+
const length = to - from;
|
|
53
|
+
if (length === 0) {
|
|
54
|
+
target[index] = Number.NaN;
|
|
55
|
+
return;
|
|
15
56
|
}
|
|
16
|
-
if (
|
|
17
|
-
|
|
57
|
+
if (length === 1) {
|
|
58
|
+
target[index] = sorted[from];
|
|
59
|
+
return;
|
|
18
60
|
}
|
|
19
|
-
const position = (
|
|
61
|
+
const position = (length - 1) * fraction;
|
|
20
62
|
const lower = Math.floor(position);
|
|
21
63
|
const upper = Math.ceil(position);
|
|
22
64
|
if (lower === upper) {
|
|
23
|
-
|
|
65
|
+
target[index] = sorted[from + lower];
|
|
66
|
+
return;
|
|
24
67
|
}
|
|
25
|
-
const lowerValue = sorted[lower];
|
|
26
|
-
const upperValue = sorted[upper];
|
|
68
|
+
const lowerValue = sorted[from + lower];
|
|
69
|
+
const upperValue = sorted[from + upper];
|
|
27
70
|
const weight = position - lower;
|
|
28
71
|
const difference = upperValue - lowerValue;
|
|
29
72
|
if (difference === Infinity &&
|
|
@@ -31,8 +74,10 @@ export function quantile(sorted, fraction) {
|
|
|
31
74
|
upperValue !== Infinity) {
|
|
32
75
|
// Finite neighbours further apart than the largest double: their halves,
|
|
33
76
|
// exact at that magnitude, interpolate without overflow.
|
|
34
|
-
|
|
77
|
+
target[index] =
|
|
78
|
+
2 * (lowerValue / 2 + (upperValue / 2 - lowerValue / 2) * weight);
|
|
79
|
+
return;
|
|
35
80
|
}
|
|
36
|
-
|
|
81
|
+
target[index] = lowerValue + difference * weight;
|
|
37
82
|
}
|
|
38
83
|
//# sourceMappingURL=quantile.js.map
|
package/dist/quantile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quantile.js","sourceRoot":"","sources":["../src/quantile.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quantile.js","sourceRoot":"","sources":["../src/quantile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,QAAQ,CACvB,MAAyB,EACzB,QAAgB,EAChB,IAAI,GAAG,CAAC,EACR,EAAE,GAAW,MAAM,CAAC,MAAM;IAE1B,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IAC3C,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IAC/C,OAAO,OAAO,CA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ACR,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;IACzC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClC,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QACrB,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,CAAE,CAAC;QACtC,OAAO;IACR,CAAC;IACD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,CAAE,CAAC;IACzC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,CAAE,CAAC;IACzC,MAAM,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IAChC,MAAM,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;IAC3C,IACC,UAAU,KAAK,QAAQ;QACvB,UAAU,KAAK,CAAC,QAAQ;QACxB,UAAU,KAAK,QAAQ,EACtB,CAAC;QACF,yEAAyE;QACzE,yDAAyD;QACzD,MAAM,CAAC,KAAK,CAAC;YACZ,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,GAAG,UAAU,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;QACnE,OAAO;IACR,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Count, mean, variance, minimum and maximum of numbers added one at a time,
|
|
3
|
+
* without keeping them: one pass, constant memory, and mergeable, so partitions
|
|
4
|
+
* of a data set (the groups of a column, the chunks of a stream) combine
|
|
5
|
+
* exactly as if added to one accumulator.
|
|
6
|
+
*
|
|
7
|
+
* The variance is Welford's update (1962), `delta = x − mean; mean += delta /
|
|
8
|
+
* n; m2 += delta · (x − mean)`, merged by Chan, Golub and LeVeque's pairwise
|
|
9
|
+
* rule (`m2 = m2ₐ + m2_b + delta² · nₐ · n_b / n`). The textbook `E[X²] −
|
|
10
|
+
* E[X]²` subtracts two nearly equal numbers when the mean dwarfs the spread
|
|
11
|
+
* (`1e9 + 0.1`), and loses every significant digit; here `m2` only ever
|
|
12
|
+
* accumulates non-negative terms of deviations from the running mean, so there
|
|
13
|
+
* is no cancellation. The updates work on offsets from the first number (a
|
|
14
|
+
* shifted Welford), which stay exact when the numbers cluster far from 0 where
|
|
15
|
+
* a plain running mean would round at their size (`1e12 + 0.3`): the relative
|
|
16
|
+
* error is about `n · ε` whatever the offset. Two passes with exact summation
|
|
17
|
+
* (`sampleVariance`) are a little more accurate still, but need the data twice;
|
|
18
|
+
* choose that when the values are in an array, and this when they are not, or
|
|
19
|
+
* when they come in parts.
|
|
20
|
+
*
|
|
21
|
+
* `NaN` is a missing value and is ignored, so a column with gaps adds as is. An
|
|
22
|
+
* infinite value makes the mean and variance `NaN`; the extremes stay exact.
|
|
23
|
+
* Deviations are not rescaled, so values near `Number.MAX_VALUE` overflow the
|
|
24
|
+
* variance (use `sampleVariance` there).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const statistics = new RunningStatistics();
|
|
28
|
+
* statistics.addIndexed(column, rows, groupStart, groupEnd);
|
|
29
|
+
* statistics.sampleStandardDeviation;
|
|
30
|
+
*/
|
|
31
|
+
export declare class RunningStatistics {
|
|
32
|
+
private readonly single_;
|
|
33
|
+
private readonly state_;
|
|
34
|
+
/** How many numbers were added (`NaN` excluded). */
|
|
35
|
+
get count(): number;
|
|
36
|
+
/** The arithmetic mean, or `NaN` when nothing was added. */
|
|
37
|
+
get mean(): number;
|
|
38
|
+
/** The smallest number, or `NaN` when nothing was added. */
|
|
39
|
+
get min(): number;
|
|
40
|
+
/** The largest number, or `NaN` when nothing was added. */
|
|
41
|
+
get max(): number;
|
|
42
|
+
/**
|
|
43
|
+
* The variance with Bessel's correction, or `NaN` for fewer than two numbers
|
|
44
|
+
* (where the function `sampleVariance` answers `0`).
|
|
45
|
+
*/
|
|
46
|
+
get sampleVariance(): number;
|
|
47
|
+
/** The variance of the numbers as a whole population, `NaN` when none. */
|
|
48
|
+
get populationVariance(): number;
|
|
49
|
+
get sampleStandardDeviation(): number;
|
|
50
|
+
get populationStandardDeviation(): number;
|
|
51
|
+
/** Writes {@link mean} to `target[index]`, without allocating. */
|
|
52
|
+
writeMean(target: Float64Array | number[], index: number): void;
|
|
53
|
+
/** Writes {@link min} to `target[index]`, without allocating. */
|
|
54
|
+
writeMin(target: Float64Array | number[], index: number): void;
|
|
55
|
+
/** Writes {@link max} to `target[index]`, without allocating. */
|
|
56
|
+
writeMax(target: Float64Array | number[], index: number): void;
|
|
57
|
+
/** Writes {@link sampleVariance} to `target[index]`, without allocating. */
|
|
58
|
+
writeSampleVariance(target: Float64Array | number[], index: number): void;
|
|
59
|
+
/** Writes {@link populationVariance} to `target[index]`, without allocating. */
|
|
60
|
+
writePopulationVariance(target: Float64Array | number[], index: number): void;
|
|
61
|
+
/**
|
|
62
|
+
* Writes {@link sampleStandardDeviation} to `target[index]`, without
|
|
63
|
+
* allocating.
|
|
64
|
+
*/
|
|
65
|
+
writeSampleStandardDeviation(target: Float64Array | number[], index: number): void;
|
|
66
|
+
/**
|
|
67
|
+
* Writes {@link populationStandardDeviation} to `target[index]`, without
|
|
68
|
+
* allocating.
|
|
69
|
+
*/
|
|
70
|
+
writePopulationStandardDeviation(target: Float64Array | number[], index: number): void;
|
|
71
|
+
private computeMean_;
|
|
72
|
+
private computeSampleVariance_;
|
|
73
|
+
private computePopulationVariance_;
|
|
74
|
+
private put_;
|
|
75
|
+
/** Adds one number; `NaN` is ignored. O(1). */
|
|
76
|
+
add(value: number): this;
|
|
77
|
+
/**
|
|
78
|
+
* Adds `values[from … to)`, without copying them. O(to − from).
|
|
79
|
+
*
|
|
80
|
+
* @param values Not modified.
|
|
81
|
+
* @param from First position. Default `0`.
|
|
82
|
+
* @param to End position, excluded. Default `values.length`.
|
|
83
|
+
*/
|
|
84
|
+
addRange(values: ArrayLike<number>, from?: number, to?: number): this;
|
|
85
|
+
/**
|
|
86
|
+
* Adds `values[indices[from]]`, …, `values[indices[to − 1]]`: the rows of one
|
|
87
|
+
* group of a column, in a grouping's index array, without copying them. O(to
|
|
88
|
+
* − from).
|
|
89
|
+
*
|
|
90
|
+
* @param values Not modified.
|
|
91
|
+
* @param indices Positions in `values`.
|
|
92
|
+
* @param from First position in `indices`. Default `0`.
|
|
93
|
+
* @param to End position in `indices`, excluded. Default `indices.length`.
|
|
94
|
+
*/
|
|
95
|
+
addIndexed(values: ArrayLike<number>, indices: ArrayLike<number>, from?: number, to?: number): this;
|
|
96
|
+
private foldRange_;
|
|
97
|
+
private foldIndexed_;
|
|
98
|
+
/** Adds everything `other` holds, as if its numbers had been added here. O(1). */
|
|
99
|
+
merge(other: RunningStatistics): this;
|
|
100
|
+
/** Forgets everything, to reuse the accumulator. O(1), no allocation. */
|
|
101
|
+
reset(): this;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=running-statistics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"running-statistics.d.ts","sourceRoot":"","sources":["../src/running-statistics.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAG/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuD;IAE9E,oDAAoD;IACpD,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,4DAA4D;IAC5D,IAAI,IAAI,IAAI,MAAM,CAGjB;IAED,4DAA4D;IAC5D,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,2DAA2D;IAC3D,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED;;;OA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