Execution Modes

Choose the right adapter for your use case.

Overview

Choose the first row below whose condition applies:

Condition Adapter

Data too large to fit in memory

StreamingLowess

Fits in memory, need real-time/incremental updates

OnlineLowess

Fits in memory, no real-time requirement

Lowess

Mode Use Case Memory Features

Batch (Lowess)

Complete datasets

Full

All features

Streaming (StreamingLowess)

Large files (>100K)

Chunked

Residuals, robustness

Online (OnlineLowess)

Real-time sensors

Fixed window

Incremental updates

Adapter Comparison

Batch Adapter

Standard mode for complete datasets. Supports all features.

When to Use

  • Dataset fits in memory

  • Need intervals, cross-validation, or diagnostics

  • Processing complete files

Example

import fastlowess.IntervalsOptions;
import fastlowess.Lowess;
import fastlowess.Options;
import fastlowess.Result;

public class Example {
    public static void main(String[] args) {
        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;
        }

        Options options = Options.builder()
                .fraction(0.5)
                .iterations(3)
                .parallel(true)
                .outputs("diagnostics")
                .intervals(IntervalsOptions.builder().confidence(0.95).prediction(0.95).build())
                .build();

        try (Lowess model = new Lowess(options)) {
            Result result = model.fit(x, y);
            int mid = n / 2;
            System.out.printf("95%% CI at midpoint: [%.4f, %.4f]%n",
                    result.confidenceLower().get()[mid], result.confidenceUpper().get()[mid]);
            System.out.printf("R2: %.4f%n", result.diagnostics().get().rSquared());
        }
    }
}
95% CI at midpoint: [0.0433, 0.1038]
R2: 0.9668

Streaming Adapter

Process large datasets in chunks with configurable overlap.

When to Use

  • Dataset >100,000 points

  • Memory-constrained environments

  • Batch processing pipelines

Parameters

Parameter Default Description

chunk_size

5000

Points per chunk

overlap

chunk_size / 10

Overlap between chunks

merge_strategy

"weighted_average"

How to merge overlaps

Merge Strategies

Strategy Behavior

"average"

Average overlapping values

"weighted_average"

Distance-weighted blend

"take_first"

Keep left chunk values

"take_last"

Keep right chunk values

Example

import fastlowess.Result;
import fastlowess.StreamingLowess;
import fastlowess.StreamingOptions;

public class Example {
    public static void main(String[] args) {
        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;
        }

        StreamingOptions options = StreamingOptions.builder()
                .fraction(0.3)
                .iterations(2)
                .chunkSize(5000)
                .overlap(500)
                .mergeStrategy("average")
                .build();

        try (StreamingLowess model = new StreamingLowess(options)) {
            model.processChunk(x, y);
            Result result = model.finish();
            System.out.printf("Smoothed y[0]: %.4f%n", result.y()[0]);
        }
    }
}
Smoothed y[0]: 0.2578

Always call finish()

Always call model.finish() after processing all chunks to retrieve buffered overlap data.

Online Adapter

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

When to Use

  • Data arrives incrementally (sensors, streams)

  • Need real-time smoothed values

  • Fixed memory budget

Parameters

Parameter Default Description

window_capacity

1000

Max points in window

min_points

2

Points before output starts

update_mode

"incremental"

Update strategy

Update Modes

Mode Behavior Speed

"incremental"

Update only affected fits

Faster

"full"

Recompute entire window

More accurate

Example

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

public class Example {
    public static void main(String[] args) {
        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.2)
                .windowCapacity(100)
                .minPoints(5)
                .updateMode("incremental")
                .build();

        try (OnlineLowess model = new OnlineLowess(options)) {
            int shown = 0;
            for (int i = 0; i < n && shown < 5; i++) {
                AddPointResult result = model.addPoint(x[i], y[i]);
                if (result.isReady()) {
                    System.out.println(result.point().orElseThrow().y());
                    shown++;
                }
            }
        }
    }
}
0.3511479871810792
0.4120334456984871
0.4716624556603275
0.5297949120891716
0.5861967361004687

Feature Comparison

Feature Batch Streaming Online

Confidence intervals

✓

✗

✗

Prediction intervals

✓

✗

✗

Cross-validation

✓

✗

✗

Diagnostics

✓

✓

✗

Residuals

✓

✓

✓

Robustness weights

✓

✓

✓

Parallel execution

✓

✓

✗


Next Steps