OnlineLowess API
See also: fastLowess
When to Use
Section titled “When to Use”- Data arrives incrementally (sensors, streams)
- Need real-time smoothed values
- Fixed memory budget
OnlineLowess
Section titled “OnlineLowess”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 thresholdfor (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.8415Online smoothed at x=3: 0.9975options: An object containingOnlineSmoothOptionsfields (a subset of the BatchLowessOptionsfields — see below).onlineOptions: An object containingOnlineOptionsfields.
add_point(x, y)
Section titled “add_point(x, y)”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 reachedonline.add_point(x[0], y[0]); // nullonline.add_point(x[1], y[1]); // null
// Returns OnlineOutput once enough points are availableconst result = online.add_point(x[2], y[2]);console.log("Smoothed y:", result.y);Smoothed y: 0.22659245357374927Options Structure
Section titled “Options Structure”OnlineSmoothOptions
Section titled “OnlineSmoothOptions”| Field | Type | Default | Description |
|---|---|---|---|
fraction | number | 0.67 | Smoothing fraction (bandwidth) |
iterations | number | 0 | Number of robustifying iterations (requires update_mode = "full") |
weight_function | string | "tricube" | Weight function name |
robustness_method | string | "bisquare" | Robustness method name |
delta | number | NaN | Interpolation distance (NaN disables interpolation); positive values require update_mode = "full" |
zero_weight_fallback | string | "use_local_mean" | Zero-weight handling |
boundary_policy | string | "extend" | Boundary handling policy |
scaling_method | string | "mad" | Residual scaling method |
auto_converge | number | null | Auto-convergence tolerance; requires update_mode = "full" and iterations > 0 |
missing | string | "error" | Policy for non-finite (NaN/Inf) values in each point |
window_capacity | number | 1000 | Max points in sliding window |
min_points | number | 2 | Min points before smoothing starts |
update_mode | string | "incremental" | Update mode ("full" or "incremental") |
outputs | string[] | [] | Select se, weights, and/or derivative; se requires update_mode: "full" |
intervals | object | null | Grouped confidence, prediction, and per-window bootstrap options (requires update_mode: "full") |
seed | number | null | Reproducible 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.
Options
Section titled “Options”fraction
Section titled “fraction”fraction is the most important parameter: it controls the size of the local neighbourhood used at each point.
| Range | Effect | Use case |
|---|---|---|
| 0.1-0.3 | Fine detail | Rapidly changing signals |
| 0.3-0.5 | Balanced | General purpose |
| 0.5-0.7 | Heavy smoothing | Noisy data |
| 0.7-1.0 | Very smooth | Trend extraction |
iterations
Section titled “iterations”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.
| Value | Effect | Performance |
|---|---|---|
| 0 | No robustness | Fastest |
| 1-3 | Moderate | Recommended |
| 4-6 | Strong | Contaminated data |
| 7+ | Very strong | Heavy outliers |
weight_function
Section titled “weight_function”See: Weight Functions
"tricube"(default)"epanechnikov""gaussian""uniform"(alias:"boxcar")"biweight"(alias:"bisquare")"triangle"(alias:"triangular")"cosine"
robustness_method
Section titled “robustness_method”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.
zero_weight_fallback
Section titled “zero_weight_fallback”Behavior when all neighborhood weights are zero:
| Option | Behavior |
|---|---|
"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 |
boundary_policy
Section titled “boundary_policy”See: Boundary Handling
"extend"(default; alias:"pad")"reflect"(alias:"mirror")"zero""noboundary"(alias:"none")
scaling_method
Section titled “scaling_method”See: Scaling Methods
"mad"(default; alias:"median_absolute_deviation")"mar"(alias:"median_absolute_residual")"mean"(alias:"mean_absolute_residual")
auto_converge
Section titled “auto_converge”See: Robustness
Convergence tolerance for early stopping of robustness iterations. null (default) disables early stopping.
missing
Section titled “missing”Policy for handling a non-finite (NaN/Inf) x or y value passed to add_point:
| Option | Behavior |
|---|---|
"error" (default) | Throw an error |
"drop" | Silently ignore the point — add_point returns null instead of adding it to the window |
window_capacity
Section titled “window_capacity”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.
min_points
Section titled “min_points”Minimum number of points required before smoothing starts. add_point() returns null until the window reaches this size.
update_mode
Section titled “update_mode”See: Execution Modes
| Mode | Alias | Behavior | Speed |
|---|---|---|---|
"incremental" (default) | "single" | Update only affected fits | Faster |
"full" | "resmooth" | Recompute entire window | More accurate |
outputs: se
Section titled “outputs: se”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.
outputs: weights
Section titled “outputs: weights”Select "weights" to include the robustness weight for the latest point (from the last robustness iteration) in the result.
outputs: derivative
Section titled “outputs: derivative”Select "derivative" to expose the latest point’s local WLS slope in OnlineOutput.derivative at effectively no extra computation cost.
intervals
Section titled “intervals”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.
Result Structure
Section titled “Result Structure”OnlineOutput
Section titled “OnlineOutput”Returned by add_point() once the window has enough points (null until then).
| Field | Type | Description |
|---|---|---|
y | number | Smoothed value for the latest point |
standard_error | number | null | Populated when "se" or any interval is set (requires update_mode: "full"); otherwise always null |
confidence_lower / confidence_upper | number | null | Confidence interval bounds around the mean response, if intervals.confidence was set (requires update_mode: "full") |
prediction_lower / prediction_upper | number | null | Prediction interval bounds for a new observation, if intervals.prediction was set (requires update_mode: "full") |
residual | number | null | Residual y − smoothed; always present (there is no "residuals" output for Online) |
robustness_weight | number | null | Robustness weight, if "weights" was requested |
iterations_used | number | null | Robustness iterations performed |
derivative | number | null | Local 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.