@iyulab/u-numflow 0.2.1 → 0.3.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 +13 -0
- package/node/u_numflow.cjs +186 -0
- package/node/u_numflow.d.cts +54 -0
- package/node/u_numflow_bg.wasm +0 -0
- package/package.json +17 -5
- package/u_numflow.js +1 -1
- package/u_numflow_bg.js +1 -2
- package/u_numflow_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -80,6 +80,19 @@ cargo test
|
|
|
80
80
|
|
|
81
81
|
MIT License — see [LICENSE](LICENSE).
|
|
82
82
|
|
|
83
|
+
## npm (WebAssembly)
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
npm install @iyulab/u-numflow
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The package resolves per environment via a conditional `exports` map:
|
|
90
|
+
|
|
91
|
+
| Environment | Entry |
|
|
92
|
+
|---|---|
|
|
93
|
+
| Bundlers (webpack, Vite, …) | ESM + WebAssembly ESM-integration (`default` condition) |
|
|
94
|
+
| 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
|
+
|
|
83
96
|
## Related
|
|
84
97
|
|
|
85
98
|
- [u-metaheur](https://github.com/iyulab/u-metaheur) — Metaheuristic optimization (GA, SA, ALNS, CP)
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/* @ts-self-types="./u_numflow.d.cts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Apply the Box-Cox power transformation to positive data.
|
|
5
|
+
*
|
|
6
|
+
* All values in `data` must be strictly positive.
|
|
7
|
+
*
|
|
8
|
+
* # Errors
|
|
9
|
+
* Returns a `JsValue` error string if data contains non-positive values or
|
|
10
|
+
* has fewer than 2 elements.
|
|
11
|
+
* @param {Float64Array} data
|
|
12
|
+
* @param {number} lambda
|
|
13
|
+
* @returns {Float64Array}
|
|
14
|
+
*/
|
|
15
|
+
function box_cox(data, lambda) {
|
|
16
|
+
const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
|
|
17
|
+
const len0 = WASM_VECTOR_LEN;
|
|
18
|
+
const ret = wasm.box_cox(ptr0, len0, lambda);
|
|
19
|
+
if (ret[3]) {
|
|
20
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
21
|
+
}
|
|
22
|
+
var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
23
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
24
|
+
return v2;
|
|
25
|
+
}
|
|
26
|
+
exports.box_cox = box_cox;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Estimate the optimal Box-Cox lambda via profile maximum likelihood.
|
|
30
|
+
*
|
|
31
|
+
* Searches in the range `[lambda_min, lambda_max]` using golden-section search.
|
|
32
|
+
*
|
|
33
|
+
* # Errors
|
|
34
|
+
* Returns a `JsValue` error string if data contains non-positive values,
|
|
35
|
+
* has fewer than 2 elements, or `lambda_min >= lambda_max`.
|
|
36
|
+
* @param {Float64Array} data
|
|
37
|
+
* @param {number} lambda_min
|
|
38
|
+
* @param {number} lambda_max
|
|
39
|
+
* @returns {number}
|
|
40
|
+
*/
|
|
41
|
+
function estimate_lambda(data, lambda_min, lambda_max) {
|
|
42
|
+
const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
|
|
43
|
+
const len0 = WASM_VECTOR_LEN;
|
|
44
|
+
const ret = wasm.estimate_lambda(ptr0, len0, lambda_min, lambda_max);
|
|
45
|
+
if (ret[2]) {
|
|
46
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
47
|
+
}
|
|
48
|
+
return ret[0];
|
|
49
|
+
}
|
|
50
|
+
exports.estimate_lambda = estimate_lambda;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Arithmetic mean of `data` using Kahan compensated summation.
|
|
54
|
+
*
|
|
55
|
+
* Returns `NaN` if `data` is empty or contains non-finite values.
|
|
56
|
+
* @param {Float64Array} data
|
|
57
|
+
* @returns {number}
|
|
58
|
+
*/
|
|
59
|
+
function mean(data) {
|
|
60
|
+
const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
|
|
61
|
+
const len0 = WASM_VECTOR_LEN;
|
|
62
|
+
const ret = wasm.mean(ptr0, len0);
|
|
63
|
+
return ret;
|
|
64
|
+
}
|
|
65
|
+
exports.mean = mean;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Standard normal CDF Φ(x) = P(Z ≤ x) for Z ~ N(0, 1).
|
|
69
|
+
*
|
|
70
|
+
* To evaluate a general normal N(μ, σ), pass `(x - μ) / σ`.
|
|
71
|
+
*
|
|
72
|
+
* Uses Abramowitz & Stegun formula 26.2.17 (max abs error < 7.5 × 10⁻⁸).
|
|
73
|
+
* @param {number} x
|
|
74
|
+
* @returns {number}
|
|
75
|
+
*/
|
|
76
|
+
function normal_cdf(x) {
|
|
77
|
+
const ret = wasm.normal_cdf(x);
|
|
78
|
+
return ret;
|
|
79
|
+
}
|
|
80
|
+
exports.normal_cdf = normal_cdf;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Sample standard deviation of `data` (Bessel-corrected, denominator n−1).
|
|
84
|
+
*
|
|
85
|
+
* Returns `NaN` if `data` has fewer than 2 elements or contains non-finite values.
|
|
86
|
+
* @param {Float64Array} data
|
|
87
|
+
* @returns {number}
|
|
88
|
+
*/
|
|
89
|
+
function std_dev(data) {
|
|
90
|
+
const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
|
|
91
|
+
const len0 = WASM_VECTOR_LEN;
|
|
92
|
+
const ret = wasm.std_dev(ptr0, len0);
|
|
93
|
+
return ret;
|
|
94
|
+
}
|
|
95
|
+
exports.std_dev = std_dev;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Sample variance of `data` (Bessel-corrected, denominator n−1).
|
|
99
|
+
*
|
|
100
|
+
* Returns `NaN` if `data` has fewer than 2 elements or contains non-finite values.
|
|
101
|
+
* @param {Float64Array} data
|
|
102
|
+
* @returns {number}
|
|
103
|
+
*/
|
|
104
|
+
function variance(data) {
|
|
105
|
+
const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_malloc);
|
|
106
|
+
const len0 = WASM_VECTOR_LEN;
|
|
107
|
+
const ret = wasm.variance(ptr0, len0);
|
|
108
|
+
return ret;
|
|
109
|
+
}
|
|
110
|
+
exports.variance = variance;
|
|
111
|
+
function __wbg_get_imports() {
|
|
112
|
+
const import0 = {
|
|
113
|
+
__proto__: null,
|
|
114
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
115
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
116
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
117
|
+
return ret;
|
|
118
|
+
},
|
|
119
|
+
__wbindgen_init_externref_table: function() {
|
|
120
|
+
const table = wasm.__wbindgen_externrefs;
|
|
121
|
+
const offset = table.grow(4);
|
|
122
|
+
table.set(0, undefined);
|
|
123
|
+
table.set(offset + 0, undefined);
|
|
124
|
+
table.set(offset + 1, null);
|
|
125
|
+
table.set(offset + 2, true);
|
|
126
|
+
table.set(offset + 3, false);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
__proto__: null,
|
|
131
|
+
"./u_numflow_bg.js": import0,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function getArrayF64FromWasm0(ptr, len) {
|
|
136
|
+
ptr = ptr >>> 0;
|
|
137
|
+
return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let cachedFloat64ArrayMemory0 = null;
|
|
141
|
+
function getFloat64ArrayMemory0() {
|
|
142
|
+
if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
|
|
143
|
+
cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
|
|
144
|
+
}
|
|
145
|
+
return cachedFloat64ArrayMemory0;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function getStringFromWasm0(ptr, len) {
|
|
149
|
+
return decodeText(ptr >>> 0, len);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let cachedUint8ArrayMemory0 = null;
|
|
153
|
+
function getUint8ArrayMemory0() {
|
|
154
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
155
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
156
|
+
}
|
|
157
|
+
return cachedUint8ArrayMemory0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function passArrayF64ToWasm0(arg, malloc) {
|
|
161
|
+
const ptr = malloc(arg.length * 8, 8) >>> 0;
|
|
162
|
+
getFloat64ArrayMemory0().set(arg, ptr / 8);
|
|
163
|
+
WASM_VECTOR_LEN = arg.length;
|
|
164
|
+
return ptr;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function takeFromExternrefTable0(idx) {
|
|
168
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
169
|
+
wasm.__externref_table_dealloc(idx);
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
174
|
+
cachedTextDecoder.decode();
|
|
175
|
+
function decodeText(ptr, len) {
|
|
176
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let WASM_VECTOR_LEN = 0;
|
|
180
|
+
|
|
181
|
+
const wasmPath = `${__dirname}/u_numflow_bg.wasm`;
|
|
182
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
183
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
184
|
+
let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
|
|
185
|
+
let wasm = wasmInstance.exports;
|
|
186
|
+
wasm.__wbindgen_start();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Apply the Box-Cox power transformation to positive data.
|
|
6
|
+
*
|
|
7
|
+
* All values in `data` must be strictly positive.
|
|
8
|
+
*
|
|
9
|
+
* # Errors
|
|
10
|
+
* Returns a `JsValue` error string if data contains non-positive values or
|
|
11
|
+
* has fewer than 2 elements.
|
|
12
|
+
*/
|
|
13
|
+
export function box_cox(data: Float64Array, lambda: number): Float64Array;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Estimate the optimal Box-Cox lambda via profile maximum likelihood.
|
|
17
|
+
*
|
|
18
|
+
* Searches in the range `[lambda_min, lambda_max]` using golden-section search.
|
|
19
|
+
*
|
|
20
|
+
* # Errors
|
|
21
|
+
* Returns a `JsValue` error string if data contains non-positive values,
|
|
22
|
+
* has fewer than 2 elements, or `lambda_min >= lambda_max`.
|
|
23
|
+
*/
|
|
24
|
+
export function estimate_lambda(data: Float64Array, lambda_min: number, lambda_max: number): number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Arithmetic mean of `data` using Kahan compensated summation.
|
|
28
|
+
*
|
|
29
|
+
* Returns `NaN` if `data` is empty or contains non-finite values.
|
|
30
|
+
*/
|
|
31
|
+
export function mean(data: Float64Array): number;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Standard normal CDF Φ(x) = P(Z ≤ x) for Z ~ N(0, 1).
|
|
35
|
+
*
|
|
36
|
+
* To evaluate a general normal N(μ, σ), pass `(x - μ) / σ`.
|
|
37
|
+
*
|
|
38
|
+
* Uses Abramowitz & Stegun formula 26.2.17 (max abs error < 7.5 × 10⁻⁸).
|
|
39
|
+
*/
|
|
40
|
+
export function normal_cdf(x: number): number;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Sample standard deviation of `data` (Bessel-corrected, denominator n−1).
|
|
44
|
+
*
|
|
45
|
+
* Returns `NaN` if `data` has fewer than 2 elements or contains non-finite values.
|
|
46
|
+
*/
|
|
47
|
+
export function std_dev(data: Float64Array): number;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Sample variance of `data` (Bessel-corrected, denominator n−1).
|
|
51
|
+
*
|
|
52
|
+
* Returns `NaN` if `data` has fewer than 2 elements or contains non-finite values.
|
|
53
|
+
*/
|
|
54
|
+
export function variance(data: Float64Array): number;
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"iyulab"
|
|
6
6
|
],
|
|
7
7
|
"description": "Mathematical primitives for the U-Engine ecosystem: statistics, probability, random sampling, and collections.",
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.3.0",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -15,18 +15,30 @@
|
|
|
15
15
|
"u_numflow_bg.wasm",
|
|
16
16
|
"u_numflow.js",
|
|
17
17
|
"u_numflow_bg.js",
|
|
18
|
-
"u_numflow.d.ts"
|
|
18
|
+
"u_numflow.d.ts",
|
|
19
|
+
"node"
|
|
19
20
|
],
|
|
20
21
|
"main": "u_numflow.js",
|
|
21
22
|
"types": "u_numflow.d.ts",
|
|
22
23
|
"sideEffects": [
|
|
23
24
|
"./u_numflow.js",
|
|
24
|
-
"./snippets/*"
|
|
25
|
+
"./snippets/*",
|
|
26
|
+
"./node/u_numflow.cjs"
|
|
25
27
|
],
|
|
26
28
|
"keywords": [
|
|
27
29
|
"statistics",
|
|
28
30
|
"probability",
|
|
29
31
|
"optimization",
|
|
30
32
|
"mathematics"
|
|
31
|
-
]
|
|
32
|
-
|
|
33
|
+
],
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"node": {
|
|
37
|
+
"types": "./node/u_numflow.d.cts",
|
|
38
|
+
"default": "./node/u_numflow.cjs"
|
|
39
|
+
},
|
|
40
|
+
"types": "./u_numflow.d.ts",
|
|
41
|
+
"default": "./u_numflow.js"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
package/u_numflow.js
CHANGED
package/u_numflow_bg.js
CHANGED
package/u_numflow_bg.wasm
CHANGED
|
Binary file
|