Skip to content

StreamingLowess API

See also: fastLowess

  • Dataset >100,000 points
  • Memory-constrained environments
  • Batch processing pipelines

The StreamingLowess class processes data in chunks, suitable for very large datasets or streaming applications.

Constructor:

const { StreamingLowess } = require('fastlowess-wasm');
const stream = new StreamingLowess({ fraction: 0.5 }, { chunk_size: 50, overlap: 10 });
console.log("typeof process_chunk:", typeof stream.process_chunk);
typeof process_chunk: function
  • options: An object containing LowessOptions fields.
  • streamingOptions: An object containing StreamingOptions fields.

Methods:

const { StreamingLowess } = require('fastlowess-wasm');
const n = 100;
const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));
const y = Float64Array.from(x, xi => Math.sin(xi) + 0.1);
const stream = new StreamingLowess({ fraction: 0.5 }, { chunk_size: 50, overlap: 10 });
const partialResult = stream.process_chunk(x.slice(0, 50), y.slice(0, 50));
console.log("Fraction used:", partialResult.fraction_used);
Fraction used: 0.5
  • Processes a chunk of data. Returns partial results.
const { StreamingLowess } = require('fastlowess-wasm');
const n = 100;
const x = Float64Array.from({ length: n }, (_, i) => i * 2 * Math.PI / (n - 1));
const y = Float64Array.from(x, xi => Math.sin(xi) + 0.1);
const stream = new StreamingLowess({ fraction: 0.5 }, { chunk_size: 50, overlap: 10 });
stream.process_chunk(x.slice(0, 50), y.slice(0, 50));
stream.process_chunk(x.slice(50), y.slice(50));
const finalResult = stream.finalize();
console.log("Fraction used:", finalResult.fraction_used);
Fraction used: 0.5
  • Finalizes the smoothing process and returns any remaining buffered results.

Returned by process_chunk() and finalize().

FieldTypeDescription
xFloat64ArraySorted x values
yFloat64ArraySmoothed y values
fraction_usednumberFraction used
iterations_usednumber | undefinedRobustness iterations actually performed
residualsFloat64Array | undefinedResiduals (if return_residuals)
robustness_weightsFloat64Array | undefinedRobustness weights (if return_robustness_weights)
diagnosticsDiagnostics | undefinedFit metrics (if return_diagnostics)
dimensionsnumberNumber of predictor dimensions

See wasm.md for the full LowessResult field reference.

FieldTypeDefaultDescription
chunk_sizenumber5000Data chunk size
overlapnumber500Overlap between chunks
merge_strategystring"weighted_average"Strategy for blending overlap regions

See: Merge Strategies

StrategyAliasBehavior
"weighted_average" (default)"weighted"Distance-weighted blend
"average""mean"Average overlapping values
"take_first""first"Keep left chunk values
"take_last""last"Keep right chunk values

Merge Strategies