Description Usage Arguments Additional Options Model Fitting Author(s) Examples
Basis Pursuit is an optimization problem that minimizes ||β||_1 subject to y = X * β. Here X is an n by p matrix with p > n. Basis Pursuit is broadly applied in Compressed Sensing to recover a sparse vector β from the transformed lower dimensional vector y.
This function will not directly conduct the computation,
but rather returns an object of class "ADMM_BP
" that contains
several memeber functions to actually constructs and fits the model.
Member functions that are callable from this object are listed below:
$opts() | Setting additional options. See section Additional Options for details. |
$fit() | Fit the model and do the actual computation. See section Model Fitting for details. |
1 |
x |
The transformation matrix |
y |
The transformed vector to recover from |
Additional options related to ADMM algorithm can be set through the
$opts()
member function of an "ADMM_BP
" object. The usage of
this method is
1 2 | model$opts(maxit = 10000, eps_abs = 1e-4, eps_rel = 1e-4,
rho = NULL)
|
Here model
is the object returned by admm_bp()
.
Explanation of the arguments is given below:
maxit
Maximum number of iterations.
eps_abs
Absolute tolerance parameter.
eps_rel
Relative tolerance parameter.
rho
ADMM step size parameter. If set to NULL
, the program
will compute a default one.
This member function will implicitly return the "ADMM_BP
" object itself.
Model will be fit after calling the $fit()
member function. This is no
argument that needs to be set. The function will return an object of class
"ADMM_BP_fit
", which contains the following fields:
beta
The recovered β vector in sparse form.
niter
Number of ADMM iterations.
Class "ADMM_BP_fit
" also contains a $plot()
member function,
which plots the coefficients against their indices. See the examples below.
Yixuan Qiu <http://statr.me>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ## An Compressed Sensing example ##
## Create a sparse signal vector
set.seed(123)
n = 50
p = 100
nsig = 15
beta_true = c(runif(nsig), rep(0, p - nsig))
beta_true = sample(beta_true)
## Generate the transformation matrix and the compressed vector
x = matrix(rnorm(n * p), n, p)
y = drop(x %*% beta_true)
## Build the model
model = admm_bp(x, y)
## Request a higher precision
model$opts(eps_rel = 1e-5)
## Fit the model
res = model$fit()
res
## Plot for the recovered vector
res$plot()
## The steps above can be accomplished using a chainable call
admm_bp(x, y)$opts(eps_rel = 1e-5)$fit()$plot()
## Compare the true beta and the recovered one
library(ggplot2)
g = res$plot()
d = data.frame(ind = seq_along(beta_true),
coef = beta_true)
g + geom_segment(aes(x = ind + 0.5, xend = ind + 0.5,
y = coef, yend = 0), data = d, color = "red")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.