Online Adapter

Incremental updates with a sliding window for real-time data.

See also: Batch Adapter

When to Use

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

Online Adapter

Class

OnlineLowess

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

Constructor:

using FastLOWESS

model = OnlineLowess(; fraction=0.2, window_capacity=100, min_points=5)
println(typeof(model))
OnlineLowess

Methods:

add_point(model, x, y)

Adds a single point to the sliding window and returns the smoothed value for that point, or nothing 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.

using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

shown = 0
for i in eachindex(x)
    global shown
    result = add_point(model, x[i], y[i])
    if result !== nothing && shown < 5
        println("Current smoothed value: ", result.y)
        shown += 1
    end
end
Current smoothed value: 0.23103531694201596
Current smoothed value: 0.4962273769575686
Current smoothed value: 0.6767458589597115
Current smoothed value: 0.41363571386216635
Current smoothed value: 0.31508056492212055

Options Structure

OnlineLowess keyword arguments (mirrors Lowess)

FieldTypeDefaultDescription
fractionFloat640.67Smoothing fraction (bandwidth)
iterationsInt0Number of robustifying iterations (requires update_mode = "full")
weight_functionString"tricube"Weight function name
robustness_methodString"bisquare"Robustness method name
deltaFloat64NaNInterpolation 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_convergeFloat64NaNAuto-convergence tolerance; requires update_mode = "full" and iterations > 0
missingString"error"Policy for non-finite (NaN/Inf) values in each point
window_capacityInt1000Max points in sliding window
min_pointsInt2Min points before smoothing starts
update_modeString"incremental"Update mode ("full" or "incremental")
outputsVector{String}String[]Select se, weights, and/or derivative; se requires update_mode="full"
intervalsNamedTuplenothingGrouped confidence, prediction, and per-window bootstrap options (requires update_mode="full")
seedUnion{Integer, Nothing}nothingReproducible bootstrap draws for each full-update window

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 (or Batch/Streaming-only) and not available here; see Batch Adapter for those.

Options

fraction

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

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

weight_function

See: Weight Functions

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

robustness_method

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:

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

boundary_policy

See: Boundary Handling

  • "extend" (default; alias: "pad")
  • "reflect" (alias: "mirror")
  • "zero"
  • "noboundary" (alias: "none")

scaling_method

See: Scaling Methods

  • "mad" (default; alias: "median_absolute_deviation")
  • "mar" (alias: "median_absolute_residual")
  • "mean" (alias: "mean_absolute_residual")

auto_converge

See: Robustness

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

missing

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

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

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

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

update_mode

See: Execution Modes

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

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" errors at construction time.

outputs: weights

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) in result.derivative at effectively no extra computation cost.

intervals

See: Intervals

A NamedTuple 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.

seed

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

Result Structure

OnlineOutput

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

FieldTypeDescription
yFloat64Smoothed value for the latest point
standard_errorUnion{Float64, Nothing}Populated when "se" or any interval is set (requires update_mode="full"); otherwise always nothing
confidence_lower / confidence_upperUnion{Float64, Nothing}Confidence interval bounds around the mean response, if intervals.confidence was set (requires update_mode="full")
prediction_lower / prediction_upperUnion{Float64, Nothing}Prediction interval bounds for a new observation, if intervals.prediction was set (requires update_mode="full")
residualUnion{Float64, Nothing}Residual y − smoothed; always present (there is no "residuals" output for Online)
robustness_weightUnion{Float64, Nothing}Robustness weight, if "weights" was requested
iterations_usedUnion{Int, Nothing}Robustness iterations performed
derivativeUnion{Float64, Nothing}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.

Example

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = OnlineLowess(;
    fraction=0.2,
    window_capacity=100,
    min_points=5,
    update_mode="incremental"
)
shown = 0
for i in eachindex(x)
    global shown
    result = add_point(model, x[i], y[i])
    if result !== nothing && shown < 5
        println("Current smoothed value: ", result.y)
        shown += 1
    end
end
Current smoothed value: 0.23103531694201596
Current smoothed value: 0.4962273769575686
Current smoothed value: 0.6767458589597115
Current smoothed value: 0.41363571386216635
Current smoothed value: 0.31508056492212055