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.

Fits the model to the provided x and y typed arrays. customWeights is an optional Float64Array of per-observation weights — all values must be ≥ 0 and length must match x. Returns a LowessResult object containing the smoothed values and optional diagnostics.

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
FieldTypeDefaultDescription
fractionnumber0.67Smoothing fraction (bandwidth)
iterationsnumber3Number of robustifying iterations
weight_functionstring"tricube"Weight function name
robustness_methodstring"bisquare"Robustness method name
deltanumberNaNInterpolation distance (NaN auto-sets it to 1% of the x-range)
zero_weight_fallbackstring"use_local_mean"Zero-weight handling
boundary_policystring"extend"Boundary handling policy
scaling_methodstring"mad"Residual scaling method
auto_convergenumbernullAuto-convergence tolerance
missingstring"error"Policy for non-finite (NaN/Inf) values in input data
parallelbooleantrueEnable parallel execution
backendstring"cpu"Execution backend ("cpu" or "gpu"); GPU requires the package to be built with the gpu Cargo feature
outputsstring[][]Select se, diagnostics, residuals, weights, derivative, and/or sorted
intervalsobjectnullGrouped interval options: confidence, prediction, and bootstrap
cvobjectnullGrouped CV options: method, k, and fractions
seednumbernullShared CV/bootstrap seed; must be an integer from 0 through Number.MAX_SAFE_INTEGER
retain_modelbooleanfalseRetain training data, enabling result.predict()
custom_weightsFloat64ArraynullPer-observation case weights — passed to fit(), not the options object

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: Weight Functions

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

See: Robustness

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

Points within delta of each other on the x-axis share the same local fit instead of each computing its own regression — an interpolation shortcut that trades a small amount of accuracy for a large speedup on dense, evenly-spaced data. NaN (default) auto-sets it to 1% of the x-range. Set it to 0 explicitly to disable interpolation and fit every point exactly.

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: 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")

See: Robustness

Convergence tolerance for early stopping of robustness iterations. null (default) disables early stopping.

Policy for handling non-finite (NaN/Inf) values in x/y (and custom_weights):

OptionBehavior
"error" (default)Throw an error if any value is non-finite
"drop"Silently remove observations where x or y is non-finite before fitting

Note: A length mismatch between x and y always errors, even under "drop".

Enable multi-threaded execution via Rayon.

  • true (default) — parallelizes the local regression fits across CPU cores
  • false — forces single-threaded execution (useful for benchmarking or deterministic profiling)

See: GPU Backend

The batch Lowess class can optionally run on a GPU-accelerated backend powered by wgpu, for high-throughput processing of large datasets (10k+ points).

  • "cpu" (default)
  • "gpu" — requires the package to be built with the gpu Cargo feature

See: Intervals

Computes hat-matrix statistics (effective degrees of freedom, leverage, delta1/delta2) in addition to standard errors.

See: Diagnostics

Select "diagnostics" to include a Diagnostics object (RMSE, MAE, R², AIC/AICc, effective degrees of freedom) in the result. AIC/AICc/effective_df additionally require "se" (or confidence/prediction intervals) to be selected, since they depend on hat-matrix statistics.

Include per-point residuals (y - fitted) in the result.

Include the final per-point robustness weights (from the last robustness iteration) in the result.

Each point’s local WLS fit already computes a slope internally; this exposes that per-point slope (rate of change of the smoothed curve) in LowessResult.derivative, enabling turning-point/rate-of-change analysis at effectively no extra computation cost.

When set to true, it reorders every result field (residuals, intervals, etc.) by x in an ascending manner, instead of in original input order. To get both orderings, sort the default result client-side (e.g. by the returned x array’s sort order) instead of calling fit() twice.

See: Intervals

An object such as { confidence: 0.90, prediction: 0.99, bootstrap: 200 }. Confidence and prediction coverage levels are independent: confidence bounds the mean response and prediction bounds a new observation; omitted levels disable that bound. bootstrap (at least 2) replaces analytic intervals with residual-bootstrap standard errors and percentile bounds. seed controls fit-time bootstrap draws but does not enable bootstrap by itself.

See: Cross-Validation

An object such as { method: "kfold", k: 5, fractions: [0.2, 0.3, 0.5] }:

  • method: "kfold" (default) — fast, evaluates each candidate fraction over k folds; "loocv" — slow, exhaustive leave-one-out cross-validation
  • k: Number of folds for k-fold CV. Ignored when method: "loocv".
  • fractions: Candidate fractions to evaluate. Required.

Seed k-fold shuffling with the outer seed option, not inside cv.

One seed shared by k-fold CV shuffling and fit-time residual bootstrap. It does not enable either feature by itself; null (default) uses each feature’s default. Seeds must be finite, non-negative safe integers no greater than Number.MAX_SAFE_INTEGER; fractional, negative, and unsafe values throw. 0 is valid.

See: Predict

Retains the fitted model’s training data, enabling result.predict(newX, options) at out-of-sample query points. false (default) — no extra memory/copy cost unless requested.

See: Custom Weights

Per-observation weights, passed to fit() rather than the options object.

FieldTypeDescription
xFloat64Arrayx values (same order as input)
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 "residuals" was requested)
robustness_weightsFloat64Array | nullRobustness weights (if "weights" was requested)
cv_scoresFloat64Array | nullCV score per tested fraction
diagnosticsDiagnostics | nullFit metrics (if "diagnostics" was requested)
derivativeFloat64Array | nullPer-point local fit derivative/slope (if "derivative" was requested)
FieldTypeDescription
rmsenumberRoot Mean Squared Error
maenumberMean Absolute Error
r_squarednumberR-squared
residual_sdnumberRobust residual scale estimate (1.4826 * MAD)
effective_dfnumber | nullEffective degrees of freedom
aicnumber | nullAIC
aiccnumber | nullAICc
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 ]