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
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: AnOnlineOptionsinstance (exposes allOptionssettings pluswindowCapacity,minPoints, andupdateMode).
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. ImplementsAutoCloseable.
Options Structure
OnlineOptions
| Setting | Type | Default | Description |
|---|---|---|---|
|
|
|
Smoothing fraction (bandwidth) |
|
|
|
Number of robustifying iterations (requires |
|
|
|
Weight function name |
|
|
|
Robustness method name |
|
|
|
Interpolation distance ( |
|
|
|
Zero-weight handling |
|
|
|
Boundary handling policy |
|
|
|
Residual scaling method |
|
|
|
Auto-convergence tolerance; requires |
|
|
|
Policy for non-finite (NaN/Infinity) values in each point |
|
|
|
Maximum number of recent points retained |
|
|
|
Minimum points required before output starts |
|
|
|
How the window is updated as new points arrive: |
|
|
empty |
Select |
|
|
disabled |
Confidence/prediction levels and per-window bootstrap refits ( |
|
|
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
See: Weight Functions
-
"tricube"(default) -
"epanechnikov" -
"gaussian" -
"uniform"(alias:"boxcar") -
"biweight"(alias:"bisquare") -
"triangle"(alias:"triangular") -
"cosine"
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 the mean of the neighborhood |
|
Return the original y value |
|
Return |
boundaryPolicy
See: Boundary Handling
-
"extend"(default; alias:"pad") -
"reflect"(alias:"mirror") -
"zero" -
"noboundary"(alias:"none")
scalingMethod
See: Scaling Methods
-
"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 |
|---|---|
|
Throw |
|
Silently ignore the point — |
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
See: Execution Modes
| Mode | Alias | Behavior |
|---|---|---|
Speed |
|
|
Update only affected fits |
Faster |
|
|
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.
Result Structure
PointResult
Returned in AddPointResult.point() once the window has enough points (status is FILLING or DROPPED otherwise).
| Accessor | Type | Notes |
|---|---|---|
|
|
Smoothed value for the latest point. |
|
|
|
|
|
|
|
|
|
|
|
Residual y minus smoothed; always populated (there is no |
|
|
Robustness weight, if |
|
|
Robustness iterations performed. |
|
|
Local fit derivative/slope for the latest point, if |
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