Execution Modes
Choose the right adapter for your use case.
Overview
Section titled “Overview”Choose the first row below whose condition applies:
| Condition | Adapter |
|---|---|
| Data too large to fit in memory | Streaming |
| Fits in memory, need real-time/incremental updates | Online |
| Fits in memory, no real-time requirement | Batch |
| 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
Section titled “Batch Adapter”Standard mode for complete datasets. Supports all features.
When to Use
Section titled “When to Use”- Dataset fits in memory
- Need intervals, cross-validation, or diagnostics
- Processing complete files
Example
Section titled “Example”const { Lowess } = require('fastlowess');
const x = Float64Array.from({ length: 100 }, (_, i) => i * 2 * Math.PI / 99);const y = Float64Array.from(x, xi => Math.sin(xi) + 0.1);
const model = new Lowess({ fraction: 0.5, iterations: 3, parallel: true, outputs: ["diagnostics"], intervals: { confidence: 0.95, prediction: 0.95 }});const result = model.fit(x, y);console.log(`95% CI at midpoint: [${result.confidence_lower[50].toFixed(4)}, ${result.confidence_upper[50].toFixed(4)}]`);console.log(`R2: ${result.diagnostics.r_squared.toFixed(4)}`);95% CI at midpoint: [0.0433, 0.1038]R2: 0.9668Streaming Adapter
Section titled “Streaming Adapter”Process large datasets in chunks with configurable overlap.
When to Use
Section titled “When to Use”- Dataset >100,000 points
- Memory-constrained environments
- Batch processing pipelines
Parameters
Section titled “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
Section titled “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
Section titled “Example”const { StreamingLowess } = require('fastlowess');
const x = Float64Array.from({ length: 100 }, (_, i) => i * 2 * Math.PI / 99);const y = Float64Array.from(x, xi => Math.sin(xi) + 0.1);
const stream = new StreamingLowess( { fraction: 0.3, iterations: 2 }, { chunk_size: 5000, overlap: 500, merge_strategy: "average" });stream.process_chunk(x, y);const result = stream.finalize();console.log(`Smoothed y[0]: ${result.y[0].toFixed(4)}`);Smoothed y[0]: 0.2578Online Adapter
Section titled “Online Adapter”Incremental updates with a sliding window for real-time data.
When to Use
Section titled “When to Use”- Data arrives incrementally (sensors, streams)
- Need real-time smoothed values
- Fixed memory budget
Parameters
Section titled “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
Section titled “Update Modes”| Mode | Behavior | Speed |
|---|---|---|
"incremental" | Update only affected fits | Faster |
"full" | Recompute entire window | More accurate |
Example
Section titled “Example”const { OnlineLowess } = require('fastlowess');
const x = Float64Array.from({ length: 100 }, (_, i) => i * 2 * Math.PI / 99);const y = Float64Array.from(x, xi => Math.sin(xi) + 0.1);
const online = new OnlineLowess( { fraction: 0.2 }, { window_capacity: 100, min_points: 5, update_mode: "incremental" });let shown = 0;for (let i = 0; i < x.length && shown < 5; i++) { const result = online.add_point(x[i], y[i]); if (result !== null) { console.log(result.y); shown++; }}0.35114798718107920.41203344569848710.47166245566032750.52979491208917160.5861967361004687Feature Comparison
Section titled “Feature Comparison”| Feature | Batch | Streaming | Online |
|---|---|---|---|
| Confidence intervals | ✓ | ✗ | ✗ |
| Prediction intervals | ✓ | ✗ | ✗ |
| Cross-validation | ✓ | ✗ | ✗ |
| Diagnostics | ✓ | ✓ | ✗ |
| Residuals | ✓ | ✓ | ✓ |
| Robustness weights | ✓ | ✓ | ✓ |
| Parallel execution | ✓ | ✓ | ✗ |
Next Steps
Section titled “Next Steps”- API Reference — All configuration options
- Streaming API · Online API