Skip to content

Commit 04d4fb6

Browse files
JamesHWadeclaude
andcommitted
fix: update neg_mask inside iarpls iteration loop
Move neg_mask computation inside the loop to avoid stale mask bug. The mask now updates with each iteration's residuals instead of using the initial coarse baseline positions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0a8c9c3 commit 04d4fb6

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

R/baseline-pls-advanced.R

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,6 @@ prep.step_measure_baseline_iarpls <- function(x, training, info = NULL, ...) {
464464
# First stage: coarse baseline with smaller lambda
465465
baseline_coarse <- .arpls_simple(y, lambda_1, max_iter = 5)
466466

467-
# Calculate initial weights based on coarse baseline
468-
residuals <- y - baseline_coarse
469-
neg_mask <- residuals < 0
470-
471467
# Initialize refined baseline
472468
baseline <- baseline_coarse
473469

@@ -478,8 +474,9 @@ prep.step_measure_baseline_iarpls <- function(x, training, info = NULL, ...) {
478474
for (iter in seq_len(max_iter)) {
479475
baseline_old <- baseline
480476

481-
# Update residuals
477+
# Update residuals and mask
482478
residuals <- y - baseline
479+
neg_mask <- residuals < 0
483480

484481
# Improved weight function
485482
mad_val <- stats::mad(residuals[neg_mask], na.rm = TRUE)

0 commit comments

Comments
 (0)