@iyulab/u-numflow 0.6.3 → 0.6.4
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 +26 -21
- package/node/u_numflow.cjs +2 -2
- package/node/u_numflow_bg.wasm +0 -0
- package/package.json +1 -1
- package/u_numflow_bg.js +2 -2
- package/u_numflow_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -38,31 +38,34 @@ u-numflow = "0.2"
|
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
```rust
|
|
41
|
-
use u_numflow::
|
|
42
|
-
use u_numflow::
|
|
43
|
-
use u_numflow::
|
|
41
|
+
use u_numflow::distributions::Pert;
|
|
42
|
+
use u_numflow::random::{create_rng, shuffle};
|
|
43
|
+
use u_numflow::stats::WelfordAccumulator;
|
|
44
44
|
|
|
45
|
-
// Online statistics with numerical stability
|
|
46
|
-
let mut stats =
|
|
45
|
+
// Online statistics with numerical stability (Welford)
|
|
46
|
+
let mut stats = WelfordAccumulator::new();
|
|
47
47
|
for x in [1.0, 2.0, 3.0, 4.0, 5.0] {
|
|
48
|
-
stats.
|
|
48
|
+
stats.update(x);
|
|
49
49
|
}
|
|
50
|
-
assert_eq!(stats.mean(), 3.0);
|
|
50
|
+
assert_eq!(stats.mean(), Some(3.0));
|
|
51
51
|
|
|
52
|
-
// PERT distribution
|
|
53
|
-
let pert =
|
|
54
|
-
|
|
55
|
-
let
|
|
52
|
+
// PERT distribution: moments and quantiles; sample by inverting a uniform draw
|
|
53
|
+
let pert = Pert::new(1.0, 4.0, 7.0).unwrap();
|
|
54
|
+
assert_eq!(pert.mean(), 4.0);
|
|
55
|
+
let p90 = pert.quantile(0.9).unwrap();
|
|
56
|
+
assert!(p90 > 4.0 && p90 < 7.0);
|
|
56
57
|
|
|
57
58
|
// Seeded shuffling for reproducibility
|
|
59
|
+
let mut rng = create_rng(42);
|
|
58
60
|
let mut items = vec![1, 2, 3, 4, 5];
|
|
59
|
-
|
|
61
|
+
shuffle(&mut items, &mut rng);
|
|
60
62
|
|
|
61
63
|
// Box-Cox transformation (non-normal data normalization)
|
|
62
|
-
use u_numflow::transforms::{
|
|
64
|
+
use u_numflow::transforms::{box_cox, estimate_lambda};
|
|
63
65
|
let data = [1.0, 2.0, 4.0, 8.0, 16.0];
|
|
64
|
-
let
|
|
65
|
-
let transformed = box_cox(&data, lambda).unwrap();
|
|
66
|
+
let fit = estimate_lambda(&data, -2.0, 2.0).unwrap(); // MLE via golden-section
|
|
67
|
+
let transformed = box_cox(&data, fit.lambda).unwrap();
|
|
68
|
+
assert_eq!(transformed.len(), data.len());
|
|
66
69
|
|
|
67
70
|
// Discrete Fourier transform of any length
|
|
68
71
|
use u_numflow::fourier::rfft;
|
|
@@ -125,20 +128,22 @@ t_distribution_quantile(0.975, 10); // 2.2281…
|
|
|
125
128
|
|
|
126
129
|
### TypeScript
|
|
127
130
|
|
|
128
|
-
Every exported function declares its return
|
|
129
|
-
generated from the same structs the binding
|
|
130
|
-
from what it actually returns:
|
|
131
|
+
Every exported function declares its parameter and return types, and the
|
|
132
|
+
declarations are generated from the same structs the binding reads and
|
|
133
|
+
serialises, so they cannot drift from what it actually accepts and returns:
|
|
131
134
|
|
|
132
135
|
```ts
|
|
133
|
-
export function estimate_lambda(data:
|
|
136
|
+
export function estimate_lambda(data: Float64Array, lambda_min: number, lambda_max: number): LambdaEstimateDto;
|
|
134
137
|
```
|
|
135
138
|
|
|
136
139
|
An absent optional value is declared `T | undefined`, which is what the binding
|
|
137
140
|
sends. Nothing needs an `as` cast -- and a wrong assumption about a result's
|
|
138
141
|
shape is a compile error rather than something that fails at run time.
|
|
139
142
|
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
Every parameter is a number or a `Float64Array`, so there is nothing to
|
|
144
|
+
declare beyond what wasm-bindgen already does; the publishing workflow keeps it
|
|
145
|
+
that way. The binding still validates every input at the boundary, and a
|
|
146
|
+
rejected one says what was wrong.
|
|
142
147
|
|
|
143
148
|
## Related
|
|
144
149
|
|
package/node/u_numflow.cjs
CHANGED
|
@@ -289,10 +289,10 @@ function __wbg_get_imports() {
|
|
|
289
289
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
290
290
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
291
291
|
},
|
|
292
|
-
|
|
292
|
+
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
|
|
293
293
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
294
294
|
},
|
|
295
|
-
|
|
295
|
+
__wbg_new_617a8cdb8bb1130e: function() {
|
|
296
296
|
const ret = new Object();
|
|
297
297
|
return ret;
|
|
298
298
|
},
|
package/node/u_numflow_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/u_numflow_bg.js
CHANGED
|
@@ -269,10 +269,10 @@ export function __wbg_String_8564e559799eccda(arg0, arg1) {
|
|
|
269
269
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
270
270
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
271
271
|
}
|
|
272
|
-
export function
|
|
272
|
+
export function __wbg___wbindgen_throw_41e9ee4f547fc59a(arg0, arg1) {
|
|
273
273
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
274
274
|
}
|
|
275
|
-
export function
|
|
275
|
+
export function __wbg_new_617a8cdb8bb1130e() {
|
|
276
276
|
const ret = new Object();
|
|
277
277
|
return ret;
|
|
278
278
|
}
|
package/u_numflow_bg.wasm
CHANGED
|
Binary file
|