OnlineLowess API

For real-time data: processes one (x, y) point at a time and returns a smoothed value immediately once enough points have been seen.

See also: API

When to Use

  • Data arrives incrementally (sensors, streams)

  • Need real-time smoothed values

  • Fixed memory budget

Online Adapter

Class

OnlineLowess

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

Constructor:

OnlineOptions options = OnlineOptions.builder()
        .windowCapacity(200)
        .minPoints(10)
        .build();

try (OnlineLowess model = new OnlineLowess(options)) {
    // ...
}
  • new OnlineLowess(OnlineOptions options) creates a new online model with the given options.

  • options: An OnlineOptions instance (exposes all Options settings plus windowCapacity, minPoints, and updateMode).

Methods:

addPoint(double x, double y) AddPointResult

Adds a single point to the sliding window. Returns an AddPointResult whose status() is FILLING while fewer than minPoints finite observations have been accepted, READY once smoothing begins (point() holds the PointResult), or DROPPED when missing = "drop" ignores a non-finite input. Once the window reaches windowCapacity, each new point evicts the oldest one, so memory stays bounded regardless of how much history has passed through. updateMode 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.

AddPointResult result = model.addPoint(x, y);
result.point().ifPresent(r -> System.out.println(r.y()));
  • OnlineLowess.close() releases native resources. Safe to call multiple times. Implements AutoCloseable.

Options Structure

OnlineOptions

Setting Type Default Description

fraction

double

0.67

Smoothing fraction (bandwidth)

iterations

int

0

Number of robustifying iterations (requires updateMode("full"))

weightFunction

String

"tricube"

Weight function name

robustnessMethod

String

"bisquare"

Robustness method name

delta

double

NaN

Interpolation distance (NaN disables interpolation); positive values require updateMode("full")

zeroWeightFallback

String

"use_local_mean"

Zero-weight handling

boundaryPolicy

String

"extend"

Boundary handling policy

scalingMethod

String

"mad"

Residual scaling method

autoConverge

double

NaN

Auto-convergence tolerance; requires updateMode("full") and iterations > 0

missing

String

"error"

Policy for non-finite (NaN/Infinity) values in each point

windowCapacity

int

1000

Maximum number of recent points retained

minPoints

int

2

Minimum points required before output starts

updateMode

String

"incremental"

How the window is updated as new points arrive: incremental, full

outputs(String…​)

String…​

empty

Select se, weights, and/or derivative; se requires updateMode("full")

intervals(IntervalsOptions)

IntervalsOptions

disabled

Confidence/prediction levels and per-window bootstrap refits (updateMode("full") only)

seed(long)

long

unset

Reproducible bootstrap draws for each full-update window

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

Cross-validation, GPU backend, customWeights, the sorted output, and parallel are Batch-only; the diagnostics and residuals outputs are unavailable online. See API for those options.

Options

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

iterations controls robustness to outliers, at the cost of speed. Requires updateMode("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

weightFunction

  • "tricube" (default)

  • "epanechnikov"

  • "gaussian"

  • "uniform" (alias: "boxcar")

  • "biweight" (alias: "bisquare")

  • "triangle" (alias: "triangular")

  • "cosine"

robustnessMethod

See: Robustness

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

  • "huber"

  • "talwar"

delta

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.

zeroWeightFallback

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

boundaryPolicy

  • "extend" (default; alias: "pad")

  • "reflect" (alias: "mirror")

  • "zero"

  • "noboundary" (alias: "none")

scalingMethod

  • "mad" (default; alias: "median_absolute_deviation")

  • "mar" (alias: "median_absolute_residual")

  • "mean" (alias: "mean_absolute_residual")

autoConverge

See: Robustness

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

missing

Policy for handling a non-finite (NaN/Infinity) x or y value passed to addPoint:

Option Behavior

"error" (default)

Throw

"drop"

Silently ignore the point — addPoint returns status DROPPED instead of adding it to the window

windowCapacity

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

minPoints

Minimum number of points required before smoothing starts. addPoint returns status FILLING until the window reaches this size.

updateMode

Mode Alias Behavior

Speed

"incremental" (default)

"single"

Update only affected fits

Faster

"full"

"resmooth"

Recompute entire window

More accurate

outputs: weights

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

outputs: derivative

Each point’s local WLS fit already computes a slope internally; this exposes the latest point’s slope (rate of change of the smoothed curve) via PointResult.derivative() at effectively no extra computation cost.

intervals

See: Intervals

Build with IntervalsOptions.builder(). Requires updateMode("full"); incremental mode throws at construction. confidence(level) and prediction(level) add bounds for the latest point; bootstrap(n) (at least 2) refits each sliding window from resampled residuals.

seed

Seeds bootstrap draws. Each full-update window restarts from the same seed. It does not enable bootstrap by itself; 0 is valid.

Result Structure

PointResult

Returned in AddPointResult.point() once the window has enough points (status is FILLING or DROPPED otherwise).

Accessor Type Notes

y()

double

Smoothed value for the latest point.

standardError()

OptionalDouble

"se" output or any interval (requires updateMode("full")).

confidenceLower(), confidenceUpper()

OptionalDouble

intervals confidence set.

predictionLower(), predictionUpper()

OptionalDouble

intervals prediction set.

residual()

OptionalDouble

Residual y minus smoothed; always populated (there is no "residuals" output for Online).

robustnessWeight()

OptionalDouble

Robustness weight, if "weights" was requested.

iterationsUsed()

OptionalInt

Robustness iterations performed.

derivative()

OptionalDouble

Local fit derivative/slope for the latest point, if "derivative" was requested.

There is no diagnostics accessor or "diagnostics" output for OnlineLowess: PointResult carries no diagnostics field, since diagnostics like RMSE/R2 need more than one point’s worth of history to be meaningful.

Example

import fastlowess.AddPointResult;
import fastlowess.OnlineLowess;
import fastlowess.OnlineOptions;

public class Example {
    public static void main(String[] args) {
        final int n = 100;
        double[] x = new double[n];
        double[] y = new double[n];
        for (int i = 0; i < n; i++) {
            x[i] = i * 2 * Math.PI / (n - 1);
            y[i] = Math.sin(x[i]) + 0.1;
        }

        OnlineOptions options = OnlineOptions.builder()
                .fraction(0.5)
                .windowCapacity(50)
                .minPoints(3)
                .build();

        try (OnlineLowess model = new OnlineLowess(options)) {
            AddPointResult r1 = model.addPoint(x[0], y[0]);
            System.out.println(r1.isReady());

            AddPointResult r2 = model.addPoint(x[1], y[1]);
            System.out.println(r2.isReady());

            AddPointResult r3 = model.addPoint(x[2], y[2]);
            r3.point().ifPresent(r -> System.out.println(r.y()));
        }
    }
}
false
false
0.22659245357374927