binary_search: Binary Search for Penalization Parameter

Description Usage Arguments Details Examples

View source: R/binary_search.R

Description

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.

Usage

1
binary_search(x, c, maxit = 100)

Arguments

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

Details

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.

Examples

 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))))

schoonees/spca documentation built on Jan. 31, 2021, 6:21 p.m.