Skip to content

OnlineLowess API

See also: fastLowess

  • Data arrives incrementally (sensors, streams)
  • Need real-time smoothed values
  • Fixed memory budget

Online Adapter

The OnlineLowess class updates the model incrementally with new data points.

Constructor:

const { OnlineLowess } = require('fastlowess');
const online = new OnlineLowess({ fraction: 0.5 }, { window_capacity: 50, min_points: 3 });
// Feed enough points to pass min_points threshold
for (let i = 0; i < 4; i++) {
const result = online.add_point(i, Math.sin(i * 0.5));
if (result !== null) console.log("Online smoothed at x=" + i + ":", result.y.toFixed(4));
}
Online smoothed at x=2: 0.8415
Online smoothed at x=3: 0.9975
  • options: An object containing OnlineSmoothOptions fields (a subset of the Batch LowessOptions fields — see below).
  • onlineOptions: An object containing OnlineOptions fields.

Adds a single point to the sliding window and returns the smoothed value for that point, or null while the window is still filling up (fewer than min_points seen so far). Once the window reaches window_capacity, each new point evicts the oldest one, so memory stays bounded regardless of how much history has passed through. update_mode controls how much work each call does: "incremental" re-fits only the newest point, while "full" re-smooths the entire window for a more accurate but slower result.

const { OnlineLowess } = 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 online = new OnlineLowess({ fraction: 0.5 }, { window_capacity: 50, min_points: 3 });
// Returns null until min_points (3) are reached
online.add_point(x[0], y[0]); // null
online.add_point(x[1], y[1]); // null
// Returns OnlineOutput once enough points are available
const result = online.add_point(x[2], y[2]);
console.log("Smoothed y:", result.y);
Smoothed y: 0.22659245357374927
FieldTypeDefaultDescription
fractionnumber0.67Smoothing fraction (bandwidth)
iterationsnumber0Number of robustifying iterations (requires update_mode = "full")
weight_functionstring"tricube"Weight function name
robustness_methodstring"bisquare"Robustness method name
deltanumberNaNInterpolation distance (NaN disables interpolation); positive values require update_mode = "full"
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; requires update_mode = "full" and iterations > 0
missingstring"error"Policy for non-finite (NaN/Inf) values in each point
window_capacitynumber1000Max points in sliding window
min_pointsnumber2Min points before smoothing starts
update_modestring"incremental"Update mode ("full" or "incremental")
outputsstring[][]Select se, weights, and/or derivative; se requires update_mode: "full"
intervalsobjectnullGrouped confidence, prediction, and per-window bootstrap options (requires update_mode: "full")
seednumbernullReproducible bootstrap draws for each full-update window; must be an integer from 0 through Number.MAX_SAFE_INTEGER

Incremental mode fits only the newest point. Positive delta is rejected there, and auto_converge requires full mode with at least one robustness iteration.

Cross-validation, GPU backend, custom_weights, the "sorted" output, and parallel are Batch-only; the "diagnostics" and "residuals" outputs are not available online. See fastLowess for those options.

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. Requires update_mode = "full"; the default "incremental" mode performs a non-robust single-point fit.

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 0 in Online mode, i.e. interpolation is disabled and every point is fit 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 a non-finite (NaN/Inf) x or y value passed to add_point:

OptionBehavior
"error" (default)Throw an error
"drop"Silently ignore the point — add_point returns null instead of adding it to the window

Maximum number of most recent points kept in the sliding window; older points are discarded as new ones arrive. Each add_point() call costs O(window_capacity) rather than growing with total history.

Minimum number of points required before smoothing starts. add_point() returns null until the window reaches this size.

See: Execution Modes

ModeAliasBehaviorSpeed
"incremental" (default)"single"Update only affected fitsFaster
"full""resmooth"Recompute entire windowMore accurate

See: Intervals

Select "se" to populate standard_error; it requires update_mode: "full". The fast "incremental" path never computes standard errors, so selecting "se" (or setting intervals) with anything other than "full" throws at construction time.

Select "weights" to include the robustness weight for the latest point (from the last robustness iteration) in the result.

Select "derivative" to expose the latest point’s local WLS slope in OnlineOutput.derivative at effectively no extra computation cost.

See: Intervals

An object such as { confidence: 0.90, prediction: 0.99, bootstrap: 200 }, populating confidence_lower/confidence_upper and prediction_lower/prediction_upper for the latest point. The coverage levels are independent. Same update_mode: "full" requirement as the "se" output. bootstrap (at least 2) refits each sliding window from resampled residuals.

Seeds bootstrap draws. Each full-update window restarts from the same seed. It does not enable bootstrap by itself. Seeds must be finite, non-negative safe integers no greater than Number.MAX_SAFE_INTEGER; fractional, negative, and unsafe values throw. 0 is valid.

Returned by add_point() once the window has enough points (null until then).

FieldTypeDescription
ynumberSmoothed value for the latest point
standard_errornumber | nullPopulated when "se" or any interval is set (requires update_mode: "full"); otherwise always null
confidence_lower / confidence_uppernumber | nullConfidence interval bounds around the mean response, if intervals.confidence was set (requires update_mode: "full")
prediction_lower / prediction_uppernumber | nullPrediction interval bounds for a new observation, if intervals.prediction was set (requires update_mode: "full")
residualnumber | nullResidual y − smoothed; always present (there is no "residuals" output for Online)
robustness_weightnumber | nullRobustness weight, if "weights" was requested
iterations_usednumber | nullRobustness iterations performed
derivativenumber | nullLocal fit derivative/slope for the latest point, if "derivative" was requested

There is no Diagnostics object or "diagnostics" output for OnlineLowess: OnlineOutput carries no diagnostics field, since diagnostics like RMSE/R² need more than one point’s worth of history to be meaningful.