Description Usage Arguments Details Examples
View source: R/binary_search.R
Performs binary search to find a value of the shrinkage parameter lambda which obtains a required L1-norm value after soft-thresholding and normalization to length one. The value of lambda found is the smallest value that attains the required constraint value.
1 | binary_search(x, c, maxit = 100)
|
x |
Vector to be soft-thresholded and normalized |
c |
Desired value of the L1-norm after soft-thresholding and normalization |
maxit |
Maximum number of iterations for the binary search |
Note that in the PMA
package (version 1.2), the binary search will find the largest
value of lambda that imposes the required limit on the L1-norm after soft-thresholding in case
this norm has regions of lambda for which it is constant. This leads to sparser solutions
than what is necessary.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## Random vector to soft-threshold and normalize
set.seed(1)
(z <- rnorm(25))
## Binary search for L1-norm of 1 (returning lambda)
(lambda <- binary_search(z, 1))
## Graphical illustration
pts <- seq(from = 0, to = max(abs(z)), length.out = 100)
plot(pts, sapply(pts, function(a) sum(abs(soft_l2norm(z, a)))),
ylab = "L1-norm", xlab = expression(lambda))
abline(v = binary_search(z, 1, maxit = 1), col = 2, lty = 2)
abline(v = binary_search(z, 1, maxit = 2), col = 2, lty = 2)
abline(v = binary_search(z, 1, maxit = 3), col = 2, lty = 2)
abline(v = binary_search(z, 1, maxit = 4), col = 2, lty = 2)
abline(v = binary_search(z, 1, maxit = 15), col = 2, lty = 2)
## More tests
sum(abs(soft_l2norm(z, lambda)))
sum(abs(soft_l2norm(z, binary_search(z, 2))))
sum(abs(soft_l2norm(z, binary_search(z, 3))))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.