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 |
|
Fits in memory, need real-time/incremental updates |
|
Fits in memory, no real-time requirement |
|
| Mode | Use Case | Memory | Features |
|---|---|---|---|
Batch ( |
Complete datasets |
Full |
All features |
Streaming ( |
Large files (>100K) |
Chunked |
Residuals, robustness |
Online ( |
Real-time sensors |
Fixed window |
Incremental updates |
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.
Parameters
| Parameter | Default | Description |
|---|---|---|
|
5000 |
Points per chunk |
|
|
Overlap between chunks |
|
|
How to merge overlaps |
Merge Strategies
| Strategy | Behavior |
|---|---|
|
Average overlapping values |
|
Distance-weighted blend |
|
Keep left chunk values |
|
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 |
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 |
|---|---|---|
|
1000 |
Max points in window |
|
2 |
Points before output starts |
|
|
Update strategy |
Update Modes
| Mode | Behavior | Speed |
|---|---|---|
|
Update only affected fits |
Faster |
|
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
-
API Reference — All configuration options