Skip to contents

Zeroes the k = round(sparsity * size) smallest |W| using a STABLE sort, so ties are broken by position exactly as numpy's mergesort.

Usage

morie_geron_weight_pruning(W, sparsity)

Arguments

W

Numeric object.

sparsity

Requested fraction in [0, 1).

Value

List with W_pruned, mask, threshold, achieved_sparsity, n_pruned, norm_retained.

Examples

set.seed(2)
W <- matrix(rnorm(20), 4, 5)
morie_geron_weight_pruning(W, sparsity = 0.5)
#> $W_pruned
#>            [,1] [,2]      [,3]      [,4]      [,5]
#> [1,] -0.8969145    0 1.9844739  0.000000 0.8786046
#> [2,]  0.0000000    0 0.0000000 -1.039669 0.0000000
#> [3,]  1.5878453    0 0.0000000  1.782229 1.0128287
#> [4,] -1.1303757    0 0.9817528 -2.311069 0.0000000
#> 
#> $mask
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    0    1    0    1
#> [2,]    0    0    0    1    0
#> [3,]    1    0    0    1    1
#> [4,]    1    0    1    1    0
#> 
#> $threshold
#> [1] 0.7079547
#> 
#> $achieved_sparsity
#> [1] 0.5
#> 
#> $n_pruned
#> [1] 10
#> 
#> $norm_retained
#> [1] 0.9735129
#> 
#> $estimate
#>            [,1] [,2]      [,3]      [,4]      [,5]
#> [1,] -0.8969145    0 1.9844739  0.000000 0.8786046
#> [2,]  0.0000000    0 0.0000000 -1.039669 0.0000000
#> [3,]  1.5878453    0 0.0000000  1.782229 1.0128287
#> [4,] -1.1303757    0 0.9817528 -2.311069 0.0000000
#> 
#> $n
#> [1] 20
#>