Adaptive Smoothness Penalized Least Squares Baseline
Source:R/baseline-pls-advanced.R
step_measure_baseline_aspls.Rdstep_measure_baseline_aspls() creates a specification of a recipe step
that applies Adaptive Smoothness Penalized Least Squares baseline correction.
Usage
step_measure_baseline_aspls(
recipe,
measures = NULL,
lambda = 1e+06,
alpha = 0.5,
max_iter = 50L,
tol = 1e-05,
role = NA,
trained = FALSE,
skip = FALSE,
id = recipes::rand_id("measure_baseline_aspls")
)Arguments
- recipe
A recipe object.
- measures
An optional character vector of measure column names.
- lambda
Base smoothness parameter. Default is 1e6.
- alpha
Adaptive weight parameter controlling smoothness adaptation (0 = no adaptation, 1 = maximum adaptation). Higher values cause regions with larger residuals to receive higher smoothness penalties. Note that adaptation is applied globally via an averaged lambda. Default is 0.5. Tunable via
baseline_alpha().- max_iter
Maximum number of iterations. Default is 50.
- tol
Convergence tolerance. Default is 1e-5.
- role
Not used.
- trained
Logical indicating if the step has been trained.
- skip
Logical. Should the step be skipped when baking?
- id
Unique step identifier.
Details
aspls adapts the smoothness parameter based on the signal properties. The algorithm computes a local smoothness weight based on residual magnitude, then uses the global average as the effective lambda. This provides some adaptation to peak intensity while maintaining computational efficiency.
This method is particularly effective for:
Signals with varying peak widths
Data with both sharp peaks and gradual baseline changes
Chromatography with complex baselines
See also
Other measure-baseline:
step_measure_baseline_airpls(),
step_measure_baseline_als(),
step_measure_baseline_arpls(),
step_measure_baseline_auto(),
step_measure_baseline_custom(),
step_measure_baseline_fastchrom(),
step_measure_baseline_gpc(),
step_measure_baseline_iarpls(),
step_measure_baseline_minima(),
step_measure_baseline_morph(),
step_measure_baseline_morphological(),
step_measure_baseline_poly(),
step_measure_baseline_py(),
step_measure_baseline_rf(),
step_measure_baseline_rolling(),
step_measure_baseline_snip(),
step_measure_baseline_tophat(),
step_measure_detrend()
Examples
library(recipes)
# \donttest{
rec <- recipe(water + fat + protein ~ ., data = meats_long) |>
update_role(id, new_role = "id") |>
step_measure_input_long(transmittance, location = vars(channel)) |>
step_measure_baseline_aspls(lambda = 1e6, alpha = 0.5) |>
prep()
bake(rec, new_data = NULL)
#> # A tibble: 215 × 6
#> id water fat protein .measures channel
#> <int> <dbl> <dbl> <dbl> <meas> <list>
#> 1 1 60.5 22.5 16.7 [100 × 2] <int [100]>
#> 2 2 46 40.1 13.5 [100 × 2] <int [100]>
#> 3 3 71 8.4 20.5 [100 × 2] <int [100]>
#> 4 4 72.8 5.9 20.7 [100 × 2] <int [100]>
#> 5 5 58.3 25.5 15.5 [100 × 2] <int [100]>
#> 6 6 44 42.7 13.7 [100 × 2] <int [100]>
#> 7 7 44 42.7 13.7 [100 × 2] <int [100]>
#> 8 8 69.3 10.6 19.3 [100 × 2] <int [100]>
#> 9 9 61.4 19.9 17.7 [100 × 2] <int [100]>
#> 10 10 61.4 19.9 17.7 [100 × 2] <int [100]>
#> # ℹ 205 more rows
# }