@zukhruf/statistics 0.8.74 → 0.8.76

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @zukhruf/statistics
2
2
 
3
- The percentile bootstrap, the quantile methods of NumPy, and `numpy.sum`, `numpy.mean` and `numpy.nanmean` in JavaScript, to the last bit. Use it when a TypeScript eval must give the same interval as a Python program, such as the summary of a benchmark or the comparison of two models.
3
+ The percentile bootstrap, the quantile methods of NumPy, and `numpy.sum`, `numpy.mean`, `numpy.nanmean` and `numpy.std` in JavaScript, to the last bit. Use it when a TypeScript eval must give the same interval as a Python program, such as the summary of a benchmark or the comparison of two models.
4
4
 
5
5
  The package is public on npm. Until 2026-11-07 it was private and reached through a workspace path (ADR 0001); it became public with `@zukhruf/evals`, which depends on it (backlog #3888).
6
6
 
@@ -43,6 +43,7 @@ nanmean([1, NaN, 3]); // 2, as numpy.nanmean(a)
43
43
  | `sum` | `numpy.sum` of a 1-D float64 array | The pairwise sum of NumPy: blocks of up to 128 values in 8 accumulators, and two halves for more values. It starts from 0, so values of −0 give 0. No values give 0. |
44
44
  | `mean` | `numpy.mean` of a 1-D float64 array | `sum` divided by the number of values. No values give NaN. |
45
45
  | `nanmean` | `numpy.nanmean` of a 1-D float64 array | Each NaN becomes 0, `sum` adds all the values, and the sum is divided by the number of values that are not NaN. A `mean` of only the values that are not NaN can give other last bits. No values, or only NaN values, give NaN. |
46
+ | `std` | `numpy.std` of a 1-D float64 array, with its `ddof` | The square root of the `sum` of the squared deviations from the `mean`, divided by n − `ddof`. `ddof` is 0 by default (the population standard deviation), and `ddof: 1` gives the sample standard deviation. No values give NaN. A `ddof` of n or more divides by 0: NaN or Infinity, as NumPy gives them. |
46
47
  | `QuantileMethod` | the `method` of `numpy.quantile` | A rule that gives the value at the quantile `q` of sorted values: `of(sorted, q)`. `q` is from 0 to 1. A `q` out of that range, or no values, throws a `RangeError`. |
47
48
  | `Lower` | `method='lower'` | The value at the index `floor((n − 1)q)`. |
48
49
  | `Higher` | `method='higher'` | The value at the index `ceil((n − 1)q)`. |
@@ -63,6 +64,17 @@ These parts stay with each caller, because each caller has its own rule:
63
64
  - an interval with a rule of its own at each end, such as the `lower` method at the low end and the `higher` method at the high end of the Structured Output Benchmark: its caller writes it as a `ConfidenceIntervalMethod`;
64
65
  - a p-value and a verdict, such as "better" when the interval of a difference lies above 0: each caller builds its rule from `isAbove` and `isBelow`.
65
66
 
67
+ ## Give the standard deviation that NumPy gives
68
+
69
+ `std(values)` gives the value of `numpy.std(a)`, to the last bit. It adds the values and the squared deviations in the pairwise order of NumPy, so a large mean with small deviations gives the same bits as NumPy. Give `ddof` as NumPy names it:
70
+
71
+ ```ts
72
+ import { std } from '@zukhruf/statistics';
73
+
74
+ std([1, 2, 3, 4]); // 1.118033988749895, as numpy.std(a)
75
+ std([1, 2, 3, 4], { ddof: 1 }); // 1.2909944487358056, as numpy.std(a, ddof=1)
76
+ ```
77
+
66
78
  ## Errors
67
79
 
68
80
  Each error is a `RangeError`. Its message says which input is out of range.
@@ -77,10 +89,14 @@ Each error is a `RangeError`. Its message says which input is out of range.
77
89
  ## API
78
90
 
79
91
  ```ts
80
- // numpy.sum, numpy.mean and numpy.nanmean of a 1-D float64 array.
92
+ // numpy.sum, numpy.mean, numpy.nanmean and numpy.std of a 1-D float64 array.
81
93
  function sum(values: ArrayLike<number>): number;
82
94
  function mean(values: ArrayLike<number>): number;
83
95
  function nanmean(values: ArrayLike<number>): number;
96
+ function std(
97
+ values: ArrayLike<number>,
98
+ options?: { readonly ddof?: number },
99
+ ): number;
84
100
 
85
101
  // A method of numpy.quantile. A subclass gives only where its rule reads the values.
86
102
  abstract class QuantileMethod {
package/dist/index.d.ts CHANGED
@@ -10,5 +10,6 @@ export { Lower } from './quantile/lower.ts';
10
10
  export { QuantileMethod } from './quantile/quantile-method.ts';
11
11
  export { mean } from './sum/mean.ts';
12
12
  export { nanmean } from './sum/nanmean.ts';
13
+ export { std } from './sum/std.ts';
13
14
  export { sum } from './sum/sum.ts';
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,YAAY,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,YAAY,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -9,5 +9,6 @@ export { Lower } from './quantile/lower.js';
9
9
  export { QuantileMethod } from './quantile/quantile-method.js';
10
10
  export { mean } from './sum/mean.js';
11
11
  export { nanmean } from './sum/nanmean.js';
12
+ export { std } from './sum/std.js';
12
13
  export { sum } from './sum/sum.js';
13
14
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function std(values: ArrayLike<number>, { ddof }?: {
2
+ readonly ddof?: number;
3
+ }): number;
4
+ //# sourceMappingURL=std.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"std.d.ts","sourceRoot":"","sources":["../../src/sum/std.ts"],"names":[],"mappings":"AAQA,wBAAgB,GAAG,CACjB,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EACzB,EAAE,IAAQ,EAAE,GAAE;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAC5C,MAAM,CAOR"}
@@ -0,0 +1,16 @@
1
+ import { mean } from './mean.js';
2
+ import { sum } from './sum.js';
3
+ // numpy.std of a 1-D float64 array (_var of numpy/_core/_methods.py): the
4
+ // mean, the square of each deviation from it, the pairwise sum of the
5
+ // squares divided by max(n - ddof, 0), and the square root. ddof 0 gives the
6
+ // population standard deviation, and ddof 1 the sample one. No values give
7
+ // NaN, and a ddof of n or more gives NaN or Infinity, as NumPy gives them.
8
+ export function std(values, { ddof = 0 } = {}) {
9
+ const average = mean(values);
10
+ const squares = Float64Array.from(values, (value) => {
11
+ const deviation = value - average;
12
+ return deviation * deviation;
13
+ });
14
+ return Math.sqrt(sum(squares) / Math.max(values.length - ddof, 0));
15
+ }
16
+ //# sourceMappingURL=std.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"std.js","sourceRoot":"","sources":["../../src/sum/std.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,0EAA0E;AAC1E,sEAAsE;AACtE,6EAA6E;AAC7E,2EAA2E;AAC3E,2EAA2E;AAC3E,MAAM,UAAU,GAAG,CACjB,MAAyB,EACzB,EAAE,IAAI,GAAG,CAAC,EAAE,GAA+B,EAAE;IAE7C,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7B,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;QAClD,MAAM,SAAS,GAAG,KAAK,GAAG,OAAO,CAAC;QAClC,OAAO,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACrE,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zukhruf/statistics",
3
- "version": "0.8.74",
4
- "description": "The percentile bootstrap, NumPy's quantile methods, and numpy.sum, numpy.mean and numpy.nanmean in JavaScript, to the last bit: resamples with a random generator that the caller gives, the percentile interval of their statistic, and NumPy's pairwise sum.",
3
+ "version": "0.8.76",
4
+ "description": "The percentile bootstrap, NumPy's quantile methods, and the sum, mean, nanmean and std of NumPy in JavaScript, to the last bit: resamples with a random generator that the caller gives, the percentile interval of their statistic, and NumPy's pairwise sum.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",