@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,106 @@
1
+ import { describeValue } from "@ac-kit/core";
2
+ import { crpsCensoredLogisticKernel_, crpsCensoredShiftedGammaKernel_, crpsNormalKernel_, crpsTruncatedNormalKernel_, } from "./_score-kernels.js";
3
+ const SCRATCH_ = new Float64Array(4);
4
+ function assertScale_(routine, name, value) {
5
+ if (!(value > 0 && value < Number.POSITIVE_INFINITY)) {
6
+ throw new RangeError(`${routine}: ${name} must be positive and finite, got ${describeValue(value)}`);
7
+ }
8
+ }
9
+ function assertFinite_(routine, name, value) {
10
+ if (!Number.isFinite(value)) {
11
+ throw new RangeError(`${routine}: ${name} must be finite, got ${describeValue(value)}`);
12
+ }
13
+ }
14
+ /**
15
+ * The continuous ranked probability score `∫ (F(x) − 𝟙{x ≥ y})² dx` of the
16
+ * normal forecast `N(mean, standardDeviation²)` at the observation, in closed
17
+ * form (Gneiting et al. 2005): `σ·[z(2Φ(z) − 1) + 2φ(z) − 1/√π]`, `z = (y −
18
+ * μ)/σ`. Lower is better; in the units of the observation. Agrees with
19
+ * properscoring's `crps_gaussian`.
20
+ *
21
+ * @param observation The outcome; `NaN` gives `NaN`.
22
+ * @param mean Forecast mean, finite.
23
+ * @param standardDeviation Forecast spread, positive and finite.
24
+ * @returns The score, non-negative.
25
+ * @throws {RangeError} When a parameter is out of its range.
26
+ */
27
+ export function crpsNormal(observation, mean, standardDeviation) {
28
+ assertFinite_("crpsNormal", "mean", mean);
29
+ assertScale_("crpsNormal", "standardDeviation", standardDeviation);
30
+ crpsNormalKernel_(SCRATCH_, observation, mean, standardDeviation);
31
+ return SCRATCH_[0];
32
+ }
33
+ /**
34
+ * The CRPS of the normal of `mean` and `standardDeviation` truncated below at
35
+ * `lower` (Thorarinsdottir and Gneiting 2010's wind-speed law; see
36
+ * {@link truncatedNormalDistribution}), in closed form. Computed from Mills'
37
+ * ratios when the bound lies above the mean, so a bound hundreds of standard
38
+ * deviations out still scores; the score's relative error grows there as
39
+ * `(ε·a²)`, `a` the bound in standard deviations, from the cancellation of
40
+ * terms of size `a` into a score of size `1/a`. An observation below the bound
41
+ * scores as the bound plus its distance to it.
42
+ *
43
+ * @param observation The outcome; `NaN` gives `NaN`.
44
+ * @param mean Location of the parent normal, finite.
45
+ * @param standardDeviation Scale of the parent normal, positive and finite.
46
+ * @param lower The truncation point, finite; `0` by default.
47
+ * @returns The score, non-negative.
48
+ * @throws {RangeError} When a parameter is out of its range.
49
+ */
50
+ export function crpsTruncatedNormal(observation, mean, standardDeviation, lower = 0) {
51
+ assertFinite_("crpsTruncatedNormal", "mean", mean);
52
+ assertScale_("crpsTruncatedNormal", "standardDeviation", standardDeviation);
53
+ assertFinite_("crpsTruncatedNormal", "lower", lower);
54
+ crpsTruncatedNormalKernel_(SCRATCH_, observation, mean, standardDeviation, lower);
55
+ return SCRATCH_[0];
56
+ }
57
+ /**
58
+ * The CRPS of the logistic of `location` and `scale` censored below at `lower`
59
+ * (see {@link censoredLogisticDistribution}), in closed form: `s·[z − 2 ln Λ(z)
60
+ * − 1] − s·[ln(1 + eᵃ) − Λ(a)]` for `y ≥ lower`, `z` and `a` the standardised
61
+ * observation and bound, `Λ` the logistic function. An observation below the
62
+ * bound scores as the bound plus its distance to it.
63
+ *
64
+ * @param observation The outcome; `NaN` gives `NaN`.
65
+ * @param location Location of the parent logistic, finite.
66
+ * @param scale Scale of the parent logistic, positive and finite.
67
+ * @param lower The censoring point, finite; `0` by default.
68
+ * @returns The score, non-negative.
69
+ * @throws {RangeError} When a parameter is out of its range.
70
+ */
71
+ export function crpsCensoredLogistic(observation, location, scale, lower = 0) {
72
+ assertFinite_("crpsCensoredLogistic", "location", location);
73
+ assertScale_("crpsCensoredLogistic", "scale", scale);
74
+ assertFinite_("crpsCensoredLogistic", "lower", lower);
75
+ crpsCensoredLogisticKernel_(SCRATCH_, observation, location, scale, lower);
76
+ return SCRATCH_[0];
77
+ }
78
+ /**
79
+ * The CRPS of the censored shifted gamma `lower + max(0, X − shift)`, `X` a
80
+ * gamma of `shape` and `scale` (Scheuerer and Hamill 2015; see
81
+ * {@link censoredShiftedGammaDistribution}), in their closed form through the
82
+ * regularised incomplete gamma. An observation below the bound scores as the
83
+ * bound plus its distance to it.
84
+ *
85
+ * @param observation The outcome; `NaN` gives `NaN`.
86
+ * @param shape The gamma shape, positive and finite.
87
+ * @param scale The gamma scale, positive and finite.
88
+ * @param shift The shift, finite and non-negative.
89
+ * @param lower The censoring point, finite; `0` by default.
90
+ * @returns The score, non-negative.
91
+ * @throws {RangeError} When a parameter is out of its range.
92
+ */
93
+ export function crpsCensoredShiftedGamma(observation, shape, scale, shift, lower = 0) {
94
+ assertScale_("crpsCensoredShiftedGamma", "shape", shape);
95
+ assertScale_("crpsCensoredShiftedGamma", "scale", scale);
96
+ if (!(shift >= 0 && shift < Number.POSITIVE_INFINITY)) {
97
+ throw new RangeError(`crpsCensoredShiftedGamma: shift must be finite and non-negative, got ${describeValue(shift)}`);
98
+ }
99
+ assertFinite_("crpsCensoredShiftedGamma", "lower", lower);
100
+ if (observation !== observation) {
101
+ return observation;
102
+ }
103
+ crpsCensoredShiftedGammaKernel_(SCRATCH_, observation, shape, scale, shift, lower, false);
104
+ return SCRATCH_[0];
105
+ }
106
+ //# sourceMappingURL=crps-closed-form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crps-closed-form.js","sourceRoot":"","sources":["../../src/forecast/crps-closed-form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EACN,2BAA2B,EAC3B,+BAA+B,EAC/B,iBAAiB,EACjB,0BAA0B,GAC1B,MAAM,qBAA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EACX,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,CACL,CAAC;IAEF,OAAO,QAAQ,CAAC,CAAC,CAAE,CAAC;AACrB,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The estimator of {@link crpsEnsemble} (Zamo and Naveau 2018):
3
+ *
4
+ * - `"nrg"`: the CRPS of the ensemble's own empirical distribution, `E|X − y| −
5
+ * ½E|X − X′|` over the members (Gneiting and Raftery 2007's energy form;
6
+ * properscoring's `crps_ensemble`). Biased: it favours small ensembles that
7
+ * are underdispersed.
8
+ * - `"fair"`: the same with the spread term over distinct pairs only, `… − ½·m/(m
9
+ * − 1)·…` (Ferro 2014): unbiased for the CRPS of the distribution the members
10
+ * are drawn from, so ensembles of different sizes compare fairly.
11
+ * - `"pwm"`: through the probability weighted moments, `E|X − y| + β₀ − 2β₁`: the
12
+ * same value as `"fair"`, by another sum.
13
+ */
14
+ export type CrpsEnsembleEstimator = "nrg" | "fair" | "pwm";
15
+ /** Options of {@link crpsEnsemble}. */
16
+ export type CrpsEnsembleOptions = {
17
+ /** The estimator; `"nrg"` by default. */
18
+ readonly estimator?: CrpsEnsembleEstimator;
19
+ /**
20
+ * One finite non-negative weight per member, not all zero (normalised
21
+ * internally): a weighted ensemble, or members of unequal probability. With
22
+ * `"fair"` and `"pwm"`, the spread is averaged over distinct pairs with
23
+ * weight `wᵢwⱼ`, so it stays unbiased. `null` or absent: equal weights.
24
+ */
25
+ readonly weights?: ArrayLike<number> | null;
26
+ /**
27
+ * Whether `members` is already in ascending order (`NaN` members may sit
28
+ * anywhere), which skips the sort. Unchecked; `false` by default.
29
+ */
30
+ readonly sorted?: boolean;
31
+ };
32
+ /**
33
+ * The continuous ranked probability score of an ensemble forecast at an
34
+ * observation, `∫ (F(x) − 𝟙{x ≥ y})² dx` for the members' distribution: the
35
+ * ensemble's mean absolute error minus half its mean spread, in the units of
36
+ * the observation. Lower is better; a single member scores its absolute error
37
+ * under `"nrg"`.
38
+ *
39
+ * Members that are `NaN` are missing and ignored (with their weights). Sums run
40
+ * over the members centred on their median, so a large common offset costs no
41
+ * digits. O(m log m) time (O(m) when `sorted`); the member order lives in a
42
+ * module scratch grown to the largest ensemble seen, so scoring a season of
43
+ * cases allocates no buffer per call.
44
+ *
45
+ * @param members The ensemble members; not modified.
46
+ * @param observation The outcome; `NaN` gives `NaN`.
47
+ * @param options Estimator, weights, sorted flag.
48
+ * @returns The score; `NaN` without members, or with one for `"fair"` and
49
+ * `"pwm"`, which need a pair.
50
+ * @throws {RangeError} When the weights are invalid or `estimator` is unknown.
51
+ */
52
+ export declare function crpsEnsemble(members: ArrayLike<number>, observation: number, options?: CrpsEnsembleOptions): number;
53
+ //# sourceMappingURL=crps-ensemble.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crps-ensemble.d.ts","sourceRoot":"","sources":["../../src/forecast/crps-ensemble.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,qBAAqB,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;AAE3D,uCAAuC;AACvC,MAAM,MAAM,mBAAmB,GAAG;IACjC,yCAAyC;IACzC,QAAQ,CAAC,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAE3C;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAE5C;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAuBF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAC3B,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,EAC1B,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,MAAM,CAwGR"}
@@ -0,0 +1,121 @@
1
+ import { sortRange } from "@ac-kit/algo";
2
+ import { describeValue } from "@ac-kit/core";
3
+ import { assertSameLength_ } from "./_forecast-checks.js";
4
+ /** Member positions, grown on demand and reused by every call. */
5
+ let order_ = new Uint32Array(64);
6
+ const EMPTY_ = [];
7
+ /** The members being sorted, read by a comparator that allocates no closure. */
8
+ let sortedMembers_ = EMPTY_;
9
+ function compareMembers_(left, right) {
10
+ const a = sortedMembers_[left];
11
+ const b = sortedMembers_[right];
12
+ return a < b ? -1 : a > b ? 1 : 0;
13
+ }
14
+ function orderScratch_(count) {
15
+ if (order_.length < count) {
16
+ order_ = new Uint32Array(Math.max(count, 2 * order_.length));
17
+ }
18
+ return order_;
19
+ }
20
+ /**
21
+ * The continuous ranked probability score of an ensemble forecast at an
22
+ * observation, `∫ (F(x) − 𝟙{x ≥ y})² dx` for the members' distribution: the
23
+ * ensemble's mean absolute error minus half its mean spread, in the units of
24
+ * the observation. Lower is better; a single member scores its absolute error
25
+ * under `"nrg"`.
26
+ *
27
+ * Members that are `NaN` are missing and ignored (with their weights). Sums run
28
+ * over the members centred on their median, so a large common offset costs no
29
+ * digits. O(m log m) time (O(m) when `sorted`); the member order lives in a
30
+ * module scratch grown to the largest ensemble seen, so scoring a season of
31
+ * cases allocates no buffer per call.
32
+ *
33
+ * @param members The ensemble members; not modified.
34
+ * @param observation The outcome; `NaN` gives `NaN`.
35
+ * @param options Estimator, weights, sorted flag.
36
+ * @returns The score; `NaN` without members, or with one for `"fair"` and
37
+ * `"pwm"`, which need a pair.
38
+ * @throws {RangeError} When the weights are invalid or `estimator` is unknown.
39
+ */
40
+ export function crpsEnsemble(members, observation, options) {
41
+ const estimator = options?.estimator ?? "nrg";
42
+ if (estimator !== "nrg" && estimator !== "fair" && estimator !== "pwm") {
43
+ throw new RangeError(`crpsEnsemble: estimator must be "nrg", "fair" or "pwm", got ${describeValue(estimator)}`);
44
+ }
45
+ const weights = options?.weights ?? null;
46
+ const count = members.length;
47
+ if (weights !== null) {
48
+ assertSameLength_("crpsEnsemble", "weights", weights.length, "members", count);
49
+ for (let index = 0; index < count; index++) {
50
+ const weight = weights[index];
51
+ if (!(weight >= 0 && weight < Number.POSITIVE_INFINITY)) {
52
+ throw new RangeError(`crpsEnsemble: weights must be finite and non-negative, got ${describeValue(weight)} at ${index}`);
53
+ }
54
+ }
55
+ }
56
+ if (observation !== observation) {
57
+ return observation;
58
+ }
59
+ // Sort member positions, missing members dropped.
60
+ const order = orderScratch_(count);
61
+ let size = 0;
62
+ for (let index = 0; index < count; index++) {
63
+ if (members[index] === members[index]) {
64
+ order[size++] = index;
65
+ }
66
+ }
67
+ if (options?.sorted !== true) {
68
+ sortedMembers_ = members;
69
+ sortRange(order, compareMembers_, 0, size);
70
+ sortedMembers_ = EMPTY_;
71
+ }
72
+ let total = 0;
73
+ for (let position = 0; position < size; position++) {
74
+ total += weights === null ? 1 : weights[order[position]];
75
+ }
76
+ if (size === 0 || !(total > 0)) {
77
+ if (weights !== null && size > 0) {
78
+ throw new RangeError("crpsEnsemble: weights must not all be zero");
79
+ }
80
+ return Number.NaN;
81
+ }
82
+ const centre = members[order[size >>> 1]];
83
+ let absolute = 0;
84
+ let spread = 0;
85
+ let squares = 0;
86
+ let below = 0;
87
+ // spread = ½ Σᵢ Σⱼ wᵢwⱼ|xᵢ − xⱼ| = Σᵢ wᵢ xᵢ (2Cᵢ₋₁ + wᵢ − 1), weights normalised.
88
+ for (let position = 0; position < size; position++) {
89
+ const index = order[position];
90
+ const weight = (weights === null ? 1 : weights[index]) / total;
91
+ const value = members[index] - centre;
92
+ absolute += weight * Math.abs(members[index] - observation);
93
+ spread += weight * value * (2 * below + weight - 1);
94
+ squares += weight * weight;
95
+ below += weight;
96
+ }
97
+ if (estimator === "nrg") {
98
+ return absolute - spread;
99
+ }
100
+ const pairs = 1 - squares;
101
+ if (!(pairs > 0)) {
102
+ return Number.NaN;
103
+ }
104
+ if (estimator === "fair") {
105
+ return absolute - spread / pairs;
106
+ }
107
+ // β₀ and β₁ over distinct pairs: β₀ − 2β₁ = −spread / pairs.
108
+ let first = 0;
109
+ let second = 0;
110
+ below = 0;
111
+ for (let position = 0; position < size; position++) {
112
+ const index = order[position];
113
+ const weight = (weights === null ? 1 : weights[index]) / total;
114
+ const value = members[index] - centre;
115
+ first += weight * (1 - weight) * value;
116
+ second += weight * below * value;
117
+ below += weight;
118
+ }
119
+ return absolute + (first - 2 * second) / pairs;
120
+ }
121
+ //# sourceMappingURL=crps-ensemble.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crps-ensemble.js","sourceRoot":"","sources":["../../src/forecast/crps-ensemble.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAyB,aAAa,EAAE,MAAM,cAAc,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAqC1D,kEAAkE;AAClE,IAAI,MAAM,GAAG,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;AACjC,MAAM,MAAM,GAAsB,EAAE,CAAC;AACrC,gFAAgF;AAChF,IAAI,cAAc,GAAsB,MAAM,CAAC;AAE/C,SAAS,eAAe,CAAC,IAAY,EAAE,KAAa;IACnD,MAAM,CAAC,GAAG,cAAc,CAAC,IAAI,CAAE,CAAC;IAChC,MAAM,CAAC,GAAG,cAAc,CAAC,KAAK,CAAE,CAAC;IAEjC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,aAAa,CAAC,KAAa;IACnC,IAAI,MAAM,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;QAC3B,MAAM,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;;;GA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K,CAAE,CAAC,GAAG,KAAK,CAAC;QAChE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAE,GAAG,MAAM,CAAC;QAEvC,KAAK,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,KAAK,CAAC;QACvC,MAAM,IAAI,MAAM,GAAG,KAAK,GAAG,KAAK,CAAC;QACjC,KAAK,IAAI,MAAM,CAAC;IACjB,CAAC;IAED,OAAO,QAAQ,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,KAAK,CAAC;AAChD,CAAC"}
@@ -0,0 +1,158 @@
1
+ import { type BfgsStatus } from "@ac-kit/math-analysis";
2
+ import { type Matrix } from "@ac-kit/math-linear";
3
+ import type { Distribution } from "../distribution.js";
4
+ /**
5
+ * The predictive law of an EMOS model:
6
+ *
7
+ * - `"normal"`: `N(μ, σ²)` — temperature, pressure (Gneiting et al. 2005);
8
+ * - `"truncated-normal"`: the normal truncated below the bound — wind speed
9
+ * (Thorarinsdottir and Gneiting 2010; Scheuerer and Möller 2015);
10
+ * - `"censored-logistic"`: the logistic of location `μ` and scale `σ` censored
11
+ * below the bound, with a point mass there — precipitation (Messner et al.
12
+ * 2014);
13
+ * - `"censored-shifted-gamma"`: a gamma of mean `μ` and standard deviation `σ`
14
+ * shifted left by a fitted `δ > 0` and censored at the bound — precipitation
15
+ * (Scheuerer and Hamill 2015). `μ = softplus(Xβ)` keeps the mean positive.
16
+ */
17
+ export type EmosFamily = "normal" | "truncated-normal" | "censored-logistic" | "censored-shifted-gamma";
18
+ /**
19
+ * What the fit minimises, averaged over the cases: the closed-form CRPS
20
+ * (Gneiting et al. 2005's minimum-CRPS estimation, robust to outliers, the EMOS
21
+ * default) or the log score (maximum likelihood, sharper when the family is
22
+ * right).
23
+ */
24
+ export type EmosCriterion = "crps" | "log-score";
25
+ /**
26
+ * How the scale predictors `z` set the scale:
27
+ *
28
+ * - `"variance"`: `σ² = γ₀² + Σⱼ γⱼ² zⱼ` (Gneiting et al. 2005's `c + d·S²`, the
29
+ * squares keeping each term non-negative), so `z` must be non-negative — the
30
+ * ensemble variance, say;
31
+ * - `"log"`: `ln σ = γ₀ + Σⱼ γⱼ zⱼ` (crch's default), `z` any real — the log of
32
+ * the ensemble spread, say.
33
+ */
34
+ export type EmosScaleLink = "variance" | "log";
35
+ /**
36
+ * The predictors of an EMOS model, one case per row (the same in both): the
37
+ * location predictors `x` (the ensemble mean, or each member or model) and the
38
+ * scale predictors `z` (the ensemble variance or spread). An intercept is added
39
+ * to each; a matrix of zero columns gives an intercept-only part.
40
+ */
41
+ export type EmosPredictors = {
42
+ readonly location: Matrix;
43
+ readonly scale: Matrix;
44
+ };
45
+ /** Options of {@link emosFit}. */
46
+ export type EmosFitOptions = {
47
+ /** The predictive law; `"normal"` by default. */
48
+ readonly family?: EmosFamily;
49
+ /** The criterion minimised; `"crps"` by default. */
50
+ readonly criterion?: EmosCriterion;
51
+ /** The scale link; `"variance"` by default. */
52
+ readonly scaleLink?: EmosScaleLink;
53
+ /**
54
+ * The truncation or censoring point of the bounded families, finite; `0` by
55
+ * default (ignored by `"normal"`).
56
+ */
57
+ readonly bound?: number;
58
+ /** One finite non-negative weight per case, not all zero; `null`: equal. */
59
+ readonly weights?: ArrayLike<number> | null;
60
+ /**
61
+ * The shift `δ` of `"censored-shifted-gamma"`, finite and non-negative, held
62
+ * fixed instead of fitted; `null` (the default) fits it. Ignored by the other
63
+ * families.
64
+ */
65
+ readonly shift?: number | null;
66
+ /**
67
+ * A previous model to start from — yesterday's fit when refitting on a
68
+ * sliding training window, which then takes a few steps; of the same family,
69
+ * link and numbers of predictors. `null` (the default) starts from least
70
+ * squares.
71
+ */
72
+ readonly start?: EmosModel | null;
73
+ /**
74
+ * Converged once every partial of the mean score is at most this; finite and
75
+ * non-negative, `1e-8` by default.
76
+ */
77
+ readonly tolerance?: number;
78
+ /** BFGS steps at most, a positive integer; `1000` by default. */
79
+ readonly maxIterations?: number;
80
+ /** Checked before every evaluation; aborting throws its reason. */
81
+ readonly signal?: AbortSignal | null;
82
+ };
83
+ /** A fitted EMOS model, for {@link emosPredict}. */
84
+ export type EmosModel = {
85
+ readonly family: EmosFamily;
86
+ readonly criterion: EmosCriterion;
87
+ readonly scaleLink: EmosScaleLink;
88
+ readonly bound: number;
89
+ /** `[β₀, β₁, …]`: the intercept, then one per location predictor. */
90
+ readonly locationCoefficients: Float64Array;
91
+ /** `[γ₀, γ₁, …]`: the intercept, then one per scale predictor. */
92
+ readonly scaleCoefficients: Float64Array;
93
+ /**
94
+ * The shift `δ` of `"censored-shifted-gamma"` (fitted, or the one given); `0`
95
+ * otherwise.
96
+ */
97
+ readonly shift: number;
98
+ /** The weighted mean score at the estimate (CRPS in data units, or nats). */
99
+ readonly score: number;
100
+ /** Why BFGS stopped. */
101
+ readonly status: BfgsStatus;
102
+ /** Whether it stopped on a convergence test. */
103
+ readonly converged: boolean;
104
+ /** BFGS steps taken. */
105
+ readonly iterations: number;
106
+ };
107
+ /**
108
+ * Fits an ensemble model output statistics (EMOS, non-homogeneous regression)
109
+ * model: a predictive law whose location is linear in the location predictors
110
+ * and whose scale is linked to the scale predictors, fitted to past forecasts
111
+ * and observations by minimising the mean CRPS or log score (Gneiting, Raftery,
112
+ * Westveld and Goldman 2005).
113
+ *
114
+ * The minimiser is BFGS (`@ac-kit/math-analysis`) on analytic gradients: each
115
+ * family's closed-form score is differentiated in its location and scale (and
116
+ * the shifted gamma's shift, through the shape derivative of the incomplete
117
+ * gamma), then chained through the links. Every parameter is unconstrained —
118
+ * the scale through its link, the shift as `δ = eᵗ` — so the scale stays
119
+ * positive everywhere the search goes. The start is the (weighted)
120
+ * least-squares fit of the observations on the location predictors, with the
121
+ * residual spread as the scale.
122
+ *
123
+ * Cases whose observation is `NaN` are skipped. Observations below the bound
124
+ * score as censored at it for the censored families, by the CRPS's distance to
125
+ * the bound for the truncated normal, and are rejected under its log score
126
+ * (impossible there).
127
+ *
128
+ * O(iterations · n · (p + q)) time plus the incomplete gamma functions for the
129
+ * shifted gamma; O((p + q)²) memory beyond the inputs.
130
+ *
131
+ * @param predictors The location and scale predictors, one case per row.
132
+ * @param observations One observation per case.
133
+ * @param options Family, criterion, link, bound, weights, stopping rules.
134
+ * @returns The model; check `converged`.
135
+ * @throws {RangeError} When the shapes differ, a predictor is not finite (or
136
+ * negative under the `"variance"` link), there are fewer usable cases than
137
+ * parameters, an option is out of its range (`start` of another shape), or a
138
+ * truncated-normal observation lies below the bound under the log score.
139
+ * @throws The signal's reason once aborted.
140
+ */
141
+ export declare function emosFit(predictors: EmosPredictors, observations: ArrayLike<number>, options?: EmosFitOptions): EmosModel;
142
+ /**
143
+ * The predictive distribution of a fitted EMOS model for one new case: the
144
+ * family's law at `μ` and `σ` from the predictors (see {@link EmosFamily}). The
145
+ * censored laws give their point mass as `density` at the bound, so `logScore`
146
+ * scores them as the fit did.
147
+ *
148
+ * @param model A model from {@link emosFit}.
149
+ * @param location The case's location predictors, one per column of the fitted
150
+ * `predictors.location`.
151
+ * @param scale Its scale predictors, one per column of `predictors.scale`.
152
+ * @returns The predictive distribution.
153
+ * @throws {RangeError} When a length is wrong, a predictor is not finite (or
154
+ * negative under the `"variance"` link), or the parameters it gives are out
155
+ * of the family's range.
156
+ */
157
+ export declare function emosPredict(model: EmosModel, location: ArrayLike<number>, scale: ArrayLike<number>): Distribution;
158
+ //# sourceMappingURL=emos.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emos.d.ts","sourceRoot":"","sources":["../../src/forecast/emos.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EACN,KAAK,MAAM,EAGX,MAAM,qBAAqB,CAAC;AAK7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAevD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,UAAU,GACnB,QAAQ,GACR,kBAAkB,GAClB,mBAAmB,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