Skip to content

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

  • Dataset fits in memory
  • Need intervals, cross-validation, or diagnostics
  • Processing complete files

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: function
  • options: An object containing LoessOptions fields.

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.5
Iterations used: 3
  • x: Float64Array of input x values.
  • y: Float64Array of input y values.
  • Returns: A LoessResult object.

See Streaming Adapter for the StreamingLoess class.

See Online Adapter for the OnlineLoess class.

FieldTypeDefaultDescription
fractionnumber0.67Smoothing fraction (bandwidth)
iterationsnumber3Number of robustifying iterations
weight_functionstring"tricube"Kernel weight function
robustness_methodstring"bisquare"Robustness method
scaling_methodstring"mad"Residual scaling method
boundary_policystring"extend"Boundary handling policy
zero_weight_fallbackstring"use_local_mean"Zero-weight handling
auto_convergenumbernullAuto-convergence tolerance
custom_weightsnumber[]nullPer-observation case weights — passed to fit(), not the options object (Batch only; see Custom Weights)
confidence_intervalsnumbernullConfidence level (e.g., 0.95) — see Intervals
prediction_intervalsnumbernullPrediction level (e.g., 0.95) — see Intervals
return_diagnosticsbooleanfalseCompute RMSE, MAE, R², AIC
return_residualsbooleanfalseInclude residuals in result
return_robustness_weightsbooleanfalseInclude robustness weights in result
return_sebooleanfalseCompute hat-matrix statistics (enp, leverage …)
parallelbooleantrueEnable parallel execution
degreestring"linear"Polynomial degree of local fit — see Polynomial Degree
dimensionsnumber1Number of predictor dimensions — see Multivariate LOESS
distance_metricstring"normalized"Distance metric; use "minkowski:p" for custom p
weighted_metric_weightsnumber[]nullPer-dimension weights (used when distance_metric = "weighted")
surface_modestring"interpolation"Surface computation mode
cellnumbernullCell size for interpolation grid (smaller → more vertices, higher accuracy)
interpolation_verticesnumbernullNumber of interpolation vertices
boundary_degree_fallbackbooleannullFall back to lower polynomial degree at boundaries when higher degrees fail
cv_methodstring"kfold"CV method ("kfold" fast or "loocv" slow, exhaustive) (Batch only)
cv_knumber5Number of folds for k-fold CV (Batch only)
cv_fractionsnumber[]nullFractions to test for cross-validation (Batch only)
cv_seednumbernullRandom 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.

RangeEffectUse case
0.1-0.3Fine detailRapidly changing signals
0.3-0.5BalancedGeneral purpose
0.5-0.7Heavy smoothingNoisy data
0.7-1.0Very smoothTrend extraction

iterations controls robustness to outliers, at the cost of speed.

ValueEffectPerformance
0No robustnessFastest
1-3ModerateRecommended
4-6StrongContaminated data
7+Very strongHeavy outliers

See Streaming Adapter for StreamingOptions.

See Online Adapter for OnlineOptions.

See Online Adapter for OnlineOutput.

FieldTypeDescription
xFloat64ArraySorted x values
yFloat64ArraySmoothed y values
fraction_usednumberFraction used (set or selected by CV)
iterations_usednumber | undefinedRobustness iterations actually performed
standard_errorsFloat64Array | undefinedPer-point SE (if return_se)
confidence_lowerFloat64Array | undefinedLower confidence bounds
confidence_upperFloat64Array | undefinedUpper confidence bounds
prediction_lowerFloat64Array | undefinedLower prediction bounds
prediction_upperFloat64Array | undefinedUpper prediction bounds
residualsFloat64Array | undefinedResiduals (if return_residuals)
robustness_weightsFloat64Array | undefinedRobustness weights (if return_robustness_weights)
cv_scoresFloat64Array | undefinedCV score per tested fraction
diagnosticsDiagnostics | undefinedFit metrics (if return_diagnostics)
enpnumber | undefinedEquivalent number of parameters (if return_se)
trace_hatnumber | undefinedTrace of hat matrix (if return_se)
delta1number | undefinedFirst delta statistic (if return_se)
delta2number | undefinedSecond delta statistic (if return_se)
residual_scalenumber | undefinedResidual scale estimate (if return_se)
leverageFloat64Array | undefinedPer-point hat-matrix diagonal (if return_se)
dimensionsnumberNumber of predictor dimensions
FieldTypeDescription
rmsenumberRoot Mean Squared Error
maenumberMean Absolute Error
r_squarednumberR-squared
residual_sdnumberResidual standard deviation
effective_dfnumber | undefinedEffective degrees of freedom
aicnumber | undefinedAIC
aiccnumber | undefinedAICc

See: Weight Functions

  • "tricube" (default)
  • "epanechnikov"
  • "gaussian"
  • "uniform" (alias: "boxcar")
  • "biweight" (alias: "bisquare")
  • "triangle" (alias: "triangular")
  • "cosine"

See: Robustness

  • "bisquare" (default; alias: "biweight")
  • "huber"
  • "talwar"

See: Boundary Handling

  • "extend" (default; alias: "pad")
  • "reflect" (alias: "mirror")
  • "zero"
  • "noboundary" (alias: "none")

See: Scaling Methods

  • "mad" (default; alias: "median_absolute_deviation")
  • "mar" (alias: "median_absolute_residual")
  • "mean" (alias: "mean_absolute_residual")

Behavior when all neighborhood weights are zero:

OptionBehavior
"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

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)

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" plus weighted_metric_weights for per-dimension scaling (alias: "weighted_euclidean")

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.

ModeBehaviorSpeedAccuracy
"interpolation" (default)Evaluate at vertices, interpolate betweenFasterSlight approximation
"direct"Evaluate at every query pointSlowerFull precision
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 data
const 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 ]