Skip to content

API

The Node.js 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 allows configuring the LOWESS parameters once and fitting multiple datasets using those parameters.

Constructor:

const { Lowess } = require('fastlowess');
const model = new Lowess({ fraction: 0.5, iterations: 3 });
const result = model.fit(
new Float64Array([0, 1, 2, 3, 4, 5]),
new Float64Array([0.0, 1.1, 1.9, 3.1, 3.9, 5.0])
);
console.log("y[0]:", result.y[0].toFixed(4));
y[0]: 0.0000
  • options: An object containing LowessOptions fields.

Methods:

const { Lowess } = require('fastlowess');
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
  • Fits the model to the provided x and y typed arrays.
  • Returns a LowessResult object containing the smoothed values and optional diagnostics.

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
backendstring"cpu"Execution backend ("cpu" or "gpu"); GPU requires the package to be built with the gpu Cargo feature (Batch only)
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.

The batch Lowess class can optionally run on a GPU-accelerated backend powered by wgpu, for high-throughput processing of large datasets (10k+ points). GPU support applies to Lowess (batch) only — StreamingLowess/OnlineLowess remain CPU-only. See the GPU Backend guide for installation, usage, supported features, and hardware requirements.

See Online Adapter for OnlineOutput.

FieldTypeDescription
xFloat64ArraySorted x values
yFloat64ArraySmoothed y values
fraction_usednumberFraction used (set or selected by CV)
iterations_usednumber | nullRobustness iterations actually performed
standard_errorsFloat64Array | nullPer-point standard errors
confidence_lowerFloat64Array | nullLower confidence bounds
confidence_upperFloat64Array | nullUpper confidence bounds
prediction_lowerFloat64Array | nullLower prediction bounds
prediction_upperFloat64Array | nullUpper prediction bounds
residualsFloat64Array | nullResiduals (if return_residuals)
robustness_weightsFloat64Array | nullRobustness weights (if return_robustness_weights)
cv_scoresFloat64Array | nullCV score per tested fraction
diagnosticsDiagnostics | nullFit metrics (if return_diagnostics)
FieldTypeDescription
rmsenumberRoot Mean Squared Error
maenumberMean Absolute Error
r_squarednumberR-squared
residual_sdnumberResidual standard deviation
effective_dfnumber | nullEffective degrees of freedom
aicnumber | nullAIC
aiccnumber | nullAICc

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');
const x = new Float64Array([1, 2, 3, 4, 5]);
const y = new Float64Array([2.1, 4.0, 6.2, 8.0, 10.1]);
// Configure model
const model = new Lowess({ fraction: 0.5 });
// Fit data
const result = model.fit(x, y);
console.log("Smoothed Y:", result.y);
Smoothed Y: Float64Array(5) [ 2.1, 4, 6.2, 8, 10.1 ]