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
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- Keyword arguments configure the
OnlineLowessmodel; see Options Structure below.
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
endCurrent smoothed value: 0.23103531694201596
Current smoothed value: 0.4962273769575686
Current smoothed value: 0.6767458589597115
Current smoothed value: 0.41363571386216635
Current smoothed value: 0.31508056492212055Options Structure
OnlineLowess keyword arguments (mirrors Lowess)
| Field | Type | Default | Description |
|---|---|---|---|
fraction | Float64 | 0.67 | Smoothing fraction (bandwidth) |
iterations | Int | 0 | Number of robustifying iterations (requires update_mode = "full") |
weight_function | String | "tricube" | Weight function name |
robustness_method | String | "bisquare" | Robustness method name |
delta | Float64 | 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 | Float64 | NaN | 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 | Int | 1000 | Max points in sliding window |
min_points | Int | 2 | Min points before smoothing starts |
update_mode | String | "incremental" | Update mode ("full" or "incremental") |
outputs | Vector{String} | String[] | Select se, weights, and/or derivative; se requires update_mode="full" |
intervals | NamedTuple | nothing | Grouped confidence, prediction, and per-window bootstrap options (requires update_mode="full") |
seed | Union{Integer, Nothing} | nothing | Reproducible 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.
| 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 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
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:
| 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
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:
| Option | Behavior |
|---|---|
"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
| Mode | Alias | Behavior | Speed |
|---|---|---|---|
"incremental" (default) | "single" | Update only affected fits | Faster |
"full" | "resmooth" | Recompute entire window | More 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).
| Field | Type | Description |
|---|---|---|
y | Float64 | Smoothed value for the latest point |
standard_error | Union{Float64, Nothing} | Populated when "se" or any interval is set (requires update_mode="full"); otherwise always nothing |
confidence_lower / confidence_upper | Union{Float64, Nothing} | Confidence interval bounds around the mean response, if intervals.confidence was set (requires update_mode="full") |
prediction_lower / prediction_upper | Union{Float64, Nothing} | Prediction interval bounds for a new observation, if intervals.prediction was set (requires update_mode="full") |
residual | Union{Float64, Nothing} | Residual y − smoothed; always present (there is no "residuals" output for Online) |
robustness_weight | Union{Float64, Nothing} | Robustness weight, if "weights" was requested |
iterations_used | Union{Int, Nothing} | Robustness iterations performed |
derivative | Union{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
endCurrent smoothed value: 0.23103531694201596
Current smoothed value: 0.4962273769575686
Current smoothed value: 0.6767458589597115
Current smoothed value: 0.41363571386216635
Current smoothed value: 0.31508056492212055