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 type updates the model incrementally with new data points.
Constructor:
opts := fastlowess.DefaultOnlineOptions()
opts.WindowCapacity = 200
opts.MinPoints = 10
model, err := fastlowess.NewOnlineLowess(opts)
if err != nil {
panic(err)
}
defer model.Close()fastlowess.NewOnlineLowess(opts OnlineOptions) (*OnlineLowess, error)creates a new online model with the given options.opts: AnOnlineOptionsstruct.
Methods:
AddPoint(x, y float64) (res PointResult, status AddPointStatus, err error)
Adds a single point to the sliding window and returns the smoothed value for that point. status is AddPointFilling while the window is warming up (fewer than MinPoints finite observations), AddPointReady once smoothing begins (res is valid), and AddPointDropped when Missing = "drop" ignores a non-finite point. 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.
res, status, err := model.AddPoint(x, y)
if err != nil {
panic(err)
}
if status.Ready() {
fmt.Println(res.Y)
}(*OnlineLowess) Close() errorreleases native resources. Safe to call multiple times.
Options Structure
OnlineOptions
| Field | Type | Default | Description |
|---|---|---|---|
Fraction | float64 | 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 | *float64 | nil | Interpolation distance (nil 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 | *float64 | nil | Auto-convergence tolerance; requires UpdateMode = "full" and Iterations > 0 |
Missing | string | "error" | Policy for non-finite (NaN/Inf) 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 |
Outputs | []string | nil | Optional components: se, weights, derivative (se requires UpdateMode = "full"). |
Intervals | *IntervalsOptions | nil | Confidence/prediction levels and per-window bootstrap refits (UpdateMode = "full" only) |
Seed | *uint64 | nil | 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"
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. nil (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
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. nil (default) disables early stopping.
Missing
Policy for handling a non-finite (NaN/Inf) x or y value passed to AddPoint:
| Option | Behavior |
|---|---|
"error" (default) | Return an error |
"drop" | Ignore the point — AddPoint returns AddPointDropped 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 AddPointFilling until the window reaches this size.
UpdateMode
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 StandardError; it requires UpdateMode = "full". The fast "incremental" path never computes standard errors, so selecting "se" or Intervals with another mode returns an error from NewOnlineLowess.
Outputs: weights
Select "weights" to include the robustness weight for the latest point (from the last robustness iteration) in the result.
Outputs: derivative
Select "derivative" to expose the latest point’s local WLS slope in PointResult.Derivative at effectively no extra computation cost.
Intervals
See: Intervals
Set Intervals.Confidence and/or Intervals.Prediction to a level such as 0.95, or leave either nil to disable it. Intervals.Bootstrap (at least 2) refits the current full-update window for percentile bounds and standard errors. Set Seed for reproducible draws. All intervals require UpdateMode = "full".
Result Structure
PointResult
Returned by AddPoint once the window has enough points (AddPointFilling until then).
| Field | Type | Notes |
|---|---|---|
Y | float64 | Smoothed value for the latest point. |
StandardError | float64 | Populated when "se" or any interval is set (requires UpdateMode = "full"); NaN otherwise. |
ConfidenceLower / ConfidenceUpper | float64 | Bounds around the mean response if Intervals.Confidence was set (full mode only); NaN otherwise. |
PredictionLower / PredictionUpper | float64 | Bounds for a new observation if Intervals.Prediction was set (full mode only); NaN otherwise. |
Residual | float64 | Residual y − smoothed; always populated (there is no "residuals" output for Online). |
RobustnessWeight | float64 | Robustness weight, if "weights" was requested. |
IterationsUsed | int | Robustness iterations performed (-1 if not applicable). |
Derivative | float64 | Local fit derivative/slope for the latest point, if "derivative" was requested (NaN otherwise). |
There is no diagnostics structure or "diagnostics" output for OnlineLowess: PointResult carries no diagnostics field, since diagnostics like RMSE/R² need more than one point’s worth of history to be meaningful.
Example
package main
import (
"fmt"
"log"
"math"
"github.com/thisisamirv/lowess-project/bindings/go/fastlowess/v5"
)
func main() {
const n = 100
x := make([]float64, n)
y := make([]float64, n)
for i := 0; i < n; i++ {
x[i] = float64(i) * 2 * math.Pi / float64(n-1)
y[i] = math.Sin(x[i]) + 0.1
}
opts := fastlowess.DefaultOnlineOptions()
opts.Fraction = 0.5
opts.WindowCapacity = 50
opts.MinPoints = 3
model, err := fastlowess.NewOnlineLowess(opts)
if err != nil {
log.Fatal(err)
}
defer model.Close()
_, status1, err := model.AddPoint(x[0], y[0])
if err != nil {
log.Fatal(err)
}
fmt.Println(status1.Ready())
_, status2, err := model.AddPoint(x[1], y[1])
if err != nil {
log.Fatal(err)
}
fmt.Println(status2.Ready())
res, status3, err := model.AddPoint(x[2], y[2])
if err != nil {
log.Fatal(err)
}
if status3.Ready() {
fmt.Println(res.Y)
}
}false
false
0.22659245357374927