@ac-kit/math-stats 0.5.0 → 0.7.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.
Files changed (165) hide show
  1. package/CHANGELOG.md +205 -0
  2. package/README.md +86 -6
  3. package/dist/_digamma.d.ts +10 -0
  4. package/dist/_digamma.d.ts.map +1 -0
  5. package/dist/_digamma.js +38 -0
  6. package/dist/_digamma.js.map +1 -0
  7. package/dist/_dilogarithm.d.ts +14 -0
  8. package/dist/_dilogarithm.d.ts.map +1 -0
  9. package/dist/_dilogarithm.js +77 -0
  10. package/dist/_dilogarithm.js.map +1 -0
  11. package/dist/_histogram-rules.d.ts +15 -0
  12. package/dist/_histogram-rules.d.ts.map +1 -0
  13. package/dist/_histogram-rules.js +208 -0
  14. package/dist/_histogram-rules.js.map +1 -0
  15. package/dist/_incomplete-gamma-shape-derivative.d.ts +17 -0
  16. package/dist/_incomplete-gamma-shape-derivative.d.ts.map +1 -0
  17. package/dist/_incomplete-gamma-shape-derivative.js +90 -0
  18. package/dist/_incomplete-gamma-shape-derivative.js.map +1 -0
  19. package/dist/_logistic.d.ts +14 -0
  20. package/dist/_logistic.d.ts.map +1 -0
  21. package/dist/_logistic.js +29 -0
  22. package/dist/_logistic.js.map +1 -0
  23. package/dist/_normal-tail.d.ts +43 -0
  24. package/dist/_normal-tail.d.ts.map +1 -0
  25. package/dist/_normal-tail.js +124 -0
  26. package/dist/_normal-tail.js.map +1 -0
  27. package/dist/_rank-test.d.ts +71 -0
  28. package/dist/_rank-test.d.ts.map +1 -0
  29. package/dist/_rank-test.js +130 -0
  30. package/dist/_rank-test.js.map +1 -0
  31. package/dist/average.js +2 -2
  32. package/dist/average.js.map +1 -1
  33. package/dist/bootstrap.d.ts +67 -0
  34. package/dist/bootstrap.d.ts.map +1 -0
  35. package/dist/bootstrap.js +154 -0
  36. package/dist/bootstrap.js.map +1 -0
  37. package/dist/censored-logistic-distribution.d.ts +23 -0
  38. package/dist/censored-logistic-distribution.d.ts.map +1 -0
  39. package/dist/censored-logistic-distribution.js +63 -0
  40. package/dist/censored-logistic-distribution.js.map +1 -0
  41. package/dist/censored-shifted-gamma-distribution.d.ts +23 -0
  42. package/dist/censored-shifted-gamma-distribution.d.ts.map +1 -0
  43. package/dist/censored-shifted-gamma-distribution.js +73 -0
  44. package/dist/censored-shifted-gamma-distribution.js.map +1 -0
  45. package/dist/confidence-interval.d.ts +53 -0
  46. package/dist/confidence-interval.d.ts.map +1 -1
  47. package/dist/confidence-interval.js +73 -0
  48. package/dist/confidence-interval.js.map +1 -1
  49. package/dist/correlation.d.ts +41 -0
  50. package/dist/correlation.d.ts.map +1 -1
  51. package/dist/correlation.js +168 -2
  52. package/dist/correlation.js.map +1 -1
  53. package/dist/descriptive.d.ts +129 -0
  54. package/dist/descriptive.d.ts.map +1 -0
  55. package/dist/descriptive.js +289 -0
  56. package/dist/descriptive.js.map +1 -0
  57. package/dist/forecast/_forecast-checks.d.ts +30 -0
  58. package/dist/forecast/_forecast-checks.d.ts.map +1 -0
  59. package/dist/forecast/_forecast-checks.js +119 -0
  60. package/dist/forecast/_forecast-checks.js.map +1 -0
  61. package/dist/forecast/_score-kernels.d.ts +63 -0
  62. package/dist/forecast/_score-kernels.d.ts.map +1 -0
  63. package/dist/forecast/_score-kernels.js +264 -0
  64. package/dist/forecast/_score-kernels.js.map +1 -0
  65. package/dist/forecast/brier-score.d.ts +102 -0
  66. package/dist/forecast/brier-score.d.ts.map +1 -0
  67. package/dist/forecast/brier-score.js +163 -0
  68. package/dist/forecast/brier-score.js.map +1 -0
  69. package/dist/forecast/crps-closed-form.d.ts +64 -0
  70. package/dist/forecast/crps-closed-form.d.ts.map +1 -0
  71. package/dist/forecast/crps-closed-form.js +106 -0
  72. package/dist/forecast/crps-closed-form.js.map +1 -0
  73. package/dist/forecast/crps-ensemble.d.ts +53 -0
  74. package/dist/forecast/crps-ensemble.d.ts.map +1 -0
  75. package/dist/forecast/crps-ensemble.js +121 -0
  76. package/dist/forecast/crps-ensemble.js.map +1 -0
  77. package/dist/forecast/emos.d.ts +158 -0
  78. package/dist/forecast/emos.d.ts.map +1 -0
  79. package/dist/forecast/emos.js +397 -0
  80. package/dist/forecast/emos.js.map +1 -0
  81. package/dist/forecast/exceedance-probability.d.ts +54 -0
  82. package/dist/forecast/exceedance-probability.d.ts.map +1 -0
  83. package/dist/forecast/exceedance-probability.js +125 -0
  84. package/dist/forecast/exceedance-probability.js.map +1 -0
  85. package/dist/forecast/log-score.d.ts +18 -0
  86. package/dist/forecast/log-score.d.ts.map +1 -0
  87. package/dist/forecast/log-score.js +19 -0
  88. package/dist/forecast/log-score.js.map +1 -0
  89. package/dist/forecast/logistic-regression.d.ts +123 -0
  90. package/dist/forecast/logistic-regression.d.ts.map +1 -0
  91. package/dist/forecast/logistic-regression.js +282 -0
  92. package/dist/forecast/logistic-regression.js.map +1 -0
  93. package/dist/forecast/rank-histogram.d.ts +32 -0
  94. package/dist/forecast/rank-histogram.d.ts.map +1 -0
  95. package/dist/forecast/rank-histogram.js +63 -0
  96. package/dist/forecast/rank-histogram.js.map +1 -0
  97. package/dist/forecast/reliability-diagram.d.ts +70 -0
  98. package/dist/forecast/reliability-diagram.d.ts.map +1 -0
  99. package/dist/forecast/reliability-diagram.js +126 -0
  100. package/dist/forecast/reliability-diagram.js.map +1 -0
  101. package/dist/forecast/roc-curve.d.ts +58 -0
  102. package/dist/forecast/roc-curve.d.ts.map +1 -0
  103. package/dist/forecast/roc-curve.js +124 -0
  104. package/dist/forecast/roc-curve.js.map +1 -0
  105. package/dist/hierarchical-cluster.d.ts.map +1 -1
  106. package/dist/hierarchical-cluster.js +10 -5
  107. package/dist/hierarchical-cluster.js.map +1 -1
  108. package/dist/histogram-edges.d.ts +92 -0
  109. package/dist/histogram-edges.d.ts.map +1 -0
  110. package/dist/histogram-edges.js +325 -0
  111. package/dist/histogram-edges.js.map +1 -0
  112. package/dist/histogram.d.ts +55 -21
  113. package/dist/histogram.d.ts.map +1 -1
  114. package/dist/histogram.js +56 -83
  115. package/dist/histogram.js.map +1 -1
  116. package/dist/index.d.ts +23 -0
  117. package/dist/index.d.ts.map +1 -1
  118. package/dist/index.js +23 -0
  119. package/dist/index.js.map +1 -1
  120. package/dist/kmeans.d.ts.map +1 -1
  121. package/dist/kmeans.js +11 -6
  122. package/dist/kmeans.js.map +1 -1
  123. package/dist/kmedoids.js +2 -1
  124. package/dist/kmedoids.js.map +1 -1
  125. package/dist/mann-whitney-u.d.ts +27 -0
  126. package/dist/mann-whitney-u.d.ts.map +1 -0
  127. package/dist/mann-whitney-u.js +94 -0
  128. package/dist/mann-whitney-u.js.map +1 -0
  129. package/dist/multiple-regression.d.ts +123 -0
  130. package/dist/multiple-regression.d.ts.map +1 -0
  131. package/dist/multiple-regression.js +208 -0
  132. package/dist/multiple-regression.js.map +1 -0
  133. package/dist/principal-components.d.ts +66 -0
  134. package/dist/principal-components.d.ts.map +1 -0
  135. package/dist/principal-components.js +105 -0
  136. package/dist/principal-components.js.map +1 -0
  137. package/dist/quantile.d.ts +113 -5
  138. package/dist/quantile.d.ts.map +1 -1
  139. package/dist/quantile.js +318 -19
  140. package/dist/quantile.js.map +1 -1
  141. package/dist/regression.d.ts +46 -0
  142. package/dist/regression.d.ts.map +1 -1
  143. package/dist/regression.js +99 -1
  144. package/dist/regression.js.map +1 -1
  145. package/dist/running-statistics.d.ts +103 -0
  146. package/dist/running-statistics.d.ts.map +1 -0
  147. package/dist/running-statistics.js +283 -0
  148. package/dist/running-statistics.js.map +1 -0
  149. package/dist/sample.d.ts +29 -0
  150. package/dist/sample.d.ts.map +1 -0
  151. package/dist/sample.js +39 -0
  152. package/dist/sample.js.map +1 -0
  153. package/dist/t-digest.d.ts +136 -0
  154. package/dist/t-digest.d.ts.map +1 -0
  155. package/dist/t-digest.js +424 -0
  156. package/dist/t-digest.js.map +1 -0
  157. package/dist/truncated-normal-distribution.d.ts +28 -0
  158. package/dist/truncated-normal-distribution.d.ts.map +1 -0
  159. package/dist/truncated-normal-distribution.js +198 -0
  160. package/dist/truncated-normal-distribution.js.map +1 -0
  161. package/dist/wilcoxon-signed-rank.d.ts +42 -0
  162. package/dist/wilcoxon-signed-rank.d.ts.map +1 -0
  163. package/dist/wilcoxon-signed-rank.js +117 -0
  164. package/dist/wilcoxon-signed-rank.js.map +1 -0
  165. package/package.json +14 -10
@@ -0,0 +1,325 @@
1
+ import { assertInteger, assertPositive, describeValue, nextAfter, } from "@ac-kit/core";
2
+ import { tickIncrement } from "@ac-kit/math-scalar";
3
+ import { differenceOver_, linspaceEdge_, ruleWidth_, } from "./_histogram-rules.js";
4
+ // More bins than this cannot be held (their edges would fill 32 GiB).
5
+ const MAX_BINS_ = 2 ** 32 - 2;
6
+ // A rule's width within this relative distance of a round step takes that step:
7
+ // the width is computed in floating point, the step exact.
8
+ const ROUND_TOLERANCE_ = 1e-12;
9
+ const RULES_ = new Set([
10
+ "auto",
11
+ "freedman-diaconis",
12
+ "scott",
13
+ "sturges",
14
+ "doane",
15
+ "rice",
16
+ "sqrt",
17
+ "stone",
18
+ ]);
19
+ function gridOfIncrement_(increment) {
20
+ return increment < 0
21
+ ? { step: 1 / -increment, divisor: -increment }
22
+ : { step: increment, divisor: 0 };
23
+ }
24
+ // A width given as is; one within 10⁻⁹ of the reciprocal of an integer puts its
25
+ // edges at exact quotients.
26
+ function gridOfWidth_(width) {
27
+ const divisor = Math.round(1 / width);
28
+ return width < 1 && Math.abs(1 / width - divisor) < 1e-9 * divisor
29
+ ? { step: 1 / divisor, divisor }
30
+ : { step: width, divisor: 0 };
31
+ }
32
+ function gridEdge_(grid, index) {
33
+ return grid.divisor === 0 ? index * grid.step : index / grid.divisor;
34
+ }
35
+ // The 1, 2 or 5 times a power of ten nearest `width`, on a logarithmic scale
36
+ // (`[0, width]` holds a multiple of every step, 0, so none is skipped).
37
+ function nearestRoundGrid_(width) {
38
+ const increment = tickIncrement(0, width, 1);
39
+ return increment === increment ? gridOfIncrement_(increment) : undefined;
40
+ }
41
+ // The next of 1, 2, 5, 10, … after a step of that sequence.
42
+ function nextRoundGrid_(grid) {
43
+ return nearestRoundGrid_(grid.step * 2.5);
44
+ }
45
+ // The smallest 1, 2 or 5 times a power of ten at least `width`.
46
+ function roundGridAtLeast_(width) {
47
+ let grid = nearestRoundGrid_(width);
48
+ while (grid !== undefined && grid.step < width * (1 - ROUND_TOLERANCE_)) {
49
+ grid = nextRoundGrid_(grid);
50
+ }
51
+ return grid;
52
+ }
53
+ // The indices of the multiples of `grid` at or below `low` and at or above
54
+ // `high`, checked against the edges themselves; at least one bin apart.
55
+ function cover_(grid, low, high) {
56
+ const scale = (value) => grid.divisor === 0 ? value / grid.step : value * grid.divisor;
57
+ let first = Math.floor(scale(low));
58
+ if (gridEdge_(grid, first + 1) <= low) {
59
+ first++;
60
+ }
61
+ else if (gridEdge_(grid, first) > low) {
62
+ first--;
63
+ }
64
+ let last = Math.ceil(scale(high));
65
+ if (gridEdge_(grid, last - 1) >= high) {
66
+ last--;
67
+ }
68
+ else if (gridEdge_(grid, last) < high) {
69
+ last++;
70
+ }
71
+ return { first, last: Math.max(last, first + 1) };
72
+ }
73
+ function assertBinCount_(bins) {
74
+ if (!(bins <= MAX_BINS_)) {
75
+ throw new RangeError(`histogramEdges: ${describeValue(bins)} bins, more than ${MAX_BINS_}; pass a maxCount`);
76
+ }
77
+ }
78
+ // Merges edges a range too narrow for its bin count rounds onto one double,
79
+ // so the edges stay strictly ascending. The first and last differ, so both
80
+ // stay.
81
+ function strictlyAscending_(edges) {
82
+ let kept = 1;
83
+ for (let index = 1; index < edges.length; index++) {
84
+ if (edges[index] > edges[kept - 1]) {
85
+ edges[kept++] = edges[index];
86
+ }
87
+ }
88
+ return kept === edges.length ? edges : edges.slice(0, kept);
89
+ }
90
+ function checkOptions_(options) {
91
+ const { rule, width, count, maxCount, range } = options;
92
+ if (width !== undefined) {
93
+ assertPositive(width, "histogramEdges: width");
94
+ if (rule !== undefined || count !== undefined || maxCount !== undefined) {
95
+ throw new RangeError("histogramEdges: width excludes rule, count and maxCount");
96
+ }
97
+ }
98
+ if (count !== undefined) {
99
+ assertInteger(count, "histogramEdges: count", 1);
100
+ if (rule !== undefined) {
101
+ throw new RangeError("histogramEdges: count excludes rule");
102
+ }
103
+ }
104
+ if (maxCount !== undefined) {
105
+ assertInteger(maxCount, "histogramEdges: maxCount", 1);
106
+ }
107
+ if (rule !== undefined && !RULES_.has(rule)) {
108
+ throw new RangeError(`histogramEdges: unknown rule ${describeValue(rule)}`);
109
+ }
110
+ if (range !== undefined) {
111
+ const [low, high] = range;
112
+ if (!(low - low === 0 && high - high === 0 && low <= high)) {
113
+ throw new RangeError(`histogramEdges: range must be finite with low ≤ high, got [${describeValue(low)}, ${describeValue(high)}]`);
114
+ }
115
+ }
116
+ }
117
+ // The width the rule gives the sample; Sturges' where the rule finds none
118
+ // though there is a spread (a zero interquartile range, fewer than three
119
+ // values for Doane's).
120
+ function chosenWidth_(values, rule, low, high) {
121
+ const width = ruleWidth_(values, rule, low, high);
122
+ return width === width || rule === "sturges"
123
+ ? width
124
+ : ruleWidth_(values, "sturges", low, high);
125
+ }
126
+ function plainEdges_(values, options, low, high) {
127
+ const { width, count, maxCount } = options;
128
+ if (width !== undefined) {
129
+ let bins = Math.max(1, Math.ceil(differenceOver_(high, low, width)));
130
+ assertBinCount_(bins);
131
+ while (low + bins * width < high) {
132
+ bins++;
133
+ }
134
+ const edges = new Float64Array(bins + 1);
135
+ for (let index = 0; index <= bins; index++) {
136
+ edges[index] = low + index * width;
137
+ }
138
+ if (edges[bins] === Infinity) {
139
+ throw new RangeError(`histogramEdges: bins of width ${width} from ${low} leave the double range`);
140
+ }
141
+ return strictlyAscending_(edges);
142
+ }
143
+ let bins = count;
144
+ if (bins === undefined) {
145
+ const ruleWidth = chosenWidth_(values, options.rule ?? "auto", low, high);
146
+ bins =
147
+ ruleWidth === ruleWidth
148
+ ? Math.max(1, Math.ceil(differenceOver_(high, low, ruleWidth)))
149
+ : 1;
150
+ }
151
+ if (maxCount !== undefined) {
152
+ bins = Math.min(bins, maxCount);
153
+ }
154
+ assertBinCount_(bins);
155
+ const edges = new Float64Array(bins + 1);
156
+ for (let index = 0; index <= bins; index++) {
157
+ edges[index] = linspaceEdge_(low, high, bins, index);
158
+ }
159
+ return strictlyAscending_(edges);
160
+ }
161
+ function niceEdges_(values, options, low, high) {
162
+ const { width, count, maxCount } = options;
163
+ // A single value takes its own magnitude as the span, as Vega's does.
164
+ const spanOver = (divisor) => low === high
165
+ ? (Math.abs(low) || 1) / divisor
166
+ : differenceOver_(high, low, divisor);
167
+ let grid;
168
+ if (width === undefined) {
169
+ let target;
170
+ if (count === undefined) {
171
+ target = chosenWidth_(values, options.rule ?? "auto", low, high);
172
+ if (target !== target) {
173
+ target = spanOver(maxCount ?? 1);
174
+ }
175
+ }
176
+ else {
177
+ target = spanOver(count);
178
+ }
179
+ grid = roundGridAtLeast_(target);
180
+ }
181
+ else {
182
+ grid = gridOfWidth_(width);
183
+ }
184
+ const magnitude = Math.max(Math.abs(low), Math.abs(high));
185
+ for (;;) {
186
+ if (grid === undefined) {
187
+ throw new RangeError(`histogramEdges: no round width covers [${low}, ${high}] within the double range`);
188
+ }
189
+ // A grid finer than the doubles at a single value, whose multiples'
190
+ // indices may not even be finite.
191
+ if (low === high &&
192
+ low !== 0 &&
193
+ grid.step <= Math.abs(low - nextAfter(low, 0))) {
194
+ return singleValueEdges_(low);
195
+ }
196
+ const { first, last } = cover_(grid, low, high);
197
+ const bins = last - first;
198
+ if (maxCount === undefined || bins <= maxCount) {
199
+ assertBinCount_(bins);
200
+ const edges = gridEdges_(grid, first, last, 1);
201
+ // across a binade boundary, multiples a little coarser still merge
202
+ return edges.length > 1 ? edges : singleValueEdges_(edges[0]);
203
+ }
204
+ // A step past every value leaves a range across 0 two bins, [−s, 0]
205
+ // and [0, s]; with one bin allowed, they make one.
206
+ if (grid.step >= magnitude) {
207
+ return gridEdges_(grid, first, last, last - first);
208
+ }
209
+ grid = nextRoundGrid_(grid);
210
+ }
211
+ }
212
+ // A single value where the width is finer than the doubles' spacing has its
213
+ // enclosing multiples round onto itself. Its neighbouring double is then the
214
+ // rounding of a multiple too (the multiples are closer than the doubles), so
215
+ // the bin runs from the value to the next double up, or from the one below
216
+ // at `Number.MAX_VALUE`.
217
+ function singleValueEdges_(value) {
218
+ const above = nextAfter(value, Infinity);
219
+ return above === Infinity
220
+ ? Float64Array.of(nextAfter(value, -Infinity), value)
221
+ : Float64Array.of(value, above);
222
+ }
223
+ // The multiples of `grid` from index `first` to `last`, every `stride`th.
224
+ function gridEdges_(grid, first, last, stride) {
225
+ const edges = new Float64Array((last - first) / stride + 1);
226
+ for (let position = 0; position < edges.length; position++) {
227
+ edges[position] = gridEdge_(grid, first + position * stride);
228
+ }
229
+ if (edges[0] === -Infinity || edges[edges.length - 1] === Infinity) {
230
+ throw new RangeError(`histogramEdges: the multiples of ${grid.step} covering the range leave the double range`);
231
+ }
232
+ return strictlyAscending_(edges);
233
+ }
234
+ /**
235
+ * The edges of a histogram's bins over the finite values of `values`: equal
236
+ * bins as NumPy's `histogram_bin_edges` cuts them, or, with `nice`, round edges
237
+ * as Vega's `bin` places them. The bins are half-open, `[edges[i], edges[i +
238
+ * 1])`, but for the last, which is closed; {@link histogram} counts into them
239
+ * with `lastClosed`.
240
+ *
241
+ * **The range** is `range`, or the extent of the finite values; `[0, 1]` when
242
+ * there are none. `NaN` and the infinities are ignored, there and in the rule's
243
+ * sample, where NumPy refuses a range that is not finite. An empty range (a
244
+ * single value) is widened to `[x − 0.5, x + 0.5]`, as NumPy does (to the
245
+ * neighbouring doubles where 0.5 is below their spacing); with `nice`, it takes
246
+ * the value's magnitude (or 1 for 0) as its span, as Vega does.
247
+ *
248
+ * **The width** is `width`; or the range over `count`; or the `rule`'s over the
249
+ * values within the range ({@link histogramBinWidth}, default `"auto"`). Where
250
+ * a rule finds no width though the values spread (Freedman–Diaconis' zero
251
+ * interquartile range, Doane's fewer than three values, Stone's), Sturges'
252
+ * stands in, where NumPy would make one bin; where none can (fewer than two
253
+ * values in the range, or all equal), there is one bin, or with `nice` as many
254
+ * as `maxCount` allows.
255
+ *
256
+ * **Equal bins** (the default) run from the low end to the high end, their
257
+ * count the range over the width rounded up and at most `maxCount`; edge `i` is
258
+ * `low + i · (high − low) / count`, the last `high` itself, as NumPy's
259
+ * `linspace`. A `width` instead gives edges `low + i · width`, the last at or
260
+ * past `high`.
261
+ *
262
+ * **Nice bins** have a width of 1, 2 or 5 times a power of ten, the smallest at
263
+ * least the rule's or `count`'s (within 10⁻¹²), widened along that sequence
264
+ * until there are at most `maxCount` bins; edges are its multiples, from the
265
+ * one at or below the range to the one at or above it, a step below 1 dividing
266
+ * an integer index so that 0.3 is 0.3. A `width` is kept as given, its edges on
267
+ * its multiples (exact quotients when it is within 10⁻⁹ of the reciprocal of an
268
+ * integer). A range across 0 makes two bins at least; a `maxCount` of 1 joins
269
+ * them into one, `[−s, s]`.
270
+ *
271
+ * Edges are strictly ascending and finite: a range holding fewer doubles than
272
+ * bins has the edges that round together merged. With `nice`, a single value
273
+ * where the multiples of the width are closer than the doubles (a `width` of
274
+ * 0.1 at 10¹⁶) gets one bin from the value to the next double up (from the one
275
+ * below at `Number.MAX_VALUE`), both roundings of multiples: always two edges
276
+ * around it, as without `nice`.
277
+ *
278
+ * Time O(n + k) for `n` values and `k` bins, plus the rule's
279
+ * ({@link histogramBinWidth}); memory O(k), plus the rule's.
280
+ *
281
+ * @example
282
+ * histogramEdges([1, 2, 2, 3, 7], { count: 3 }); // [1, 3, 5, 7]
283
+ * histogramEdges([0.13, 4.2, 9.7], { count: 4, nice: true }); // [0, 5, 10]
284
+ *
285
+ * @param values - The sample, in any order; a typed array is read as is. Not
286
+ * modified.
287
+ * @param options - How to choose the bins.
288
+ * @returns At least two edges, strictly ascending.
289
+ * @throws {RangeError} For a `width` that is not finite and positive, a `count`
290
+ * or `maxCount` that is not an integer ≥ 1, an unknown `rule`, a `range` that
291
+ * is not finite and ordered, options that exclude each other, more than 2³² −
292
+ * 2 bins, and edges that would leave the double range.
293
+ */
294
+ export function histogramEdges(values, options = {}) {
295
+ checkOptions_(options);
296
+ let low = Infinity;
297
+ let high = -Infinity;
298
+ if (options.range === undefined) {
299
+ for (let index = 0; index < values.length; index++) {
300
+ const value = values[index];
301
+ if (value - value === 0) {
302
+ low = Math.min(low, value);
303
+ high = Math.max(high, value);
304
+ }
305
+ }
306
+ if (low > high) {
307
+ low = 0;
308
+ high = 1;
309
+ }
310
+ }
311
+ else {
312
+ [low, high] = options.range;
313
+ }
314
+ if (options.nice === true) {
315
+ return niceEdges_(values, options, low, high);
316
+ }
317
+ if (low === high) {
318
+ const below = low - 0.5;
319
+ const above = high + 0.5;
320
+ low = below === low ? nextAfter(low, -Infinity) : below;
321
+ high = above === high ? nextAfter(high, Infinity) : above;
322
+ }
323
+ return plainEdges_(values, options, low, high);
324
+ }
325
+ //# sourceMappingURL=histogram-edges.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"histogram-edges.js","sourceRoot":"","sources":["../src/histogram-edges.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,cAAc,EACd,aAAa,EACb,SAAS,GACT,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EACN,eAAe,EACf,aAAa,EACb,UAAU,GACV,MAAM,uBAAuB,CAAC;AAiC/B,sEAAsE;AACtE,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC9B,gFAAgF;AAChF,2DAA2D;AAC3D,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,MAAM,MAAM,GAAwB,IAAI,GAAG,CAAmB;IAC7D,MAAM;IACN,mBAAmB;IACnB,OAAO;IACP,SAAS;IACT,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;CACP,CAAC,CAAC;AASH,SAAS,gBAAgB,CAAC,SAAiB;IAC1C,OAAO,SAAS,G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AI,KAAK,IAAI,EAAE,CAAC;QAC3B,OAAO,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IACD,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAClB,MAAM,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;QACxB,MAAM,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC;QACzB,GAAG,GAAG,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACxD,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC3D,CAAC;IACD,OAAO,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAChD,CAAC"}
@@ -1,61 +1,95 @@
1
- /** The rules {@link histogramBinWidth} knows. */
2
- export type HistogramBinRule = "sturges" | "scott" | "freedman-diaconis";
1
+ /**
2
+ * The rules of thumb for a histogram's bin width, NumPy's `histogram_bin_edges`
3
+ * estimators of the same names (`'fd'` for `"freedman-diaconis"`).
4
+ */
5
+ export type HistogramBinRule = "auto" | "freedman-diaconis" | "scott" | "sturges" | "doane" | "rice" | "sqrt" | "stone";
3
6
  /**
4
7
  * The width of a histogram bin by a rule of thumb, over the finite values of
5
8
  * `values` (infinities and `NaN` are ignored), with `n` the count of those:
6
9
  *
7
10
  * - `"sturges"`: `range / (log2(n) + 1)` (Sturges, 1926), the bin count growing
8
11
  * with the logarithm of the size; suits near-normal samples.
12
+ * - `"doane"`: `range / (1 + log2(n) + log2(1 + |g₁| / σ_g₁))` (Doane, 1976),
13
+ * Sturges' with more bins for a skewed sample, `g₁` the sample skewness and
14
+ * `σ_g₁ = √(6 (n − 2) / ((n + 1)(n + 3)))`; needs three values.
15
+ * - `"rice"`: `range / (2 · n^(1/3))`.
16
+ * - `"sqrt"`: `range / √n`, Excel's and many tools' default.
9
17
  * - `"scott"`: `(24·√π / n)^(1/3) · σ` (Scott, 1979), the width minimising the
10
18
  * integrated squared error for a normal density, with `σ` the population
11
19
  * standard deviation.
12
20
  * - `"freedman-diaconis"`: `2 · IQR · n^(-1/3)` (Freedman and Diaconis, 1981),
13
21
  * with the interquartile range by linear interpolation; robust to outliers.
22
+ * - `"stone"`: `range / k` for the bin count `k` in `1 … max(100, ⌊√n⌋)` that
23
+ * minimises the leave-one-out estimate of the integrated squared error
24
+ * (Stone, 1984), the first such count on a tie.
25
+ * - `"auto"`: NumPy's default, the Freedman–Diaconis width raised to at least
26
+ * half the square-root rule's (so a near-zero interquartile range cannot ask
27
+ * for a great many bins), then capped by Sturges'.
14
28
  *
15
- * These are the definitions of NumPy's `histogram_bin_edges` (`'sturges'`,
16
- * `'scott'`, `'fd'`).
29
+ * These are the definitions of NumPy's `histogram_bin_edges` (`'fd'` for
30
+ * Freedman–Diaconis), checked against NumPy 2.5.
17
31
  *
18
- * `NaN` for fewer than two finite values, for zero spread (range, standard
19
- * deviation or interquartile range being zero, which a Freedman–Diaconis sample
20
- * of mostly equal values can have despite a non-zero range), for a width that
21
- * underflows to zero and for an unknown rule.
32
+ * `NaN` for fewer than two finite values (three for Doane's), for zero spread
33
+ * (range, standard deviation or interquartile range being zero, which a
34
+ * Freedman–Diaconis sample of mostly equal values can have despite a non-zero
35
+ * range), for a width that underflows to zero and for an unknown rule: where
36
+ * NumPy's estimator answers 0.
22
37
  *
23
38
  * The spread is measured without overflow or underflow over the whole double
24
39
  * range: the range and the interquartile range from the values themselves, the
25
- * standard deviation on the sample scaled near 1 by a power of two. The width
26
- * is the representable result, rounded; `Infinity` only when it exceeds
27
- * `Number.MAX_VALUE`, which Scott's and Freedman–Diaconis' can on a spread near
28
- * the double range, and Sturges' never does.
40
+ * standard deviation and skewness on the sample scaled near 1 by a power of
41
+ * two. The width is the representable result, rounded; `Infinity` only when it
42
+ * exceeds `Number.MAX_VALUE`, which Scott's, Freedman–Diaconis' and Stone's
43
+ * (whose best may be one bin) can on a spread near the double range, and the
44
+ * other range-based rules never do.
29
45
  *
30
- * Time O(n) for Sturges and Scott, O(n log n) for Freedman–Diaconis; memory
31
- * O(n): a filtered copy, sorted for Freedman–Diaconis.
46
+ * Time O(n) for the range-based rules (Sturges, Doane, Rice, square root) and
47
+ * Scott's, O(n log n) for Freedman–Diaconis' and `"auto"`, O(n · max(100, √n))
48
+ * for Stone's. Memory O(1) for Sturges', Rice's and the square-root rule; O(n)
49
+ * otherwise, a filtered copy.
32
50
  *
33
51
  * @example
34
52
  * histogramBinWidth([1, 2, 3, 4, 5, 6, 7, 8], "sturges"); // 7 / 4
35
53
  *
36
- * @param values - The sample, in any order. Not modified.
54
+ * @param values - The sample, in any order; a typed array is read as is. Not
55
+ * modified.
37
56
  * @param rule - The rule to apply.
38
57
  * @returns The bin width, positive, `Infinity` past the largest double, or
39
58
  * `NaN`.
40
- * @see {@link histogram} to count a sample into bins of that width.
59
+ * @see {@link histogramEdges} for the edges of bins of that width.
60
+ * @see {@link histogram} to count a sample into bins.
41
61
  */
42
- export declare function histogramBinWidth(values: readonly number[], rule: HistogramBinRule): number;
62
+ export declare function histogramBinWidth(values: ArrayLike<number>, rule: HistogramBinRule): number;
63
+ /** Options of {@link histogram}. */
64
+ export type HistogramOptions = {
65
+ /**
66
+ * Whether the last edge closes the last bin between edges, as
67
+ * {@link histogramEdges}' bins and NumPy's are: a value equal to it is then
68
+ * counted in `counts[edges.length - 1]` rather than in the overflow bin.
69
+ * Without a second edge there is no such bin, and it changes nothing. Default
70
+ * `false`.
71
+ */
72
+ readonly lastClosed?: boolean | undefined;
73
+ };
43
74
  /**
44
75
  * Counts `values` into the bins that `edges` cut: bin 0 holds the values below
45
76
  * `edges[0]`, bin `i` those at or above `edges[i - 1]` and below `edges[i]`,
46
- * and the last bin those at or above the last edge. An infinite value falls in
47
- * the first or the last bin; a not-a-number value is not counted.
77
+ * and the last bin those at or above the last edge (above it with
78
+ * `lastClosed`). An infinite value falls in the first or the last bin; a
79
+ * not-a-number value is not counted.
48
80
  *
49
81
  * Time O(k + n log k) for `n` values and `k` edges; memory O(k) for the counts.
50
82
  *
51
83
  * @example
52
84
  * histogram([-5, 0, 9, 10, 19, 20, 500], [0, 10, 20]); // [1, 2, 2, 2]
85
+ * histogram([-5, 0, 9, 10, 19, 20, 500], [0, 10, 20], { lastClosed: true }); // [1, 2, 3, 1]
53
86
  *
54
87
  * @param values - The sample, in any order; read once.
55
- * @param edges - The bin boundaries: at least one, finite, strictly ascending.
88
+ * @param edges - The bin boundaries: at least one, finite, strictly ascending;
89
+ * a typed array is read as is.
56
90
  * @returns `edges.length + 1` counts.
57
91
  * @throws {RangeError} When `edges` is empty, holds a value that is not finite
58
92
  * or is not strictly ascending.
59
93
  */
60
- export declare function histogram(values: Iterable<number>, edges: readonly number[]): number[];
94
+ export declare function histogram(values: Iterable<number>, edges: ArrayLike<number>, options?: HistogramOptions): number[];
61
95
  //# sourceMappingURL=histogram.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"histogram.d.ts","sourceRoot":"","sources":["../src/histogram.ts"],"names":[],"mappings":"AAUA,iDAAiD;AACjD,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,OAAO,GAAG,mBAAmB,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,IAAI,EAAE,gBAAgB,GACpB,MAAM,CAyDR;AAiBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACxB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EACxB,KAAK,EAAE,SAAS,MAAM,EAAE,GACtB,MAAM,EAAE,CA2BV"}
1
+ {"version":3,"file":"histogram.d.ts","sourceRoot":"","sources":["../src/histogram.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GACzB,MAAM,GACN,mBAAmB,GACnB,OAAO,GACP,SAAS,GACT,OAAO,GACP,MAAM,GACN,MAAM,GACN,OAAO,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EACzB,IAAI,EAAE,gBAAgB,GACpB,MAAM,CAYR;AAED,oCAAoC;AACpC,MAAM,MAAM,gBAAgB,GAAG;IAC9B;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CACxB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EACxB,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,EACxB,OAAO,GAAE,gBAAqB,GAC5B,MAAM,EAAE,CAgCV"}