fastlowess-wasm 4.0.0 → 4.1.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 CHANGED
@@ -12,7 +12,7 @@
12
12
  <em>One LOWESS to Rule Them All</em>
13
13
  </p>
14
14
 
15
- The fastest, most robust, and most feature-complete language-agnostic LOWESS (Locally Weighted Scatterplot Smoothing) implementation for **Rust**, **Python**, **R**, **Julia**, **JavaScript**, **C++**, **Go**, **Java**, and **WebAssembly**.
15
+ The fastest, most robust, and most feature-complete language-agnostic LOWESS (Locally Weighted Scatterplot Smoothing) implementation for **Rust**, **Python**, **R**, **Julia**, **Node.js**, **C++**, **Go**, **Java**, and **WebAssembly**.
16
16
 
17
17
  The `lowess-project` also offers bindings for Rust, Python, R, Julia, Node.js, WebAssembly, C++, Go, and Java — see the [full repository](https://github.com/thisisamirv/lowess-project).
18
18
 
@@ -25,6 +25,8 @@ export interface SmoothOptions {
25
25
  return_residuals?: boolean;
26
26
  /** Include robustness weights in result. Default: false. */
27
27
  return_robustness_weights?: boolean;
28
+ /** Include the per-point local fit derivative (slope) in result. Default: false. */
29
+ return_derivative?: boolean;
28
30
  /** Compute diagnostics (RMSE, MAE, R2, etc.). Ignored by OnlineLowess (it has no diagnostics field). Default: false. */
29
31
  return_diagnostics?: boolean;
30
32
  /** Include standard errors in result. Batch (Lowess) only; ignored by StreamingLowess/OnlineLowess. Default: false. */
@@ -47,9 +49,47 @@ export interface SmoothOptions {
47
49
  cv_seed?: number;
48
50
  /** Policy for non-finite (NaN/Inf) values in input data ("error", "drop"). Default: "error". */
49
51
  missing?: string;
52
+ /** Retain the fitted model's training data, enabling `LowessResult.predict()`. Batch (Lowess) only. Default: false. */
53
+ retain_model?: boolean;
50
54
  }
51
55
 
52
- /** Configuration options for streaming LOWESS smoothing. A subset of `SmoothOptions`: confidence/prediction intervals, standard errors, cross-validation, and `return_sorted` have no equivalent here. */
56
+ /** Options for `LowessResult.predict()`. */
57
+ export interface PredictOptions {
58
+ /** Include standard errors in the output. Default: false. */
59
+ return_se?: boolean;
60
+ /** Confidence interval coverage level (e.g. 0.95). Disabled when absent. */
61
+ confidence_level?: number;
62
+ /** Prediction interval coverage level (e.g. 0.95). Disabled when absent. */
63
+ prediction_level?: number;
64
+ /** Include the local fit's derivative (slope) in the output. Default: false. */
65
+ return_derivative?: boolean;
66
+ /** Behavior for query points outside the training range ("clamp", "linear", "error"). Default: "clamp". */
67
+ extrapolation?: string;
68
+ /** Under "linear" extrapolation, the maximum allowed distance beyond the training boundary before `predict()` errors instead of returning an unbounded value. */
69
+ max_extrapolation_distance?: number;
70
+ /** Maximum allowed distance to the farthest point in a query's local window before `predict()` errors, catching in-range-but-sparse query points. */
71
+ max_neighbor_distance?: number;
72
+ }
73
+
74
+ /** Result of `LowessResult.predict()`. */
75
+ export interface PredictOutput {
76
+ /** Predicted y values, one per query point. */
77
+ readonly y: Float64Array;
78
+ /** Standard errors (if requested). */
79
+ readonly standard_errors: Float64Array | undefined;
80
+ /** Lower confidence interval bounds (if requested). */
81
+ readonly confidence_lower: Float64Array | undefined;
82
+ /** Upper confidence interval bounds (if requested). */
83
+ readonly confidence_upper: Float64Array | undefined;
84
+ /** Lower prediction interval bounds (if requested). */
85
+ readonly prediction_lower: Float64Array | undefined;
86
+ /** Upper prediction interval bounds (if requested). */
87
+ readonly prediction_upper: Float64Array | undefined;
88
+ /** Local fit's derivative (slope) at each query point (if requested). */
89
+ readonly derivative: Float64Array | undefined;
90
+ }
91
+
92
+ /** Configuration options for streaming LOWESS smoothing. A subset of `SmoothOptions`: cross-validation and `return_sorted` have no equivalent here. */
53
93
  export interface StreamingSmoothOptions {
54
94
  /** Smoothing fraction (0 < fraction <= 1). Default: 0.67. */
55
95
  fraction?: number;
@@ -73,19 +113,27 @@ export interface StreamingSmoothOptions {
73
113
  return_residuals?: boolean;
74
114
  /** Include robustness weights in result. Default: false. */
75
115
  return_robustness_weights?: boolean;
116
+ /** Include the per-point local fit derivative (slope) in result. Default: false. */
117
+ return_derivative?: boolean;
76
118
  /** Compute diagnostics (RMSE, MAE, R2, etc.). Default: false. */
77
119
  return_diagnostics?: boolean;
120
+ /** Compute standard errors. Default: false. */
121
+ return_se?: boolean;
122
+ /** Calculate confidence intervals (e.g., 0.95). Default: undefined. */
123
+ confidence_intervals?: number;
124
+ /** Calculate prediction intervals. Default: undefined. */
125
+ prediction_intervals?: number;
78
126
  /** Enable parallel execution. Default: true. */
79
127
  parallel?: boolean;
80
128
  /** Policy for non-finite (NaN/Inf) values in each chunk ("error", "drop"). Default: "error". */
81
129
  missing?: string;
82
130
  }
83
131
 
84
- /** Configuration options for online LOWESS smoothing. A subset of `SmoothOptions`: diagnostics, residuals, parallel execution, confidence/prediction intervals, standard errors, cross-validation, and `return_sorted` have no equivalent here. */
132
+ /** Configuration options for online LOWESS smoothing. A subset of `SmoothOptions`: diagnostics, residuals, parallel execution, cross-validation, and `return_sorted` have no equivalent here. `return_se`/`confidence_intervals`/`prediction_intervals` require `update_mode = "full"`. */
85
133
  export interface OnlineSmoothOptions {
86
134
  /** Smoothing fraction (0 < fraction <= 1). Default: 0.67. */
87
135
  fraction?: number;
88
- /** Number of robustness iterations. Default: 3. */
136
+ /** Number of robustness iterations. Requires `update_mode = "full"`. Default: 0. */
89
137
  iterations?: number;
90
138
  /** Delta for interpolation speedup. Default: auto. Set to 0 to disable. */
91
139
  delta?: number;
@@ -103,8 +151,16 @@ export interface OnlineSmoothOptions {
103
151
  auto_converge?: number;
104
152
  /** Include robustness weights in result. Default: false. */
105
153
  return_robustness_weights?: boolean;
154
+ /** Include the latest point's local fit derivative (slope) in result. Default: false. */
155
+ return_derivative?: boolean;
106
156
  /** Policy for non-finite (NaN/Inf) `x`/`y` values passed to `add_point` ("error", "drop"). Default: "error". */
107
157
  missing?: string;
158
+ /** Compute standard errors. Requires `update_mode = "full"`. Default: false. */
159
+ return_se?: boolean;
160
+ /** Calculate confidence intervals (e.g., 0.95). Requires `update_mode = "full"`. Default: undefined. */
161
+ confidence_intervals?: number;
162
+ /** Calculate prediction intervals. Requires `update_mode = "full"`. Default: undefined. */
163
+ prediction_intervals?: number;
108
164
  }
109
165
 
110
166
  /** Configuration options for streaming LOWESS. */
@@ -161,6 +217,11 @@ export class OnlineOutput {
161
217
  get residual(): number | undefined;
162
218
  get robustness_weight(): number | undefined;
163
219
  get iterations_used(): number | undefined;
220
+ get derivative(): number | undefined;
221
+ get confidence_lower(): number | undefined;
222
+ get confidence_upper(): number | undefined;
223
+ get prediction_lower(): number | undefined;
224
+ get prediction_upper(): number | undefined;
164
225
  }
165
226
 
166
227
 
@@ -188,6 +249,7 @@ export class LowessResult {
188
249
  readonly confidence_lower: Float64Array | undefined;
189
250
  readonly confidence_upper: Float64Array | undefined;
190
251
  readonly cv_scores: Float64Array | undefined;
252
+ readonly derivative: Float64Array | undefined;
191
253
  readonly diagnostics: Diagnostics | undefined;
192
254
  readonly fraction_used: number;
193
255
  readonly iterations_used: number | undefined;
@@ -204,7 +266,12 @@ export class OnlineOutput {
204
266
  private constructor();
205
267
  free(): void;
206
268
  [Symbol.dispose](): void;
269
+ readonly confidence_lower: number | undefined;
270
+ readonly confidence_upper: number | undefined;
271
+ readonly derivative: number | undefined;
207
272
  readonly iterations_used: number | undefined;
273
+ readonly prediction_lower: number | undefined;
274
+ readonly prediction_upper: number | undefined;
208
275
  readonly residual: number | undefined;
209
276
  readonly robustness_weight: number | undefined;
210
277
  readonly standard_error: number | undefined;
@@ -229,6 +296,7 @@ export interface InitOutput {
229
296
  readonly __wbg_lowessresult_free: (a: number, b: number) => void;
230
297
  readonly __wbg_onlinelowess_free: (a: number, b: number) => void;
231
298
  readonly __wbg_onlineoutput_free: (a: number, b: number) => void;
299
+ readonly __wbg_predictoutput_free: (a: number, b: number) => void;
232
300
  readonly __wbg_set_diagnostics_aic: (a: number, b: number, c: number) => void;
233
301
  readonly __wbg_set_diagnostics_aicc: (a: number, b: number, c: number) => void;
234
302
  readonly __wbg_set_diagnostics_effective_df: (a: number, b: number, c: number) => void;
@@ -243,9 +311,11 @@ export interface InitOutput {
243
311
  readonly lowessresult_confidence_lower: (a: number) => any;
244
312
  readonly lowessresult_confidence_upper: (a: number) => any;
245
313
  readonly lowessresult_cv_scores: (a: number) => any;
314
+ readonly lowessresult_derivative: (a: number) => any;
246
315
  readonly lowessresult_diagnostics: (a: number) => number;
247
316
  readonly lowessresult_fraction_used: (a: number) => number;
248
317
  readonly lowessresult_iterations_used: (a: number) => number;
318
+ readonly lowessresult_predict: (a: number, b: any, c: any) => [number, number, number];
249
319
  readonly lowessresult_prediction_lower: (a: number) => any;
250
320
  readonly lowessresult_prediction_upper: (a: number) => any;
251
321
  readonly lowessresult_residuals: (a: number) => any;
@@ -255,11 +325,23 @@ export interface InitOutput {
255
325
  readonly lowessresult_y: (a: number) => any;
256
326
  readonly onlinelowess_add_point: (a: number, b: number, c: number) => [number, number, number];
257
327
  readonly onlinelowess_new: (a: any, b: any) => [number, number, number];
328
+ readonly onlineoutput_confidence_lower: (a: number) => [number, number];
329
+ readonly onlineoutput_confidence_upper: (a: number) => [number, number];
330
+ readonly onlineoutput_derivative: (a: number) => [number, number];
258
331
  readonly onlineoutput_iterations_used: (a: number) => number;
332
+ readonly onlineoutput_prediction_lower: (a: number) => [number, number];
333
+ readonly onlineoutput_prediction_upper: (a: number) => [number, number];
259
334
  readonly onlineoutput_residual: (a: number) => [number, number];
260
335
  readonly onlineoutput_robustness_weight: (a: number) => [number, number];
261
336
  readonly onlineoutput_standard_error: (a: number) => [number, number];
262
337
  readonly onlineoutput_y: (a: number) => number;
338
+ readonly predictoutput_confidence_lower: (a: number) => any;
339
+ readonly predictoutput_confidence_upper: (a: number) => any;
340
+ readonly predictoutput_derivative: (a: number) => any;
341
+ readonly predictoutput_prediction_lower: (a: number) => any;
342
+ readonly predictoutput_prediction_upper: (a: number) => any;
343
+ readonly predictoutput_standard_errors: (a: number) => any;
344
+ readonly predictoutput_y: (a: number) => any;
263
345
  readonly streaminglowess_finalize: (a: number) => [number, number, number];
264
346
  readonly streaminglowess_new: (a: any, b: any) => [number, number, number];
265
347
  readonly streaminglowess_process_chunk: (a: number, b: any, c: any) => [number, number, number];
@@ -189,6 +189,13 @@ export class LowessResult {
189
189
  const ret = wasm.lowessresult_cv_scores(this.__wbg_ptr);
190
190
  return ret;
191
191
  }
192
+ /**
193
+ * @returns {Float64Array | undefined}
194
+ */
195
+ get derivative() {
196
+ const ret = wasm.lowessresult_derivative(this.__wbg_ptr);
197
+ return ret;
198
+ }
192
199
  /**
193
200
  * @returns {Diagnostics | undefined}
194
201
  */
@@ -210,6 +217,21 @@ export class LowessResult {
210
217
  const ret = wasm.lowessresult_iterations_used(this.__wbg_ptr);
211
218
  return ret === Number.MAX_SAFE_INTEGER ? undefined : ret;
212
219
  }
220
+ /**
221
+ * Evaluate the fitted model at out-of-sample query points not in the training set.
222
+ *
223
+ * Requires `retain_model: true` to have been set on the builder before `fit()`.
224
+ * @param {Float64Array} new_x
225
+ * @param {any} options
226
+ * @returns {PredictOutput}
227
+ */
228
+ predict(new_x, options) {
229
+ const ret = wasm.lowessresult_predict(this.__wbg_ptr, new_x, options);
230
+ if (ret[2]) {
231
+ throw takeFromExternrefTable0(ret[1]);
232
+ }
233
+ return PredictOutput.__wrap(ret[0]);
234
+ }
213
235
  /**
214
236
  * @returns {Float64Array | undefined}
215
237
  */
@@ -318,6 +340,27 @@ export class OnlineOutput {
318
340
  const ptr = this.__destroy_into_raw();
319
341
  wasm.__wbg_onlineoutput_free(ptr, 0);
320
342
  }
343
+ /**
344
+ * @returns {number | undefined}
345
+ */
346
+ get confidence_lower() {
347
+ const ret = wasm.onlineoutput_confidence_lower(this.__wbg_ptr);
348
+ return ret[0] === 0 ? undefined : ret[1];
349
+ }
350
+ /**
351
+ * @returns {number | undefined}
352
+ */
353
+ get confidence_upper() {
354
+ const ret = wasm.onlineoutput_confidence_upper(this.__wbg_ptr);
355
+ return ret[0] === 0 ? undefined : ret[1];
356
+ }
357
+ /**
358
+ * @returns {number | undefined}
359
+ */
360
+ get derivative() {
361
+ const ret = wasm.onlineoutput_derivative(this.__wbg_ptr);
362
+ return ret[0] === 0 ? undefined : ret[1];
363
+ }
321
364
  /**
322
365
  * @returns {number | undefined}
323
366
  */
@@ -325,6 +368,20 @@ export class OnlineOutput {
325
368
  const ret = wasm.onlineoutput_iterations_used(this.__wbg_ptr);
326
369
  return ret === Number.MAX_SAFE_INTEGER ? undefined : ret;
327
370
  }
371
+ /**
372
+ * @returns {number | undefined}
373
+ */
374
+ get prediction_lower() {
375
+ const ret = wasm.onlineoutput_prediction_lower(this.__wbg_ptr);
376
+ return ret[0] === 0 ? undefined : ret[1];
377
+ }
378
+ /**
379
+ * @returns {number | undefined}
380
+ */
381
+ get prediction_upper() {
382
+ const ret = wasm.onlineoutput_prediction_upper(this.__wbg_ptr);
383
+ return ret[0] === 0 ? undefined : ret[1];
384
+ }
328
385
  /**
329
386
  * @returns {number | undefined}
330
387
  */
@@ -356,6 +413,78 @@ export class OnlineOutput {
356
413
  }
357
414
  if (Symbol.dispose) OnlineOutput.prototype[Symbol.dispose] = OnlineOutput.prototype.free;
358
415
 
416
+ /**
417
+ * Result of `LowessResult.predict()`.
418
+ */
419
+ export class PredictOutput {
420
+ static __wrap(ptr) {
421
+ const obj = Object.create(PredictOutput.prototype);
422
+ obj.__wbg_ptr = ptr;
423
+ PredictOutputFinalization.register(obj, obj.__wbg_ptr, obj);
424
+ return obj;
425
+ }
426
+ __destroy_into_raw() {
427
+ const ptr = this.__wbg_ptr;
428
+ this.__wbg_ptr = 0;
429
+ PredictOutputFinalization.unregister(this);
430
+ return ptr;
431
+ }
432
+ free() {
433
+ const ptr = this.__destroy_into_raw();
434
+ wasm.__wbg_predictoutput_free(ptr, 0);
435
+ }
436
+ /**
437
+ * @returns {Float64Array | undefined}
438
+ */
439
+ get confidence_lower() {
440
+ const ret = wasm.predictoutput_confidence_lower(this.__wbg_ptr);
441
+ return ret;
442
+ }
443
+ /**
444
+ * @returns {Float64Array | undefined}
445
+ */
446
+ get confidence_upper() {
447
+ const ret = wasm.predictoutput_confidence_upper(this.__wbg_ptr);
448
+ return ret;
449
+ }
450
+ /**
451
+ * @returns {Float64Array | undefined}
452
+ */
453
+ get derivative() {
454
+ const ret = wasm.predictoutput_derivative(this.__wbg_ptr);
455
+ return ret;
456
+ }
457
+ /**
458
+ * @returns {Float64Array | undefined}
459
+ */
460
+ get prediction_lower() {
461
+ const ret = wasm.predictoutput_prediction_lower(this.__wbg_ptr);
462
+ return ret;
463
+ }
464
+ /**
465
+ * @returns {Float64Array | undefined}
466
+ */
467
+ get prediction_upper() {
468
+ const ret = wasm.predictoutput_prediction_upper(this.__wbg_ptr);
469
+ return ret;
470
+ }
471
+ /**
472
+ * @returns {Float64Array | undefined}
473
+ */
474
+ get standard_errors() {
475
+ const ret = wasm.predictoutput_standard_errors(this.__wbg_ptr);
476
+ return ret;
477
+ }
478
+ /**
479
+ * @returns {Float64Array}
480
+ */
481
+ get y() {
482
+ const ret = wasm.predictoutput_y(this.__wbg_ptr);
483
+ return ret;
484
+ }
485
+ }
486
+ if (Symbol.dispose) PredictOutput.prototype[Symbol.dispose] = PredictOutput.prototype.free;
487
+
359
488
  export class StreamingLowess {
360
489
  __destroy_into_raw() {
361
490
  const ptr = this.__wbg_ptr;
@@ -645,6 +774,9 @@ const OnlineLowessFinalization = (typeof FinalizationRegistry === 'undefined')
645
774
  const OnlineOutputFinalization = (typeof FinalizationRegistry === 'undefined')
646
775
  ? { register: () => {}, unregister: () => {} }
647
776
  : new FinalizationRegistry(ptr => wasm.__wbg_onlineoutput_free(ptr, 1));
777
+ const PredictOutputFinalization = (typeof FinalizationRegistry === 'undefined')
778
+ ? { register: () => {}, unregister: () => {} }
779
+ : new FinalizationRegistry(ptr => wasm.__wbg_predictoutput_free(ptr, 1));
648
780
  const StreamingLowessFinalization = (typeof FinalizationRegistry === 'undefined')
649
781
  ? { register: () => {}, unregister: () => {} }
650
782
  : new FinalizationRegistry(ptr => wasm.__wbg_streaminglowess_free(ptr, 1));
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Amir Valizadeh <thisisamirv@gmail.com>"
6
6
  ],
7
7
  "description": "High-performance LOWESS (Locally Weighted Scatterplot Smoothing)",
8
- "version": "4.0.0",
8
+ "version": "4.1.0",
9
9
  "license": "MIT OR Apache-2.0",
10
10
  "repository": {
11
11
  "type": "git",