This function removes the bias of treating a single column as "special" by running the `sparsify_by_column_winner` function multiple times. In each run, the columns of the input matrix are permuted so that a different column is in the "first" position. The results are un-permuted and then averaged to produce a stable, unbiased sparse representation.

ensembled_sparsity(X, default_constraint = "positive")

Arguments

X

A numeric matrix [p_features x k_components].

default_constraint

The constraint to apply to all other columns.

Value

A single, averaged sparse matrix with the same dimensions as X.

Examples

set.seed(42)
mat <- matrix(rnorm(15), nrow=5, ncol=3)
mat[2,1] <- 10; mat[4,2] <- -12; mat[1,3] <- 14
print("Original Matrix:")
#> [1] "Original Matrix:"
print(round(mat, 2))
#>       [,1]   [,2]  [,3]
#> [1,]  1.37  -0.11 14.00
#> [2,] 10.00   1.51  2.29
#> [3,]  0.36  -0.09 -1.39
#> [4,]  0.63 -12.00 -0.28
#> [5,]  0.40  -0.06 -0.13

# Keep one column dense, sparsify others by magnitude ('either')
# sparse_ensembled <- ensembled_sparsity(mat,
#  default_constraint = "either"
# )