sparsify_by_column_winner.Rd
This function applies a "winner-take-all" sparsity model. For each column, it finds the single most significant entry based on specified sign constraints and sets all other entries in that column to zero.
A numeric matrix [p_features x k_components].
How to treat the first column. One of:
`"none"`: (Default) The first column is left dense (not sparsified).
`"either"`: The entry with the largest absolute value is kept, regardless of sign.
`"positive"`: The largest entry with a positive sign is kept.
`"negative"`: The entry with the largest magnitude (most negative) with a negative sign is kept.
How to treat all other columns (from the second onwards). Takes the same options as `first_column_constraint`. Defaults to `"either"`.
Logical. If TRUE, ensures every feature is represented in at least one component by "reviving" the single most significant entry for any row that becomes all-zero after sparsity.
A sparsified matrix with the same dimensions as X.
It includes special handling for the first column, which often represents a main effect that may not require the same constraints as subsequent components.
set.seed(123)
mat <- matrix(c(
-5, 0.1, 0.2, 0.3, 0.4, # Col 1: Large negative value
1, 2.0, 0.1, 0.2, 0.3, # Col 2: Large positive value
-1, -0.2, -3, -0.4, -0.5, # Col 3: Only negative values
1, -2, 3, -4, 5 # Col 4: Mixed signs
), nrow = 5, ncol = 4)
res1 <- sparsify_by_column_winner(mat, 'positive', 'positive')