fastLoess WebAssembly API Reference
The WebAssembly bindings provide a high-performance interface to the core Rust library, mirroring the Rust API structure.
StreamingLoess and OnlineLoess are documented separately: Streaming Adapter, Online Adapter
When to Use Batch Adapter
Section titled “When to Use Batch Adapter”- Dataset fits in memory
- Need intervals, cross-validation, or diagnostics
- Processing complete files
Classes
Section titled “Classes”The Loess class is the main entry point for batch smoothing.
Constructor:
const { Loess } = require('fastloess-wasm');
const model = new Loess({ fraction: 0.5 });console.log("typeof fit:", typeof model.fit);typeof fit: functionoptions: An object containingLoessOptionsfields.
Methods:
const { Loess } = require('fastloess-wasm');
const n = 100;const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));const y = Float64Array.from(x, xi => Math.sin(xi) + 0.1);
const model = new Loess({ fraction: 0.5 });const result = model.fit(x, y);console.log("Fraction used:", result.fraction_used);console.log("Iterations used:", result.iterations_used);// or with per-observation weights:const weights = new Float64Array(n).fill(1);const resultWeighted = model.fit(x, y, weights);Fraction used: 0.5Iterations used: 3x:Float64Arrayof input x values.y:Float64Arrayof input y values.- Returns: A
LoessResultobject.
See Streaming Adapter for the StreamingLoess class.
See Online Adapter for the OnlineLoess class.
Options Structures
Section titled “Options Structures”LoessOptions
Section titled “LoessOptions”| Field | Type | Default | Description |
|---|---|---|---|
fraction | number | 0.67 | Smoothing fraction (bandwidth) |
iterations | number | 3 | Number of robustifying iterations |
weight_function | string | "tricube" | Kernel weight function |
robustness_method | string | "bisquare" | Robustness method |
scaling_method | string | "mad" | Residual scaling method |
boundary_policy | string | "extend" | Boundary handling policy |
zero_weight_fallback | string | "use_local_mean" | Zero-weight handling |
auto_converge | number | null | Auto-convergence tolerance |
custom_weights | number[] | null | Per-observation case weights — passed to fit(), not the options object (Batch only; see Custom Weights) |
confidence_intervals | number | null | Confidence level (e.g., 0.95) — see Intervals |
prediction_intervals | number | null | Prediction level (e.g., 0.95) — see Intervals |
return_diagnostics | boolean | false | Compute RMSE, MAE, R², AIC |
return_residuals | boolean | false | Include residuals in result |
return_robustness_weights | boolean | false | Include robustness weights in result |
return_se | boolean | false | Compute hat-matrix statistics (enp, leverage …) |
parallel | boolean | true | Enable parallel execution |
degree | string | "linear" | Polynomial degree of local fit — see Polynomial Degree |
dimensions | number | 1 | Number of predictor dimensions — see Multivariate LOESS |
distance_metric | string | "normalized" | Distance metric; use "minkowski:p" for custom p |
weighted_metric_weights | number[] | null | Per-dimension weights (used when distance_metric = "weighted") |
surface_mode | string | "interpolation" | Surface computation mode |
cell | number | null | Cell size for interpolation grid (smaller → more vertices, higher accuracy) |
interpolation_vertices | number | null | Number of interpolation vertices |
boundary_degree_fallback | boolean | null | Fall back to lower polynomial degree at boundaries when higher degrees fail |
cv_method | string | "kfold" | CV method ("kfold" fast or "loocv" slow, exhaustive) (Batch only) |
cv_k | number | 5 | Number of folds for k-fold CV (Batch only) |
cv_fractions | number[] | null | Fractions to test for cross-validation (Batch only) |
cv_seed | number | null | Random seed for cross-validation shuffling (Batch only) |
fraction is the most important parameter: it controls the size of the local neighbourhood used at each point.
| Range | Effect | Use case |
|---|---|---|
| 0.1-0.3 | Fine detail | Rapidly changing signals |
| 0.3-0.5 | Balanced | General purpose |
| 0.5-0.7 | Heavy smoothing | Noisy data |
| 0.7-1.0 | Very smooth | Trend extraction |
iterations controls robustness to outliers, at the cost of speed.
| Value | Effect | Performance |
|---|---|---|
| 0 | No robustness | Fastest |
| 1-3 | Moderate | Recommended |
| 4-6 | Strong | Contaminated data |
| 7+ | Very strong | Heavy outliers |
See Streaming Adapter for StreamingOptions.
See Online Adapter for OnlineOptions.
Result Structure
Section titled “Result Structure”See Online Adapter for OnlineOutput.
LoessResult
Section titled “LoessResult”| Field | Type | Description |
|---|---|---|
x | Float64Array | Sorted x values |
y | Float64Array | Smoothed y values |
fraction_used | number | Fraction used (set or selected by CV) |
iterations_used | number | undefined | Robustness iterations actually performed |
standard_errors | Float64Array | undefined | Per-point SE (if return_se) |
confidence_lower | Float64Array | undefined | Lower confidence bounds |
confidence_upper | Float64Array | undefined | Upper confidence bounds |
prediction_lower | Float64Array | undefined | Lower prediction bounds |
prediction_upper | Float64Array | undefined | Upper prediction bounds |
residuals | Float64Array | undefined | Residuals (if return_residuals) |
robustness_weights | Float64Array | undefined | Robustness weights (if return_robustness_weights) |
cv_scores | Float64Array | undefined | CV score per tested fraction |
diagnostics | Diagnostics | undefined | Fit metrics (if return_diagnostics) |
enp | number | undefined | Equivalent number of parameters (if return_se) |
trace_hat | number | undefined | Trace of hat matrix (if return_se) |
delta1 | number | undefined | First delta statistic (if return_se) |
delta2 | number | undefined | Second delta statistic (if return_se) |
residual_scale | number | undefined | Residual scale estimate (if return_se) |
leverage | Float64Array | undefined | Per-point hat-matrix diagonal (if return_se) |
dimensions | number | Number of predictor dimensions |
Diagnostics
Section titled “Diagnostics”| Field | Type | Description |
|---|---|---|
rmse | number | Root Mean Squared Error |
mae | number | Mean Absolute Error |
r_squared | number | R-squared |
residual_sd | number | Residual standard deviation |
effective_df | number | undefined | Effective degrees of freedom |
aic | number | undefined | AIC |
aicc | number | undefined | AICc |
Options
Section titled “Options”weight_function
Section titled “weight_function”See: Weight Functions
"tricube"(default)"epanechnikov""gaussian""uniform"(alias:"boxcar")"biweight"(alias:"bisquare")"triangle"(alias:"triangular")"cosine"
robustness_method
Section titled “robustness_method”See: Robustness
"bisquare"(default; alias:"biweight")"huber""talwar"
boundary_policy
Section titled “boundary_policy”See: Boundary Handling
"extend"(default; alias:"pad")"reflect"(alias:"mirror")"zero""noboundary"(alias:"none")
scaling_method
Section titled “scaling_method”See: Scaling Methods
"mad"(default; alias:"median_absolute_deviation")"mar"(alias:"median_absolute_residual")"mean"(alias:"mean_absolute_residual")
zero_weight_fallback
Section titled “zero_weight_fallback”Behavior when all neighborhood weights are zero:
| Option | Behavior |
|---|---|
"use_local_mean" (default; aliases: "local_mean", "mean") | Use the mean of the neighborhood |
"return_original" (alias: "original") | Return the original y value |
"return_none" (alias: "none") | Return NaN |
degree
Section titled “degree”See: Polynomial Degree
"constant"or"0"(degree 0)"linear"or"1"(default, degree 1)"quadratic"or"2"(degree 2)"cubic"or"3"(degree 3)"quartic"or"4"(degree 4)
distance_metric
Section titled “distance_metric”See: Multivariate LOESS
"normalized"(default — scales each dimension by its range; alias:"norm")"euclidean"(alias:"euclid")"manhattan"(alias:"l1")"chebyshev"(alias:"linf")"minkowski"(Euclidean when no suffix; use"minkowski:p"for custom p, e.g."minkowski:3")"weighted"plusweighted_metric_weightsfor per-dimension scaling (alias:"weighted_euclidean")
surface_mode
Section titled “surface_mode”See: Polynomial Degree
Controls whether the local polynomial is evaluated at every query point or at a sparser grid of anchor vertices with Hermite cubic interpolation in between.
| Mode | Behavior | Speed | Accuracy |
|---|---|---|---|
"interpolation" (default) | Evaluate at vertices, interpolate between | Faster | Slight approximation |
"direct" | Evaluate at every query point | Slower | Full precision |
Example
Section titled “Example”const { Loess } = require('fastloess-wasm');
const x = new Float64Array([1, 2, 3, 4, 5]);const y = new Float64Array([2.1, 4.0, 6.2, 8.0, 10.1]);
// Fit dataconst model = new Loess({ fraction: 0.5 });const result = model.fit(x, y);
console.log("Smoothed Y:", result.y);Smoothed Y: Float64Array(5) [ 2.1, 4, 6.2, 8, 10.1 ]