R/transformers.R
penalty_l1.Rd
Creates a penalty function that computes the L1 norm (sum of absolute values). Used for sparsity-inducing regularization.
penalty_l1(weights = NULL)
Optional parameter weights (default: all 1)
Penalty function
penalty <- penalty_l1() penalty(c(1, -2, 3)) # Returns 6 #> [1] 6 # Weighted L1 penalty <- penalty_l1(weights = c(1, 2, 1)) penalty(c(1, -2, 3)) # Returns 1*1 + 2*2 + 1*3 = 8 #> [1] 8