@iyulab/u-numflow 0.7.0 → 0.9.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.
@@ -1,5 +1,18 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ /**
4
+ * A distribution named by `kind`, with its parameters.
5
+ */
6
+ export type DistributionSpec = { kind: "uniform"; min: number; max: number } | { kind: "triangular"; min: number; mode: number; max: number } | { kind: "pert"; min: number; mode: number; max: number; lambda?: number } | { kind: "normal"; mu: number; sigma: number } | { kind: "lognormal"; mu: number; sigma: number } | { kind: "weibull"; shape: number; scale: number } | { kind: "exponential"; rate: number } | { kind: "gamma"; shape: number; rate: number } | { kind: "beta"; alpha: number; beta: number } | { kind: "chi_squared"; k: number };
7
+
8
+ /**
9
+ * Mean and variance of a distribution.
10
+ */
11
+ export interface MomentsDto {
12
+ mean: number;
13
+ variance: number;
14
+ }
15
+
3
16
  /**
4
17
  * Output of [`estimate_lambda`]: `{ lambda, at_bound }`.
5
18
  */
@@ -19,7 +32,7 @@ export interface LambdaEstimateDto {
19
32
  * data contains a value ≤ 0, a NaN or infinity, or fewer than 2 elements, and
20
33
  * `invalid_transform` when a result is not finite.
21
34
  */
22
- export function box_cox(data: Float64Array, lambda: number): Float64Array;
35
+ export function box_cox(data: number[] | Float64Array, lambda: number): Float64Array;
23
36
 
24
37
  /**
25
38
  * Chi-squared CDF: `P(X ≤ x)` for `X ~ χ²(k)` (`0` for `x ≤ 0`).
@@ -38,6 +51,49 @@ export function chi_squared_cdf(x: number, k: number): number;
38
51
  */
39
52
  export function chi_squared_quantile(p: number, k: number): number;
40
53
 
54
+ /**
55
+ * `P(X ≤ x)` for the distribution `{ kind, ...parameters }`.
56
+ *
57
+ * # Errors
58
+ * As every `distribution` argument: `malformed_input` for a value that is
59
+ * not such an object, `unknown_option` for an unknown `kind` (with
60
+ * `expected`), `value_not_finite` for a NaN or infinite parameter,
61
+ * `parameter_out_of_range` for a parameter that must be `> 0`, and
62
+ * `invalid_option` for parameters out of order (`min < max`,
63
+ * `min ≤ mode ≤ max`). `x` NaN throws `value_not_finite`.
64
+ */
65
+ export function distribution_cdf(distribution: DistributionSpec, x: number): number;
66
+
67
+ /**
68
+ * Mean and variance of `distribution` — also the way to check a
69
+ * specification before using it.
70
+ *
71
+ * # Errors
72
+ * As [`distribution_cdf`] for `distribution`.
73
+ */
74
+ export function distribution_moments(distribution: DistributionSpec): MomentsDto;
75
+
76
+ /**
77
+ * The `x` with `P(X ≤ x) = p`.
78
+ *
79
+ * # Errors
80
+ * As [`distribution_cdf`] for `distribution`; `p` outside `(0, 1)` throws
81
+ * `parameter_out_of_range`.
82
+ */
83
+ export function distribution_quantile(distribution: DistributionSpec, p: number): number;
84
+
85
+ /**
86
+ * `n` random variates, reproducible from `seed`: the same `(distribution, n,
87
+ * seed)` always returns the same values. Uniforms are drawn from the open
88
+ * interval (0, 1), so no variate is infinite.
89
+ *
90
+ * # Errors
91
+ * As [`distribution_cdf`] for `distribution`; `n` not a whole number in
92
+ * `[0, 2³² − 1]` or `seed` not a whole number in `[0, 2⁵³]` throws
93
+ * `parameter_out_of_range`.
94
+ */
95
+ export function distribution_sample(distribution: DistributionSpec, n: number, seed: number): Float64Array;
96
+
41
97
  /**
42
98
  * Estimate the optimal Box-Cox lambda via profile maximum likelihood.
43
99
  *
@@ -51,7 +107,7 @@ export function chi_squared_quantile(p: number, k: number): number;
51
107
  * Throws as [`box_cox`] does for the data, and `invalid_lambda_range` when the
52
108
  * range is not finite with `lambda_min < lambda_max`.
53
109
  */
54
- export function estimate_lambda(data: Float64Array, lambda_min: number, lambda_max: number): LambdaEstimateDto;
110
+ export function estimate_lambda(data: number[] | Float64Array, lambda_min: number, lambda_max: number): LambdaEstimateDto;
55
111
 
56
112
  /**
57
113
  * F CDF: `P(X ≤ x)` for `X ~ F(df1, df2)` (`0` for `x ≤ 0`).
@@ -70,6 +126,53 @@ export function f_distribution_cdf(x: number, df1: number, df2: number): number;
70
126
  */
71
127
  export function f_distribution_quantile(p: number, df1: number, df2: number): number;
72
128
 
129
+ /**
130
+ * Points in `a` but not in `b`, in normal form — e.g. a reporting window
131
+ * minus down-time is up-time.
132
+ *
133
+ * # Errors
134
+ * As [`interval_normalize`], naming `a` or `b`.
135
+ */
136
+ export function interval_difference(a: [number, number][], b: [number, number][]): [number, number][];
137
+
138
+ /**
139
+ * Points in both `a` and `b`, in normal form. Clipping to a window is
140
+ * `interval_intersection(a, [[from, to]])`.
141
+ *
142
+ * # Errors
143
+ * As [`interval_normalize`], naming `a` or `b`.
144
+ */
145
+ export function interval_intersection(a: [number, number][], b: [number, number][]): [number, number][];
146
+
147
+ /**
148
+ * Total length of the union of `intervals`: each point counts once, however
149
+ * many rows cover it.
150
+ *
151
+ * # Errors
152
+ * As [`interval_normalize`].
153
+ */
154
+ export function interval_measure(intervals: [number, number][]): number;
155
+
156
+ /**
157
+ * The union of `intervals` (each `[start, end]`, half-open) in normal form:
158
+ * sorted, disjoint, touching pieces merged, empty ones dropped.
159
+ *
160
+ * # Errors
161
+ * Throws `malformed_input` for a row that is not two numbers (`parameter` is
162
+ * the row's path, e.g. `intervals[2]`), `value_not_finite` for a NaN or
163
+ * ±Infinity bound, and `reversed_interval` (`parameter`, `index`) for a row
164
+ * with start > end — reversed rows are refused, not swapped.
165
+ */
166
+ export function interval_normalize(intervals: [number, number][]): [number, number][];
167
+
168
+ /**
169
+ * Points in `a` or `b`, in normal form.
170
+ *
171
+ * # Errors
172
+ * As [`interval_normalize`], naming `a` or `b`.
173
+ */
174
+ export function interval_union(a: [number, number][], b: [number, number][]): [number, number][];
175
+
73
176
  /**
74
177
  * Standard normal quantile Φ⁻¹(p): the `z` with `P(Z ≤ z) = p`.
75
178
  *
@@ -81,9 +184,11 @@ export function inverse_normal_cdf(p: number): number;
81
184
  /**
82
185
  * Arithmetic mean of `data` using Kahan compensated summation.
83
186
  *
84
- * Returns `NaN` if `data` is empty or contains non-finite values.
187
+ * # Errors
188
+ * Throws `empty_input` when `data` is empty, and as every `data` argument
189
+ * does for an element that is not a finite number.
85
190
  */
86
- export function mean(data: Float64Array): number;
191
+ export function mean(data: number[] | Float64Array): number;
87
192
 
88
193
  /**
89
194
  * Standard normal CDF Φ(x) = P(Z ≤ x) for Z ~ N(0, 1).
@@ -110,15 +215,20 @@ export function normal_sf(x: number): number;
110
215
  * Returns the `n` complex bins interleaved as `[re0, im0, re1, im1, …]`
111
216
  * (length `2n`). Bins `k` and `n − k` are conjugates, so the spectrum of a
112
217
  * real signal is fully described by bins `0..=n/2`.
218
+ *
219
+ * # Errors
220
+ * Throws as every `data` argument does for an element that is not a finite
221
+ * number.
113
222
  */
114
- export function rfft(data: Float64Array): Float64Array;
223
+ export function rfft(data: number[] | Float64Array): Float64Array;
115
224
 
116
225
  /**
117
226
  * Sample standard deviation of `data` (Bessel-corrected, denominator n−1).
118
227
  *
119
- * Returns `NaN` if `data` has fewer than 2 elements or contains non-finite values.
228
+ * # Errors
229
+ * Throws `insufficient_data` below 2 values.
120
230
  */
121
- export function std_dev(data: Float64Array): number;
231
+ export function std_dev(data: number[] | Float64Array): number;
122
232
 
123
233
  /**
124
234
  * Student's t CDF: `P(T ≤ t)` for `T ~ t(df)`. `df` may be fractional.
@@ -141,6 +251,7 @@ export function t_distribution_quantile(p: number, df: number): number;
141
251
  /**
142
252
  * Sample variance of `data` (Bessel-corrected, denominator n−1).
143
253
  *
144
- * Returns `NaN` if `data` has fewer than 2 elements or contains non-finite values.
254
+ * # Errors
255
+ * Throws `insufficient_data` below 2 values.
145
256
  */
146
- export function variance(data: Float64Array): number;
257
+ export function variance(data: number[] | Float64Array): number;
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "iyulab"
6
6
  ],
7
7
  "description": "Foundational mathematical primitives: statistics, probability distributions, random sampling, and collections.",
8
- "version": "0.7.0",
8
+ "version": "0.9.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
package/u_numflow.d.ts CHANGED
@@ -1,5 +1,18 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ /**
4
+ * A distribution named by `kind`, with its parameters.
5
+ */
6
+ export type DistributionSpec = { kind: "uniform"; min: number; max: number } | { kind: "triangular"; min: number; mode: number; max: number } | { kind: "pert"; min: number; mode: number; max: number; lambda?: number } | { kind: "normal"; mu: number; sigma: number } | { kind: "lognormal"; mu: number; sigma: number } | { kind: "weibull"; shape: number; scale: number } | { kind: "exponential"; rate: number } | { kind: "gamma"; shape: number; rate: number } | { kind: "beta"; alpha: number; beta: number } | { kind: "chi_squared"; k: number };
7
+
8
+ /**
9
+ * Mean and variance of a distribution.
10
+ */
11
+ export interface MomentsDto {
12
+ mean: number;
13
+ variance: number;
14
+ }
15
+
3
16
  /**
4
17
  * Output of [`estimate_lambda`]: `{ lambda, at_bound }`.
5
18
  */
@@ -19,7 +32,7 @@ export interface LambdaEstimateDto {
19
32
  * data contains a value ≤ 0, a NaN or infinity, or fewer than 2 elements, and
20
33
  * `invalid_transform` when a result is not finite.
21
34
  */
22
- export function box_cox(data: Float64Array, lambda: number): Float64Array;
35
+ export function box_cox(data: number[] | Float64Array, lambda: number): Float64Array;
23
36
 
24
37
  /**
25
38
  * Chi-squared CDF: `P(X ≤ x)` for `X ~ χ²(k)` (`0` for `x ≤ 0`).
@@ -38,6 +51,49 @@ export function chi_squared_cdf(x: number, k: number): number;
38
51
  */
39
52
  export function chi_squared_quantile(p: number, k: number): number;
40
53
 
54
+ /**
55
+ * `P(X ≤ x)` for the distribution `{ kind, ...parameters }`.
56
+ *
57
+ * # Errors
58
+ * As every `distribution` argument: `malformed_input` for a value that is
59
+ * not such an object, `unknown_option` for an unknown `kind` (with
60
+ * `expected`), `value_not_finite` for a NaN or infinite parameter,
61
+ * `parameter_out_of_range` for a parameter that must be `> 0`, and
62
+ * `invalid_option` for parameters out of order (`min < max`,
63
+ * `min ≤ mode ≤ max`). `x` NaN throws `value_not_finite`.
64
+ */
65
+ export function distribution_cdf(distribution: DistributionSpec, x: number): number;
66
+
67
+ /**
68
+ * Mean and variance of `distribution` — also the way to check a
69
+ * specification before using it.
70
+ *
71
+ * # Errors
72
+ * As [`distribution_cdf`] for `distribution`.
73
+ */
74
+ export function distribution_moments(distribution: DistributionSpec): MomentsDto;
75
+
76
+ /**
77
+ * The `x` with `P(X ≤ x) = p`.
78
+ *
79
+ * # Errors
80
+ * As [`distribution_cdf`] for `distribution`; `p` outside `(0, 1)` throws
81
+ * `parameter_out_of_range`.
82
+ */
83
+ export function distribution_quantile(distribution: DistributionSpec, p: number): number;
84
+
85
+ /**
86
+ * `n` random variates, reproducible from `seed`: the same `(distribution, n,
87
+ * seed)` always returns the same values. Uniforms are drawn from the open
88
+ * interval (0, 1), so no variate is infinite.
89
+ *
90
+ * # Errors
91
+ * As [`distribution_cdf`] for `distribution`; `n` not a whole number in
92
+ * `[0, 2³² − 1]` or `seed` not a whole number in `[0, 2⁵³]` throws
93
+ * `parameter_out_of_range`.
94
+ */
95
+ export function distribution_sample(distribution: DistributionSpec, n: number, seed: number): Float64Array;
96
+
41
97
  /**
42
98
  * Estimate the optimal Box-Cox lambda via profile maximum likelihood.
43
99
  *
@@ -51,7 +107,7 @@ export function chi_squared_quantile(p: number, k: number): number;
51
107
  * Throws as [`box_cox`] does for the data, and `invalid_lambda_range` when the
52
108
  * range is not finite with `lambda_min < lambda_max`.
53
109
  */
54
- export function estimate_lambda(data: Float64Array, lambda_min: number, lambda_max: number): LambdaEstimateDto;
110
+ export function estimate_lambda(data: number[] | Float64Array, lambda_min: number, lambda_max: number): LambdaEstimateDto;
55
111
 
56
112
  /**
57
113
  * F CDF: `P(X ≤ x)` for `X ~ F(df1, df2)` (`0` for `x ≤ 0`).
@@ -70,6 +126,53 @@ export function f_distribution_cdf(x: number, df1: number, df2: number): number;
70
126
  */
71
127
  export function f_distribution_quantile(p: number, df1: number, df2: number): number;
72
128
 
129
+ /**
130
+ * Points in `a` but not in `b`, in normal form — e.g. a reporting window
131
+ * minus down-time is up-time.
132
+ *
133
+ * # Errors
134
+ * As [`interval_normalize`], naming `a` or `b`.
135
+ */
136
+ export function interval_difference(a: [number, number][], b: [number, number][]): [number, number][];
137
+
138
+ /**
139
+ * Points in both `a` and `b`, in normal form. Clipping to a window is
140
+ * `interval_intersection(a, [[from, to]])`.
141
+ *
142
+ * # Errors
143
+ * As [`interval_normalize`], naming `a` or `b`.
144
+ */
145
+ export function interval_intersection(a: [number, number][], b: [number, number][]): [number, number][];
146
+
147
+ /**
148
+ * Total length of the union of `intervals`: each point counts once, however
149
+ * many rows cover it.
150
+ *
151
+ * # Errors
152
+ * As [`interval_normalize`].
153
+ */
154
+ export function interval_measure(intervals: [number, number][]): number;
155
+
156
+ /**
157
+ * The union of `intervals` (each `[start, end]`, half-open) in normal form:
158
+ * sorted, disjoint, touching pieces merged, empty ones dropped.
159
+ *
160
+ * # Errors
161
+ * Throws `malformed_input` for a row that is not two numbers (`parameter` is
162
+ * the row's path, e.g. `intervals[2]`), `value_not_finite` for a NaN or
163
+ * ±Infinity bound, and `reversed_interval` (`parameter`, `index`) for a row
164
+ * with start > end — reversed rows are refused, not swapped.
165
+ */
166
+ export function interval_normalize(intervals: [number, number][]): [number, number][];
167
+
168
+ /**
169
+ * Points in `a` or `b`, in normal form.
170
+ *
171
+ * # Errors
172
+ * As [`interval_normalize`], naming `a` or `b`.
173
+ */
174
+ export function interval_union(a: [number, number][], b: [number, number][]): [number, number][];
175
+
73
176
  /**
74
177
  * Standard normal quantile Φ⁻¹(p): the `z` with `P(Z ≤ z) = p`.
75
178
  *
@@ -81,9 +184,11 @@ export function inverse_normal_cdf(p: number): number;
81
184
  /**
82
185
  * Arithmetic mean of `data` using Kahan compensated summation.
83
186
  *
84
- * Returns `NaN` if `data` is empty or contains non-finite values.
187
+ * # Errors
188
+ * Throws `empty_input` when `data` is empty, and as every `data` argument
189
+ * does for an element that is not a finite number.
85
190
  */
86
- export function mean(data: Float64Array): number;
191
+ export function mean(data: number[] | Float64Array): number;
87
192
 
88
193
  /**
89
194
  * Standard normal CDF Φ(x) = P(Z ≤ x) for Z ~ N(0, 1).
@@ -110,15 +215,20 @@ export function normal_sf(x: number): number;
110
215
  * Returns the `n` complex bins interleaved as `[re0, im0, re1, im1, …]`
111
216
  * (length `2n`). Bins `k` and `n − k` are conjugates, so the spectrum of a
112
217
  * real signal is fully described by bins `0..=n/2`.
218
+ *
219
+ * # Errors
220
+ * Throws as every `data` argument does for an element that is not a finite
221
+ * number.
113
222
  */
114
- export function rfft(data: Float64Array): Float64Array;
223
+ export function rfft(data: number[] | Float64Array): Float64Array;
115
224
 
116
225
  /**
117
226
  * Sample standard deviation of `data` (Bessel-corrected, denominator n−1).
118
227
  *
119
- * Returns `NaN` if `data` has fewer than 2 elements or contains non-finite values.
228
+ * # Errors
229
+ * Throws `insufficient_data` below 2 values.
120
230
  */
121
- export function std_dev(data: Float64Array): number;
231
+ export function std_dev(data: number[] | Float64Array): number;
122
232
 
123
233
  /**
124
234
  * Student's t CDF: `P(T ≤ t)` for `T ~ t(df)`. `df` may be fractional.
@@ -141,6 +251,7 @@ export function t_distribution_quantile(p: number, df: number): number;
141
251
  /**
142
252
  * Sample variance of `data` (Bessel-corrected, denominator n−1).
143
253
  *
144
- * Returns `NaN` if `data` has fewer than 2 elements or contains non-finite values.
254
+ * # Errors
255
+ * Throws `insufficient_data` below 2 values.
145
256
  */
146
- export function variance(data: Float64Array): number;
257
+ export function variance(data: number[] | Float64Array): number;
package/u_numflow.js CHANGED
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./u_numflow_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
  wasm.__wbindgen_start();
7
7
  export {
8
- box_cox, chi_squared_cdf, chi_squared_quantile, estimate_lambda, f_distribution_cdf, f_distribution_quantile, inverse_normal_cdf, mean, normal_cdf, normal_sf, rfft, std_dev, t_distribution_cdf, t_distribution_quantile, variance
8
+ box_cox, chi_squared_cdf, chi_squared_quantile, distribution_cdf, distribution_moments, distribution_quantile, distribution_sample, estimate_lambda, f_distribution_cdf, f_distribution_quantile, interval_difference, interval_intersection, interval_measure, interval_normalize, interval_union, inverse_normal_cdf, mean, normal_cdf, normal_sf, rfft, std_dev, t_distribution_cdf, t_distribution_quantile, variance
9
9
  } from "./u_numflow_bg.js";