@iyulab/u-numflow 0.14.0 → 0.14.1

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 CHANGED
@@ -140,8 +140,8 @@ MIT License — see [LICENSE](LICENSE).
140
140
  dotnet add package UNumflow
141
141
  ```
142
142
 
143
- The distributions (CDF, quantile, moments, seeded sampling) and interval sets,
144
- backed by this crate through its C ABI (the `ffi` feature) — see
143
+ The distributions (CDF, quantile, moments, seeded sampling), sample statistics
144
+ (median, R-7 quantiles), interval sets and units, backed by this crate through its C ABI (the `ffi` feature) — see
145
145
  [bindings/csharp/README.md](bindings/csharp/README.md). Refusals carry the same
146
146
  `code` and fields as the WebAssembly binding's.
147
147
 
@@ -163,7 +163,7 @@ file with an ES module import, which browsers refuse (`application/wasm` is not
163
163
  module script type), so `<script type="module">` from a CDN fails, and CDN
164
164
  re-bundling services fail on the same import. Use a bundler or Node.
165
165
 
166
- 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
166
+ Exported functions: `mean`, `std_dev`, `variance`, `median`, `quantiles(data, probabilities) -> Float64Array` (sample quantiles in the order asked, R-7 linear interpolation — the default of R, NumPy and Excel — with one sort for all of them), `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
167
167
  `rfft(data) -> Float64Array` — the DFT of a real sequence of any length, interleaved as
168
168
  `[re0, im0, re1, im1, …]` (bins `k` and `n − k` are conjugates, so `0..=n/2` describes the spectrum).
169
169
 
@@ -172,6 +172,8 @@ element that is not a number (`null`, `undefined`, a string) throws `malformed_i
172
172
  and a NaN or ±Infinity throws `value_not_finite`, each with the element's `index` —
173
173
  `mean([1, null, 3])` throws rather than averaging the `null` as 0. `mean` of no values
174
174
  throws `empty_input`; `std_dev` and `variance` of fewer than 2 throw `insufficient_data`.
175
+ `median` and `quantiles` of no values throw `empty_input`; a probability outside `[0, 1]`
176
+ throws `parameter_out_of_range` with `parameter` `probabilities[i]`, `min` 0 and `max` 1.
175
177
 
176
178
  Distribution functions for critical values and p-values — each returns a `number` and
177
179
  **throws** (an `Error` naming the argument — see *Errors* below) when an argument is outside the domain,
@@ -362,6 +362,23 @@ function mean(data) {
362
362
  }
363
363
  exports.mean = mean;
364
364
 
365
+ /**
366
+ * Median of the sample `data` (even length: the mean of the middle two).
367
+ *
368
+ * # Errors
369
+ * Throws `empty_input` when `data` is empty.
370
+ * @param {number[] | Float64Array} data
371
+ * @returns {number}
372
+ */
373
+ function median(data) {
374
+ const ret = wasm.median(data);
375
+ if (ret[2]) {
376
+ throw takeFromExternrefTable0(ret[1]);
377
+ }
378
+ return ret[0];
379
+ }
380
+ exports.median = median;
381
+
365
382
  /**
366
383
  * Standard normal CDF Φ(x) = P(Z ≤ x) for Z ~ N(0, 1).
367
384
  *
@@ -393,6 +410,30 @@ function normal_sf(x) {
393
410
  }
394
411
  exports.normal_sf = normal_sf;
395
412
 
413
+ /**
414
+ * Sample quantiles of `data` at each of `probabilities`, in the order asked
415
+ * — R-7 linear interpolation (Hyndman & Fan 1996; the default of R, NumPy
416
+ * and Excel), sorting the sample once.
417
+ *
418
+ * # Errors
419
+ * Throws `empty_input` when `data` is empty, and `parameter_out_of_range`
420
+ * (`parameter` `probabilities[i]`, `min` 0, `max` 1) for a probability
421
+ * outside `[0, 1]`.
422
+ * @param {number[] | Float64Array} data
423
+ * @param {number[] | Float64Array} probabilities
424
+ * @returns {Float64Array}
425
+ */
426
+ function quantiles(data, probabilities) {
427
+ const ret = wasm.quantiles(data, probabilities);
428
+ if (ret[3]) {
429
+ throw takeFromExternrefTable0(ret[2]);
430
+ }
431
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
432
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
433
+ return v1;
434
+ }
435
+ exports.quantiles = quantiles;
436
+
396
437
  /**
397
438
  * Forward DFT of a real sequence of any length.
398
439
  *
@@ -276,6 +276,14 @@ export function inverse_normal_cdf(p: number): number;
276
276
  */
277
277
  export function mean(data: number[] | Float64Array): number;
278
278
 
279
+ /**
280
+ * Median of the sample `data` (even length: the mean of the middle two).
281
+ *
282
+ * # Errors
283
+ * Throws `empty_input` when `data` is empty.
284
+ */
285
+ export function median(data: number[] | Float64Array): number;
286
+
279
287
  /**
280
288
  * Standard normal CDF Φ(x) = P(Z ≤ x) for Z ~ N(0, 1).
281
289
  *
@@ -295,6 +303,18 @@ export function normal_cdf(x: number): number;
295
303
  */
296
304
  export function normal_sf(x: number): number;
297
305
 
306
+ /**
307
+ * Sample quantiles of `data` at each of `probabilities`, in the order asked
308
+ * — R-7 linear interpolation (Hyndman & Fan 1996; the default of R, NumPy
309
+ * and Excel), sorting the sample once.
310
+ *
311
+ * # Errors
312
+ * Throws `empty_input` when `data` is empty, and `parameter_out_of_range`
313
+ * (`parameter` `probabilities[i]`, `min` 0, `max` 1) for a probability
314
+ * outside `[0, 1]`.
315
+ */
316
+ export function quantiles(data: number[] | Float64Array, probabilities: number[] | Float64Array): Float64Array;
317
+
298
318
  /**
299
319
  * Forward DFT of a real sequence of any length.
300
320
  *
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.14.0",
8
+ "version": "0.14.1",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
package/u_numflow.d.ts CHANGED
@@ -276,6 +276,14 @@ export function inverse_normal_cdf(p: number): number;
276
276
  */
277
277
  export function mean(data: number[] | Float64Array): number;
278
278
 
279
+ /**
280
+ * Median of the sample `data` (even length: the mean of the middle two).
281
+ *
282
+ * # Errors
283
+ * Throws `empty_input` when `data` is empty.
284
+ */
285
+ export function median(data: number[] | Float64Array): number;
286
+
279
287
  /**
280
288
  * Standard normal CDF Φ(x) = P(Z ≤ x) for Z ~ N(0, 1).
281
289
  *
@@ -295,6 +303,18 @@ export function normal_cdf(x: number): number;
295
303
  */
296
304
  export function normal_sf(x: number): number;
297
305
 
306
+ /**
307
+ * Sample quantiles of `data` at each of `probabilities`, in the order asked
308
+ * — R-7 linear interpolation (Hyndman & Fan 1996; the default of R, NumPy
309
+ * and Excel), sorting the sample once.
310
+ *
311
+ * # Errors
312
+ * Throws `empty_input` when `data` is empty, and `parameter_out_of_range`
313
+ * (`parameter` `probabilities[i]`, `min` 0, `max` 1) for a probability
314
+ * outside `[0, 1]`.
315
+ */
316
+ export function quantiles(data: number[] | Float64Array, probabilities: number[] | Float64Array): Float64Array;
317
+
298
318
  /**
299
319
  * Forward DFT of a real sequence of any length.
300
320
  *
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, codes, 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, unit_convert, unit_convert_difference, unit_info, variance
8
+ box_cox, chi_squared_cdf, chi_squared_quantile, codes, 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, median, normal_cdf, normal_sf, quantiles, rfft, std_dev, t_distribution_cdf, t_distribution_quantile, unit_convert, unit_convert_difference, unit_info, variance
9
9
  } from "./u_numflow_bg.js";
package/u_numflow_bg.js CHANGED
@@ -342,6 +342,22 @@ export function mean(data) {
342
342
  return ret[0];
343
343
  }
344
344
 
345
+ /**
346
+ * Median of the sample `data` (even length: the mean of the middle two).
347
+ *
348
+ * # Errors
349
+ * Throws `empty_input` when `data` is empty.
350
+ * @param {number[] | Float64Array} data
351
+ * @returns {number}
352
+ */
353
+ export function median(data) {
354
+ const ret = wasm.median(data);
355
+ if (ret[2]) {
356
+ throw takeFromExternrefTable0(ret[1]);
357
+ }
358
+ return ret[0];
359
+ }
360
+
345
361
  /**
346
362
  * Standard normal CDF Φ(x) = P(Z ≤ x) for Z ~ N(0, 1).
347
363
  *
@@ -371,6 +387,29 @@ export function normal_sf(x) {
371
387
  return ret;
372
388
  }
373
389
 
390
+ /**
391
+ * Sample quantiles of `data` at each of `probabilities`, in the order asked
392
+ * — R-7 linear interpolation (Hyndman & Fan 1996; the default of R, NumPy
393
+ * and Excel), sorting the sample once.
394
+ *
395
+ * # Errors
396
+ * Throws `empty_input` when `data` is empty, and `parameter_out_of_range`
397
+ * (`parameter` `probabilities[i]`, `min` 0, `max` 1) for a probability
398
+ * outside `[0, 1]`.
399
+ * @param {number[] | Float64Array} data
400
+ * @param {number[] | Float64Array} probabilities
401
+ * @returns {Float64Array}
402
+ */
403
+ export function quantiles(data, probabilities) {
404
+ const ret = wasm.quantiles(data, probabilities);
405
+ if (ret[3]) {
406
+ throw takeFromExternrefTable0(ret[2]);
407
+ }
408
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
409
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
410
+ return v1;
411
+ }
412
+
374
413
  /**
375
414
  * Forward DFT of a real sequence of any length.
376
415
  *
package/u_numflow_bg.wasm CHANGED
Binary file