Skip to content

API

The WebAssembly bindings provide a high-performance interface to the core Rust library, mirroring the Rust API structure.

StreamingLowess and OnlineLowess are documented separately: Streaming Adapter, Online Adapter

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

The Lowess class is the main entry point for batch smoothing.

Constructor:

const { Lowess } = require('fastlowess-wasm');
const model = new Lowess({ fraction: 0.5, iterations: 3 });
console.log("typeof fit:", typeof model.fit);
typeof fit: function
  • options: An object containing LowessOptions fields.

Methods:

const { Lowess } = require('fastlowess-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 Lowess({ fraction: 0.5 });
const result = model.fit(x, y);
console.log("Fraction used:", result.fraction_used);
Fraction used: 0.5
  • x: Float64Array of input x values.
  • y: Float64Array of input y values.
  • Returns: A LowessResult object.

See Streaming Adapter for the StreamingLowess class.

See Online Adapter for the OnlineLowess class.

FieldTypeDefaultDescription
fractionnumber0.67Smoothing fraction (bandwidth)
iterationsnumber3Number of robustifying iterations
deltanumberNaNInterpolation distance (NaN auto-sets it to 1% of the x-range in Batch, or 0.0 in Streaming/Online)
weight_functionstring"tricube"Weight function name
robustness_methodstring"bisquare"Robustness method name
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
confidence_intervalsnumbernullConfidence level (e.g., 0.95) — see Intervals
prediction_intervalsnumbernullPrediction level (e.g., 0.95) — see Intervals
return_diagnosticsbooleanfalseInclude diagnostics in result
return_residualsbooleanfalseInclude residuals in result
return_robustness_weightsbooleanfalseInclude weights in result
return_sebooleanfalseReturn standard errors
parallelbooleantrueEnable parallel execution
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)
custom_weightsFloat64ArraynullPer-observation case weights — passed to fit(), not the options object (Batch only; see Custom Weights)

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 standard errors
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)
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
const { Lowess } = require('fastlowess-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 Lowess({ 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 ]