Choosing an Execution Mode

rfastloess provides three execution modes for different data sizes and processing needs:

Execution mode comparison
Execution mode comparison
Mode Class Use Case Memory Key Features
Batch Loess Full dataset Entire dataset CI, PI, CV
Streaming StreamingLoess >100K points Per chunk With overlap
Online OnlineLoess Live / real-time Sliding window Per-point

Quick Decision Guide

Situation Mode
Data fits in memory; needs intervals or CV Batch
Data too large for memory or arrives in chunks Streaming
Data arrives point-by-point in real time Online

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

library(rfastloess)

x <- seq(0, 2 * pi, length.out = 100)
y <- sin(x) + rnorm(100, sd = 0.3)

model <- Loess(
    fraction = 0.5,
    iterations = 3,
    parallel = TRUE,
    outputs = "diagnostics",
    intervals = intervals_opts(confidence = 0.95, prediction = 0.95)
)
result <- fit(model, x, y)
cat("95% CI at midpoint: [", result$confidence_lower[50], ", ",
    result$confidence_upper[50], "]\n")
#> 95% CI at midpoint: [ -0.01020224 ,  0.2409727 ]
cat("R2:", result$diagnostics$r_squared, "\n")
#> R2: 0.7848951

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 500 Overlap between chunks
merge_strategy "weighted_average" How to merge overlaps

Merge Strategies

Strategy Behavior
"average" Average overlapping values
"weighted_average" Distance-weighted blend (default)
"take_first" Keep left chunk values
"take_last" Keep right chunk values
Merge Strategies
Merge Strategies

Example

library(rfastloess)

x <- seq(0, 2 * pi, length.out = 100)
y <- sin(x) + rnorm(100, sd = 0.3)

model <- StreamingLoess(
    fraction = 0.3,
    iterations = 2,
    chunk_size = 5000,
    overlap = 500,
    merge_strategy = "average"
)
process_chunk(model, x, y)
#> <LoessResult>
#>   Points:            0 
#>   Fraction Used:     0.3 
#>   Iterations Used:   2
result <- finalize(model)
cat("Smoothed y[0]:", result$y[1], "\n")
#> Smoothed y[0]: 0.07117552

Always call finalize(): The streaming adapter buffers overlap data. Call finalize(model) after processing all chunks to retrieve the buffered tail.

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
Online Adapter
Online Adapter

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

library(rfastloess)

x <- seq(0, 2 * pi, length.out = 100)
y <- sin(x) + rnorm(100, sd = 0.3)

model <- OnlineLoess(
    fraction = 0.2,
    window_capacity = 100,
    min_points = 5,
    update_mode = "incremental"
)
shown <- 0
for (i in seq_along(x)) {
    result <- add_point(model, x[i], y[i])
    if (!is.null(result) && shown < 5) {
        cat(result$y, "\n")
        shown <- shown + 1
    }
}
#> 0.2240037 
#> 0.6589422 
#> 0.8440962 
#> 0.5805868 
#> 0.7859969

Feature Comparison

Feature Batch Streaming Online
Confidence intervals ✓ ✗ ✗
Prediction intervals ✓ ✗ ✗
Cross-validation ✓ ✗ ✗
Diagnostics ✓ ✓ ✗
Residuals ✓ ✓ ✓
Robustness weights ✓ ✓ ✓
Parallel execution ✓ ✓ ✗

Next Steps

sessionInfo()
#> R version 4.6.1 (2026-06-24)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 26.04.1 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so;  LAPACK version 3.12.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] rfastloess_3.0.0 rmarkdown_2.32  
#> 
#> loaded via a namespace (and not attached):
#>  [1] digest_0.6.39    R6_2.6.1         fastmap_1.2.0    xfun_0.62       
#>  [5] maketools_1.3.2  cachem_1.1.0     knitr_1.52       htmltools_0.5.9 
#>  [9] buildtools_1.0.0 lifecycle_1.0.5  cli_3.6.6        sass_0.4.10     
#> [13] jquerylib_0.1.4  compiler_4.6.1   sys_3.4.3        tools_4.6.1     
#> [17] evaluate_1.0.5   bslib_0.12.0     yaml_2.3.12      otel_0.2.0      
#> [21] jsonlite_2.0.0   rlang_1.3.0