@iyulab/u-numflow 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/node/u_numflow.cjs +126 -6
- package/node/u_numflow.d.cts +28 -4
- package/node/u_numflow_bg.wasm +0 -0
- package/package.json +2 -2
- package/u_numflow.d.ts +28 -4
- package/u_numflow.js +1 -1
- package/u_numflow_bg.js +124 -6
- package/u_numflow_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -17,8 +17,9 @@ u-numflow provides foundational mathematical, statistical, and probabilistic bui
|
|
|
17
17
|
|--------|-------------|
|
|
18
18
|
| `stats` | Descriptive statistics (mean, variance, skewness, kurtosis) with Welford's online algorithm and Neumaier summation |
|
|
19
19
|
| `distributions` | Probability distributions: Uniform, Triangular, PERT, Normal, LogNormal |
|
|
20
|
-
| `special` | Special functions: normal
|
|
20
|
+
| `special` | Special functions: normal CDF and tail-precise survival function (and their inverses), t/F/chi² CDF, regularized incomplete beta/gamma, erf |
|
|
21
21
|
| `transforms` | Data transformations: Box-Cox (λ via MLE golden-section search), inverse Box-Cox |
|
|
22
|
+
| `fourier` | Discrete Fourier transform of any length (radix-2 for powers of two, Bluestein otherwise): `fft`, `ifft`, `rfft`, `Complex` |
|
|
22
23
|
| `matrix` | Dense matrix operations: determinant, inverse, Cholesky decomposition, Jacobi eigenvalue decomposition |
|
|
23
24
|
| `random` | Seeded RNG, Fisher-Yates shuffle, weighted sampling, random subset selection |
|
|
24
25
|
| `collections` | Specialized data structures: Union-Find with path compression and union-by-rank |
|
|
@@ -62,6 +63,12 @@ use u_numflow::transforms::{estimate_lambda, box_cox};
|
|
|
62
63
|
let data = [1.0, 2.0, 4.0, 8.0, 16.0];
|
|
63
64
|
let lambda = estimate_lambda(&data, -2.0, 2.0).unwrap(); // MLE via golden-section
|
|
64
65
|
let transformed = box_cox(&data, lambda).unwrap();
|
|
66
|
+
|
|
67
|
+
// Discrete Fourier transform of any length
|
|
68
|
+
use u_numflow::fourier::rfft;
|
|
69
|
+
let signal: Vec<f64> = (0..30).map(|j| (2.0 * std::f64::consts::PI * 3.0 * j as f64 / 30.0).sin()).collect();
|
|
70
|
+
let spectrum = rfft(&signal); // 30 complex bins; bin 3 carries the energy
|
|
71
|
+
assert!(spectrum[3].norm() > 14.0);
|
|
65
72
|
```
|
|
66
73
|
|
|
67
74
|
## Build & Test
|
|
@@ -93,6 +100,10 @@ The package resolves per environment via a conditional `exports` map:
|
|
|
93
100
|
| Bundlers (webpack, Vite, …) | ESM + WebAssembly ESM-integration (`default` condition) |
|
|
94
101
|
| Node.js — `require()`, ESM `import`, CJS TS runners (`tsx`, `ts-node`) | CJS glue loading the wasm from the filesystem (`node` condition) — no loader hooks or flags |
|
|
95
102
|
|
|
103
|
+
Exported functions: `mean`, `std_dev`, `variance`, `normal_cdf`, `normal_sf` (upper tail `P(Z > x)`, computed directly so tail probabilities keep ~15 significant digits), `box_cox`, `estimate_lambda` (returns `{ lambda, at_bound }` — `at_bound` is `true` when the likelihood was still rising at an end of the search range, so `lambda` is that limit), and
|
|
104
|
+
`rfft(data) -> Float64Array` — the DFT of a real sequence of any length, interleaved as
|
|
105
|
+
`[re0, im0, re1, im1, …]` (bins `k` and `n − k` are conjugates, so `0..=n/2` describes the spectrum).
|
|
106
|
+
|
|
96
107
|
## Related
|
|
97
108
|
|
|
98
109
|
- [u-metaheur](https://github.com/iyulab/u-metaheur) — Metaheuristic optimization (GA, SA, ALNS, CP)
|
package/node/u_numflow.cjs
CHANGED
|
@@ -28,15 +28,20 @@ exports.box_cox = box_cox;
|
|
|
28
28
|
/**
|
|
29
29
|
* Estimate the optimal Box-Cox lambda via profile maximum likelihood.
|
|
30
30
|
*
|
|
31
|
-
* Searches in the range `[lambda_min, lambda_max]` using golden-section search
|
|
31
|
+
* Searches in the range `[lambda_min, lambda_max]` using golden-section search
|
|
32
|
+
* and returns `{ lambda: number, at_bound: boolean }`. `at_bound` is `true`
|
|
33
|
+
* when the maximum lies on an end of the range — the likelihood was still
|
|
34
|
+
* rising there, so `lambda` is that range limit (reported exactly), not an
|
|
35
|
+
* interior estimate; widen the range to find the unconstrained optimum.
|
|
32
36
|
*
|
|
33
37
|
* # Errors
|
|
34
38
|
* Returns a `JsValue` error string if data contains non-positive values,
|
|
35
|
-
* has fewer than 2 elements, or
|
|
39
|
+
* has fewer than 2 elements, or the range is not finite with
|
|
40
|
+
* `lambda_min < lambda_max`.
|
|
36
41
|
* @param {Float64Array} data
|
|
37
42
|
* @param {number} lambda_min
|
|
38
43
|
* @param {number} lambda_max
|
|
39
|
-
* @returns {
|
|
44
|
+
* @returns {any}
|
|
40
45
|
*/
|
|
41
46
|
function estimate_lambda(data, lambda_min, lambda_max) {
|
|
42
47
|
const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
|
|
@@ -45,7 +50,7 @@ function estimate_lambda(data, lambda_min, lambda_max) {
|
|
|
45
50
|
if (ret[2]) {
|
|
46
51
|
throw takeFromExternrefTable0(ret[1]);
|
|
47
52
|
}
|
|
48
|
-
return ret[0];
|
|
53
|
+
return takeFromExternrefTable0(ret[0]);
|
|
49
54
|
}
|
|
50
55
|
exports.estimate_lambda = estimate_lambda;
|
|
51
56
|
|
|
@@ -69,7 +74,8 @@ exports.mean = mean;
|
|
|
69
74
|
*
|
|
70
75
|
* To evaluate a general normal N(μ, σ), pass `(x - μ) / σ`.
|
|
71
76
|
*
|
|
72
|
-
*
|
|
77
|
+
* Computed as `erfc(−x/√2)/2` with a direct `erfc`, so the lower tail keeps
|
|
78
|
+
* relative precision. For the upper tail use [`normal_sf`].
|
|
73
79
|
* @param {number} x
|
|
74
80
|
* @returns {number}
|
|
75
81
|
*/
|
|
@@ -79,6 +85,40 @@ function normal_cdf(x) {
|
|
|
79
85
|
}
|
|
80
86
|
exports.normal_cdf = normal_cdf;
|
|
81
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Standard normal survival function P(Z > x) = 1 − Φ(x) for Z ~ N(0, 1).
|
|
90
|
+
*
|
|
91
|
+
* Computed directly (not as `1 − normal_cdf(x)`), so upper-tail
|
|
92
|
+
* probabilities such as PPM defect rates keep their significant digits:
|
|
93
|
+
* `normal_sf(6)` is `9.865876450376948e-10` to about 15 digits.
|
|
94
|
+
* @param {number} x
|
|
95
|
+
* @returns {number}
|
|
96
|
+
*/
|
|
97
|
+
function normal_sf(x) {
|
|
98
|
+
const ret = wasm.normal_sf(x);
|
|
99
|
+
return ret;
|
|
100
|
+
}
|
|
101
|
+
exports.normal_sf = normal_sf;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Forward DFT of a real sequence of any length.
|
|
105
|
+
*
|
|
106
|
+
* Returns the `n` complex bins interleaved as `[re0, im0, re1, im1, …]`
|
|
107
|
+
* (length `2n`). Bins `k` and `n − k` are conjugates, so the spectrum of a
|
|
108
|
+
* real signal is fully described by bins `0..=n/2`.
|
|
109
|
+
* @param {Float64Array} data
|
|
110
|
+
* @returns {Float64Array}
|
|
111
|
+
*/
|
|
112
|
+
function rfft(data) {
|
|
113
|
+
const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
|
|
114
|
+
const len0 = WASM_VECTOR_LEN;
|
|
115
|
+
const ret = wasm.rfft(ptr0, len0);
|
|
116
|
+
var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
117
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
118
|
+
return v2;
|
|
119
|
+
}
|
|
120
|
+
exports.rfft = rfft;
|
|
121
|
+
|
|
82
122
|
/**
|
|
83
123
|
* Sample standard deviation of `data` (Bessel-corrected, denominator n−1).
|
|
84
124
|
*
|
|
@@ -111,7 +151,29 @@ exports.variance = variance;
|
|
|
111
151
|
function __wbg_get_imports() {
|
|
112
152
|
const import0 = {
|
|
113
153
|
__proto__: null,
|
|
114
|
-
|
|
154
|
+
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
155
|
+
const ret = String(arg1);
|
|
156
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
157
|
+
const len1 = WASM_VECTOR_LEN;
|
|
158
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
159
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
160
|
+
},
|
|
161
|
+
__wbg___wbindgen_throw_5d9e815e6fdf150f: function(arg0, arg1) {
|
|
162
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
163
|
+
},
|
|
164
|
+
__wbg_new_bebc3f4757acf305: function() {
|
|
165
|
+
const ret = new Object();
|
|
166
|
+
return ret;
|
|
167
|
+
},
|
|
168
|
+
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
169
|
+
arg0[arg1] = arg2;
|
|
170
|
+
},
|
|
171
|
+
__wbindgen_generic_0000000000000001: function(arg0) {
|
|
172
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
173
|
+
const ret = arg0;
|
|
174
|
+
return ret;
|
|
175
|
+
},
|
|
176
|
+
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
115
177
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
116
178
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
117
179
|
return ret;
|
|
@@ -137,6 +199,14 @@ function getArrayF64FromWasm0(ptr, len) {
|
|
|
137
199
|
return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
|
|
138
200
|
}
|
|
139
201
|
|
|
202
|
+
let cachedDataViewMemory0 = null;
|
|
203
|
+
function getDataViewMemory0() {
|
|
204
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
205
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
206
|
+
}
|
|
207
|
+
return cachedDataViewMemory0;
|
|
208
|
+
}
|
|
209
|
+
|
|
140
210
|
let cachedFloat64ArrayMemory0 = null;
|
|
141
211
|
function getFloat64ArrayMemory0() {
|
|
142
212
|
if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
|
|
@@ -164,6 +234,43 @@ function passArrayF64ToWasm0(arg, malloc) {
|
|
|
164
234
|
return ptr;
|
|
165
235
|
}
|
|
166
236
|
|
|
237
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
238
|
+
if (realloc === undefined) {
|
|
239
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
240
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
241
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
242
|
+
WASM_VECTOR_LEN = buf.length;
|
|
243
|
+
return ptr;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
let len = arg.length;
|
|
247
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
248
|
+
|
|
249
|
+
const mem = getUint8ArrayMemory0();
|
|
250
|
+
|
|
251
|
+
let offset = 0;
|
|
252
|
+
|
|
253
|
+
for (; offset < len; offset++) {
|
|
254
|
+
const code = arg.charCodeAt(offset);
|
|
255
|
+
if (code > 0x7F) break;
|
|
256
|
+
mem[ptr + offset] = code;
|
|
257
|
+
}
|
|
258
|
+
if (offset !== len) {
|
|
259
|
+
if (offset !== 0) {
|
|
260
|
+
arg = arg.slice(offset);
|
|
261
|
+
}
|
|
262
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
263
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
264
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
265
|
+
|
|
266
|
+
offset += ret.written;
|
|
267
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
WASM_VECTOR_LEN = offset;
|
|
271
|
+
return ptr;
|
|
272
|
+
}
|
|
273
|
+
|
|
167
274
|
function takeFromExternrefTable0(idx) {
|
|
168
275
|
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
169
276
|
wasm.__externref_table_dealloc(idx);
|
|
@@ -176,6 +283,19 @@ function decodeText(ptr, len) {
|
|
|
176
283
|
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
177
284
|
}
|
|
178
285
|
|
|
286
|
+
const cachedTextEncoder = new TextEncoder();
|
|
287
|
+
|
|
288
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
289
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
290
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
291
|
+
view.set(buf);
|
|
292
|
+
return {
|
|
293
|
+
read: arg.length,
|
|
294
|
+
written: buf.length
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
179
299
|
let WASM_VECTOR_LEN = 0;
|
|
180
300
|
|
|
181
301
|
const wasmPath = `${__dirname}/u_numflow_bg.wasm`;
|
package/node/u_numflow.d.cts
CHANGED
|
@@ -15,13 +15,18 @@ export function box_cox(data: Float64Array, lambda: number): Float64Array;
|
|
|
15
15
|
/**
|
|
16
16
|
* Estimate the optimal Box-Cox lambda via profile maximum likelihood.
|
|
17
17
|
*
|
|
18
|
-
* Searches in the range `[lambda_min, lambda_max]` using golden-section search
|
|
18
|
+
* Searches in the range `[lambda_min, lambda_max]` using golden-section search
|
|
19
|
+
* and returns `{ lambda: number, at_bound: boolean }`. `at_bound` is `true`
|
|
20
|
+
* when the maximum lies on an end of the range — the likelihood was still
|
|
21
|
+
* rising there, so `lambda` is that range limit (reported exactly), not an
|
|
22
|
+
* interior estimate; widen the range to find the unconstrained optimum.
|
|
19
23
|
*
|
|
20
24
|
* # Errors
|
|
21
25
|
* Returns a `JsValue` error string if data contains non-positive values,
|
|
22
|
-
* has fewer than 2 elements, or
|
|
26
|
+
* has fewer than 2 elements, or the range is not finite with
|
|
27
|
+
* `lambda_min < lambda_max`.
|
|
23
28
|
*/
|
|
24
|
-
export function estimate_lambda(data: Float64Array, lambda_min: number, lambda_max: number):
|
|
29
|
+
export function estimate_lambda(data: Float64Array, lambda_min: number, lambda_max: number): any;
|
|
25
30
|
|
|
26
31
|
/**
|
|
27
32
|
* Arithmetic mean of `data` using Kahan compensated summation.
|
|
@@ -35,10 +40,29 @@ export function mean(data: Float64Array): number;
|
|
|
35
40
|
*
|
|
36
41
|
* To evaluate a general normal N(μ, σ), pass `(x - μ) / σ`.
|
|
37
42
|
*
|
|
38
|
-
*
|
|
43
|
+
* Computed as `erfc(−x/√2)/2` with a direct `erfc`, so the lower tail keeps
|
|
44
|
+
* relative precision. For the upper tail use [`normal_sf`].
|
|
39
45
|
*/
|
|
40
46
|
export function normal_cdf(x: number): number;
|
|
41
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Standard normal survival function P(Z > x) = 1 − Φ(x) for Z ~ N(0, 1).
|
|
50
|
+
*
|
|
51
|
+
* Computed directly (not as `1 − normal_cdf(x)`), so upper-tail
|
|
52
|
+
* probabilities such as PPM defect rates keep their significant digits:
|
|
53
|
+
* `normal_sf(6)` is `9.865876450376948e-10` to about 15 digits.
|
|
54
|
+
*/
|
|
55
|
+
export function normal_sf(x: number): number;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Forward DFT of a real sequence of any length.
|
|
59
|
+
*
|
|
60
|
+
* Returns the `n` complex bins interleaved as `[re0, im0, re1, im1, …]`
|
|
61
|
+
* (length `2n`). Bins `k` and `n − k` are conjugates, so the spectrum of a
|
|
62
|
+
* real signal is fully described by bins `0..=n/2`.
|
|
63
|
+
*/
|
|
64
|
+
export function rfft(data: Float64Array): Float64Array;
|
|
65
|
+
|
|
42
66
|
/**
|
|
43
67
|
* Sample standard deviation of `data` (Bessel-corrected, denominator n−1).
|
|
44
68
|
*
|
package/node/u_numflow_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"collaborators": [
|
|
5
5
|
"iyulab"
|
|
6
6
|
],
|
|
7
|
-
"description": "
|
|
8
|
-
"version": "0.
|
|
7
|
+
"description": "Foundational mathematical primitives: statistics, probability distributions, random sampling, and collections.",
|
|
8
|
+
"version": "0.6.0",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
package/u_numflow.d.ts
CHANGED
|
@@ -15,13 +15,18 @@ export function box_cox(data: Float64Array, lambda: number): Float64Array;
|
|
|
15
15
|
/**
|
|
16
16
|
* Estimate the optimal Box-Cox lambda via profile maximum likelihood.
|
|
17
17
|
*
|
|
18
|
-
* Searches in the range `[lambda_min, lambda_max]` using golden-section search
|
|
18
|
+
* Searches in the range `[lambda_min, lambda_max]` using golden-section search
|
|
19
|
+
* and returns `{ lambda: number, at_bound: boolean }`. `at_bound` is `true`
|
|
20
|
+
* when the maximum lies on an end of the range — the likelihood was still
|
|
21
|
+
* rising there, so `lambda` is that range limit (reported exactly), not an
|
|
22
|
+
* interior estimate; widen the range to find the unconstrained optimum.
|
|
19
23
|
*
|
|
20
24
|
* # Errors
|
|
21
25
|
* Returns a `JsValue` error string if data contains non-positive values,
|
|
22
|
-
* has fewer than 2 elements, or
|
|
26
|
+
* has fewer than 2 elements, or the range is not finite with
|
|
27
|
+
* `lambda_min < lambda_max`.
|
|
23
28
|
*/
|
|
24
|
-
export function estimate_lambda(data: Float64Array, lambda_min: number, lambda_max: number):
|
|
29
|
+
export function estimate_lambda(data: Float64Array, lambda_min: number, lambda_max: number): any;
|
|
25
30
|
|
|
26
31
|
/**
|
|
27
32
|
* Arithmetic mean of `data` using Kahan compensated summation.
|
|
@@ -35,10 +40,29 @@ export function mean(data: Float64Array): number;
|
|
|
35
40
|
*
|
|
36
41
|
* To evaluate a general normal N(μ, σ), pass `(x - μ) / σ`.
|
|
37
42
|
*
|
|
38
|
-
*
|
|
43
|
+
* Computed as `erfc(−x/√2)/2` with a direct `erfc`, so the lower tail keeps
|
|
44
|
+
* relative precision. For the upper tail use [`normal_sf`].
|
|
39
45
|
*/
|
|
40
46
|
export function normal_cdf(x: number): number;
|
|
41
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Standard normal survival function P(Z > x) = 1 − Φ(x) for Z ~ N(0, 1).
|
|
50
|
+
*
|
|
51
|
+
* Computed directly (not as `1 − normal_cdf(x)`), so upper-tail
|
|
52
|
+
* probabilities such as PPM defect rates keep their significant digits:
|
|
53
|
+
* `normal_sf(6)` is `9.865876450376948e-10` to about 15 digits.
|
|
54
|
+
*/
|
|
55
|
+
export function normal_sf(x: number): number;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Forward DFT of a real sequence of any length.
|
|
59
|
+
*
|
|
60
|
+
* Returns the `n` complex bins interleaved as `[re0, im0, re1, im1, …]`
|
|
61
|
+
* (length `2n`). Bins `k` and `n − k` are conjugates, so the spectrum of a
|
|
62
|
+
* real signal is fully described by bins `0..=n/2`.
|
|
63
|
+
*/
|
|
64
|
+
export function rfft(data: Float64Array): Float64Array;
|
|
65
|
+
|
|
42
66
|
/**
|
|
43
67
|
* Sample standard deviation of `data` (Bessel-corrected, denominator n−1).
|
|
44
68
|
*
|
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, estimate_lambda, mean, normal_cdf, std_dev, variance
|
|
8
|
+
box_cox, estimate_lambda, mean, normal_cdf, normal_sf, rfft, std_dev, variance
|
|
9
9
|
} from "./u_numflow_bg.js";
|
package/u_numflow_bg.js
CHANGED
|
@@ -25,15 +25,20 @@ export function box_cox(data, lambda) {
|
|
|
25
25
|
/**
|
|
26
26
|
* Estimate the optimal Box-Cox lambda via profile maximum likelihood.
|
|
27
27
|
*
|
|
28
|
-
* Searches in the range `[lambda_min, lambda_max]` using golden-section search
|
|
28
|
+
* Searches in the range `[lambda_min, lambda_max]` using golden-section search
|
|
29
|
+
* and returns `{ lambda: number, at_bound: boolean }`. `at_bound` is `true`
|
|
30
|
+
* when the maximum lies on an end of the range — the likelihood was still
|
|
31
|
+
* rising there, so `lambda` is that range limit (reported exactly), not an
|
|
32
|
+
* interior estimate; widen the range to find the unconstrained optimum.
|
|
29
33
|
*
|
|
30
34
|
* # Errors
|
|
31
35
|
* Returns a `JsValue` error string if data contains non-positive values,
|
|
32
|
-
* has fewer than 2 elements, or
|
|
36
|
+
* has fewer than 2 elements, or the range is not finite with
|
|
37
|
+
* `lambda_min < lambda_max`.
|
|
33
38
|
* @param {Float64Array} data
|
|
34
39
|
* @param {number} lambda_min
|
|
35
40
|
* @param {number} lambda_max
|
|
36
|
-
* @returns {
|
|
41
|
+
* @returns {any}
|
|
37
42
|
*/
|
|
38
43
|
export function estimate_lambda(data, lambda_min, lambda_max) {
|
|
39
44
|
const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
|
|
@@ -42,7 +47,7 @@ export function estimate_lambda(data, lambda_min, lambda_max) {
|
|
|
42
47
|
if (ret[2]) {
|
|
43
48
|
throw takeFromExternrefTable0(ret[1]);
|
|
44
49
|
}
|
|
45
|
-
return ret[0];
|
|
50
|
+
return takeFromExternrefTable0(ret[0]);
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
/**
|
|
@@ -64,7 +69,8 @@ export function mean(data) {
|
|
|
64
69
|
*
|
|
65
70
|
* To evaluate a general normal N(μ, σ), pass `(x - μ) / σ`.
|
|
66
71
|
*
|
|
67
|
-
*
|
|
72
|
+
* Computed as `erfc(−x/√2)/2` with a direct `erfc`, so the lower tail keeps
|
|
73
|
+
* relative precision. For the upper tail use [`normal_sf`].
|
|
68
74
|
* @param {number} x
|
|
69
75
|
* @returns {number}
|
|
70
76
|
*/
|
|
@@ -73,6 +79,38 @@ export function normal_cdf(x) {
|
|
|
73
79
|
return ret;
|
|
74
80
|
}
|
|
75
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Standard normal survival function P(Z > x) = 1 − Φ(x) for Z ~ N(0, 1).
|
|
84
|
+
*
|
|
85
|
+
* Computed directly (not as `1 − normal_cdf(x)`), so upper-tail
|
|
86
|
+
* probabilities such as PPM defect rates keep their significant digits:
|
|
87
|
+
* `normal_sf(6)` is `9.865876450376948e-10` to about 15 digits.
|
|
88
|
+
* @param {number} x
|
|
89
|
+
* @returns {number}
|
|
90
|
+
*/
|
|
91
|
+
export function normal_sf(x) {
|
|
92
|
+
const ret = wasm.normal_sf(x);
|
|
93
|
+
return ret;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Forward DFT of a real sequence of any length.
|
|
98
|
+
*
|
|
99
|
+
* Returns the `n` complex bins interleaved as `[re0, im0, re1, im1, …]`
|
|
100
|
+
* (length `2n`). Bins `k` and `n − k` are conjugates, so the spectrum of a
|
|
101
|
+
* real signal is fully described by bins `0..=n/2`.
|
|
102
|
+
* @param {Float64Array} data
|
|
103
|
+
* @returns {Float64Array}
|
|
104
|
+
*/
|
|
105
|
+
export function rfft(data) {
|
|
106
|
+
const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
|
|
107
|
+
const len0 = WASM_VECTOR_LEN;
|
|
108
|
+
const ret = wasm.rfft(ptr0, len0);
|
|
109
|
+
var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
110
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
111
|
+
return v2;
|
|
112
|
+
}
|
|
113
|
+
|
|
76
114
|
/**
|
|
77
115
|
* Sample standard deviation of `data` (Bessel-corrected, denominator n−1).
|
|
78
116
|
*
|
|
@@ -100,7 +138,29 @@ export function variance(data) {
|
|
|
100
138
|
const ret = wasm.variance(ptr0, len0);
|
|
101
139
|
return ret;
|
|
102
140
|
}
|
|
103
|
-
export function
|
|
141
|
+
export function __wbg_String_8564e559799eccda(arg0, arg1) {
|
|
142
|
+
const ret = String(arg1);
|
|
143
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
144
|
+
const len1 = WASM_VECTOR_LEN;
|
|
145
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
146
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
147
|
+
}
|
|
148
|
+
export function __wbg___wbindgen_throw_5d9e815e6fdf150f(arg0, arg1) {
|
|
149
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
150
|
+
}
|
|
151
|
+
export function __wbg_new_bebc3f4757acf305() {
|
|
152
|
+
const ret = new Object();
|
|
153
|
+
return ret;
|
|
154
|
+
}
|
|
155
|
+
export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
|
|
156
|
+
arg0[arg1] = arg2;
|
|
157
|
+
}
|
|
158
|
+
export function __wbindgen_generic_0000000000000001(arg0) {
|
|
159
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
160
|
+
const ret = arg0;
|
|
161
|
+
return ret;
|
|
162
|
+
}
|
|
163
|
+
export function __wbindgen_generic_0000000000000002(arg0, arg1) {
|
|
104
164
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
105
165
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
106
166
|
return ret;
|
|
@@ -119,6 +179,14 @@ function getArrayF64FromWasm0(ptr, len) {
|
|
|
119
179
|
return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
|
|
120
180
|
}
|
|
121
181
|
|
|
182
|
+
let cachedDataViewMemory0 = null;
|
|
183
|
+
function getDataViewMemory0() {
|
|
184
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
185
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
186
|
+
}
|
|
187
|
+
return cachedDataViewMemory0;
|
|
188
|
+
}
|
|
189
|
+
|
|
122
190
|
let cachedFloat64ArrayMemory0 = null;
|
|
123
191
|
function getFloat64ArrayMemory0() {
|
|
124
192
|
if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
|
|
@@ -146,6 +214,43 @@ function passArrayF64ToWasm0(arg, malloc) {
|
|
|
146
214
|
return ptr;
|
|
147
215
|
}
|
|
148
216
|
|
|
217
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
218
|
+
if (realloc === undefined) {
|
|
219
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
220
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
221
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
222
|
+
WASM_VECTOR_LEN = buf.length;
|
|
223
|
+
return ptr;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
let len = arg.length;
|
|
227
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
228
|
+
|
|
229
|
+
const mem = getUint8ArrayMemory0();
|
|
230
|
+
|
|
231
|
+
let offset = 0;
|
|
232
|
+
|
|
233
|
+
for (; offset < len; offset++) {
|
|
234
|
+
const code = arg.charCodeAt(offset);
|
|
235
|
+
if (code > 0x7F) break;
|
|
236
|
+
mem[ptr + offset] = code;
|
|
237
|
+
}
|
|
238
|
+
if (offset !== len) {
|
|
239
|
+
if (offset !== 0) {
|
|
240
|
+
arg = arg.slice(offset);
|
|
241
|
+
}
|
|
242
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
243
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
244
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
245
|
+
|
|
246
|
+
offset += ret.written;
|
|
247
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
WASM_VECTOR_LEN = offset;
|
|
251
|
+
return ptr;
|
|
252
|
+
}
|
|
253
|
+
|
|
149
254
|
function takeFromExternrefTable0(idx) {
|
|
150
255
|
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
151
256
|
wasm.__externref_table_dealloc(idx);
|
|
@@ -166,6 +271,19 @@ function decodeText(ptr, len) {
|
|
|
166
271
|
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
167
272
|
}
|
|
168
273
|
|
|
274
|
+
const cachedTextEncoder = new TextEncoder();
|
|
275
|
+
|
|
276
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
277
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
278
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
279
|
+
view.set(buf);
|
|
280
|
+
return {
|
|
281
|
+
read: arg.length,
|
|
282
|
+
written: buf.length
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
169
287
|
let WASM_VECTOR_LEN = 0;
|
|
170
288
|
|
|
171
289
|
|
package/u_numflow_bg.wasm
CHANGED
|
Binary file
|