Title: | Fast Structural Filtering |
---|---|
Description: | An implementation of the fast structural filtering with L0 penalty. It includes an adaptive polynomial estimator by minimizing the least squares error with constraints on the number of breaks in their (k + 1)-st discrete derivative, for a chosen integer k >= 0. It also includes generalized structure sparsity constraint, i.e., graph trend filtering. This package is implemented via the primal dual active set algorithm, which formulates estimates and residuals as primal and dual variables, and utilizes efficient active set selection strategies based on the properties of the primal and dual variables. |
Authors: | Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang |
Maintainer: | Canhong Wen <[email protected]> |
License: | GPL-3 |
Version: | 0.1.1 |
Built: | 2024-12-15 07:31:00 UTC |
Source: | CRAN |
This is a fast calculation function that solves the L0 fused problem via the primal dual active set algorithm. It fits a piecewise constant regression model by minimizing the least squares error with constraints on the number of breaks in their 1-st discrete derivative.
ffused(y, s, K.max=5)
ffused(y, s, K.max=5)
y |
Response sequence to be fitted. |
s |
Number of knots in the piecewise constant(breaks in the derivative), default is 10. |
K.max |
The maximum number of steps for the algorithm to take before termination. Default is 5. |
y |
The observed response vector. Useful for plotting and other methods. |
beta |
Fitted value. |
v |
Primal coefficient. The indexes of the nonzero values correspond to the locations of the breaks. |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
Wen,C., Wang, X., Shen, Y., and Zhang, A. (2017). "L0 trend filtering", technical report.
set.seed(111) n <- 1000 sigma <- 0.5 y0 <- rep(0,n) y0[100:150] <- 2.5 y0[400:600] <- -2.4 y0[800:810] <- 4 y <- y0 + sigma*rnorm(n) re = ffused(y, s = 8, K.max = 5)
set.seed(111) n <- 1000 sigma <- 0.5 y0 <- rep(0,n) y0[100:150] <- 2.5 y0[400:600] <- -2.4 y0[800:810] <- 4 y <- y0 + sigma*rnorm(n) re = ffused(y, s = 8, K.max = 5)
This is a fast calculation function that solves the L0 fused problem via the primal dual active set algorithm. It fits a piecewise constant regression model by minimizing the number of breaks in derivative with constraints on the least squares error.
ffused.ada(y, tau = 1, s.max = 20, eps = 0.1)
ffused.ada(y, tau = 1, s.max = 20, eps = 0.1)
y |
Numeric vector of inputs. |
tau |
Step length for searching the best model, i.e., in the t-th iteration, a model with tau*t knots will be fitted. |
s.max |
The maximum nubmer of knots in the piecewise constant(breaks in the (k+1)-st derivative), default is 20 |
eps |
Early stop criterion. The algorithm stops when mean squared error is less than eps |
y |
The observed response vector. Useful for plotting and other methods. |
beta |
Fitted value |
v |
Primal coefficient. The indexes of the nonzero values correspond to the locations of the breaks. |
beta.all |
Solution path of fitted value, beta, corresponding to different degrees of freedom. |
df |
A vector giving an unbiased estimate of the degrees of freedom of the fit, i.e., the number of nonzero values in |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
Wen,C., Wang, X., Shen, Y., and Zhang, A. (2017). "L0 trend filtering", technical report.
set.seed(111) n <- 1000 sigma <- 0.5 y0 <- rep(0,n) y0[100:150] <- 2.5 y0[400:600] <- -2.4 y0[800:810] <- 4 y <- y0 + sigma*rnorm(n) re = ffused.ada(y, tau = 1, s.max = 10)
set.seed(111) n <- 1000 sigma <- 0.5 y0 <- rep(0,n) y0[100:150] <- 2.5 y0[400:600] <- -2.4 y0[800:810] <- 4 y <- y0 + sigma*rnorm(n) re = ffused.ada(y, tau = 1, s.max = 10)
This function solves the generalized structural filtering problem via the primal dual active set algorithm. It fits a non-parametric regression model by minimizing the least squares error with penalty matrix D on coefficient beta.
fsf(y, D, s = 20, K.max = 5, ddinv=NULL)
fsf(y, D, s = 20, K.max = 5, ddinv=NULL)
y |
Response sequence to be filtered. |
D |
Penalty matrix on coeffient beta. |
s |
Number of knots in the penalized coefficient(breaks in the |
K.max |
The maximum number of steps for the algorithm to take before termination. Default is 5. |
ddinv |
The inverse matrix of |
y |
The observed response vector. Useful for plotting and other methods. |
beta |
Fitted value. |
v |
Primal coefficient. The indexes of the nonzero values correspond to the locations of the breaks in |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
Wen,C., Wang, X., Shen, Y., and Zhang, A. (2017). "L0 trend filtering", technical report.
require(limSolve) n <- 1000 sigma <- 0.5 y0 <- rep(0,n) y0[100:150] <- 2 y0[400:600] <- -1 y0[800:810] <- 4 y <- y0 + sigma*rnorm(n) y[800:810] <- y0[800:810] + sigma*rnorm(11) D0 <- matrix(0, n-1,n) diag(D0) <- -1 for(i in 1:(n-1)) D0[i,i+1] <- 1 m <- dim(D0)[1] re = fsf(y, D0)
require(limSolve) n <- 1000 sigma <- 0.5 y0 <- rep(0,n) y0[100:150] <- 2 y0[400:600] <- -1 y0[800:810] <- 4 y <- y0 + sigma*rnorm(n) y[800:810] <- y0[800:810] + sigma*rnorm(11) D0 <- matrix(0, n-1,n) diag(D0) <- -1 for(i in 1:(n-1)) D0[i,i+1] <- 1 m <- dim(D0)[1] re = fsf(y, D0)
This is a function that solves the structural filtering problem with L0 penalty via the primal dual active set algorithm. It fits a non-parametric regression model by minimizing the number of nonzero values in D*beta with constraints on the least squares error.
fsf.ada(y, D, tau=1, s.max=20, eps=0.1, ddinv=NULL)
fsf.ada(y, D, tau=1, s.max=20, eps=0.1, ddinv=NULL)
y |
Response sequence to be filtered. |
D |
Penalty matrix on coeffient beta. |
tau |
Step length for searching the best model, i.e., in the t-th iteration, a model with tau*t knots will be fitted. |
s.max |
The maximum nubmer of knots in the penalized coefficient(breaks in |
eps |
Early stop criterion. The algorithm stops when mean squared error is less than eps. |
ddinv |
The inverse matrix of |
y |
The observed response vector. Useful for plotting and other methods. |
beta |
Fitted value |
v |
Primal coefficient. The indexes of the nonzero values correspond to the locations of the breaks. |
beta.all |
Solution path of fitted value, beta, corresponding to different degrees of freedom. |
df |
A vector giving an unbiased estimate of the degrees of freedom of the fit, i.e., the number of nonzero values in |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
Wen,C., Wang, X., Shen, Y., and Zhang, A. (2017). "L0 trend filtering", technical report.
require(limSolve) n <- 1000 sigma <- 0.5 y0 <- rep(0,n) y0[100:150] <- 2 y0[400:600] <- -1 y0[800:810] <- 4 y <- y0 + sigma*rnorm(n) y[800:810] <- y0[800:810] + sigma*rnorm(11) D0 <- matrix(0, n-1,n) diag(D0) <- -1 for(i in 1:(n-1)) D0[i,i+1] <- 1 ddt <- D0%*%t(D0) ddinv<- Solve.banded(ddt, 1,1, B = diag(1,dim(D0)[1])) re <- fsf.ada(y, D0, tau = 1, s.max = 10, eps = 0.1, ddinv = ddinv)
require(limSolve) n <- 1000 sigma <- 0.5 y0 <- rep(0,n) y0[100:150] <- 2 y0[400:600] <- -1 y0[800:810] <- 4 y <- y0 + sigma*rnorm(n) y[800:810] <- y0[800:810] + sigma*rnorm(11) D0 <- matrix(0, n-1,n) diag(D0) <- -1 for(i in 1:(n-1)) D0[i,i+1] <- 1 ddt <- D0%*%t(D0) ddinv<- Solve.banded(ddt, 1,1, B = diag(1,dim(D0)[1])) re <- fsf.ada(y, D0, tau = 1, s.max = 10, eps = 0.1, ddinv = ddinv)
This is a function that solves the L0 fused problem via the primal dual active set algorithm in sparse condition. It fits a piecewise constant regression model by minimizing the least squares error with constraints on the number of breaks in their discrete derivative.
fsfused(y, s = 10, T, K.max=5)
fsfused(y, s = 10, T, K.max=5)
y |
Response sequence to be fitted. |
s |
Number of knots in the piecewise constant(breaks in the derivative), default is 10. |
T |
Number of non-zero values in fitted coefficient. |
K.max |
The maximum number of steps for the algorithm to take before termination. Default is 5. |
y |
The observed response vector. Useful for plotting and other methods. |
beta |
Fitted value. |
v |
Primal coefficient. The indexes of the nonzero values correspond to the locations of the breaks. |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
Wen,C., Wang, X., Shen, Y., and Zhang, A. (2017). "L0 trend filtering", technical report.
n <- 1000 sigma <- 0.5 y0 <- rep(0,n) y0[100:150] <- 2.5 y0[400:600] <- -2.4 y0[800:810] <- 4 y <- y0 + sigma*rnorm(n) re = fsfused(y, s = 10, T = 300)
n <- 1000 sigma <- 0.5 y0 <- rep(0,n) y0[100:150] <- 2.5 y0[400:600] <- -2.4 y0[800:810] <- 4 y <- y0 + sigma*rnorm(n) re = fsfused(y, s = 10, T = 300)
This is a function that solves the L0 fused problem via the primal dual active set algorithm in sparse condition. It fits a piecewise constant regression model by minimizing the number of breaks in derivative with constraints on the least squares error.
fsfused.ada(y, tau=1, s.max=20, T, eps=0.1)
fsfused.ada(y, tau=1, s.max=20, T, eps=0.1)
y |
Numeric vector of inputs. |
tau |
Step length for searching the best model, i.e., in the t-th iteration, a model with tau*t knots will be fitted. |
s.max |
The maximum nubmer of knots in the piecewise constant(breaks in the (k+1)-st derivative), default is 20 |
T |
Number of non-zero values in fitted coefficient. |
eps |
Early stop criterion. The algorithm stops when mean squared error is less than eps |
y |
The observed response vector. Useful for plotting and other methods. |
beta |
Fitted value |
v |
Primal coefficient. The indexes of the nonzero values correspond to the locations of the breaks. |
beta.all |
Solution path of fitted value, beta, corresponding to different degrees of freedom. |
df |
A vector giving an unbiased estimate of the degrees of freedom of the fit, i.e., the number of nonzero values in |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
Wen,C., Wang, X., Shen, Y., and Zhang, A. (2017). "L0 trend filtering", technical report.
n <- 1000 sigma <- 0.5 y0 <- rep(0,n) y0[100:150] <- 2.5 y0[400:600] <- -2.4 y0[800:810] <- 4 y <- y0 + sigma*rnorm(n) re = fsfused.ada(y, tau=1, s.max=10, T = 260, eps=1.2*sigma^2)
n <- 1000 sigma <- 0.5 y0 <- rep(0,n) y0[100:150] <- 2.5 y0[400:600] <- -2.4 y0[800:810] <- 4 y <- y0 + sigma*rnorm(n) re = fsfused.ada(y, tau=1, s.max=10, T = 260, eps=1.2*sigma^2)
This function solves the structural filtering problem via the primal dual active set algorithm. It fits a k-th order piecewise polynomial by minimizing the least squares error with constraints on the number of breaks in their (k + 1)-st discrete derivative, for a chosen integer k >= 0.
ftf(y, k = 1, s = 20, K.max = 5)
ftf(y, k = 1, s = 20, K.max = 5)
y |
Numeric vector of inputs. |
k |
An integer specifying the desired order of the piecewise polyomial produced by the solution of the trend filtering problem. Must be non-negative, and the default to 1 (linear trend filtering). |
s |
Number of knots in the piecewise polynomial(breaks in the (k+1)-st derivative), default is 20. |
K.max |
The maximum number of steps for the algorithm to take before termination. Default is 5. |
The L0 trend filtering fits an adaptive piecewise polynomial to linearly ordered observations with contraints on the number of knots, for a chosen integer k >= 0. The knots or the breaks in their (k + 1)-st discrete derivative are chosen adaptively based on the observations.
y |
The observed response vector. Useful for plotting and other methods. |
beta |
Filtered value. |
v |
Primal coefficient. The indexes of the nonzero values correspond to the locations of the breaks. |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
Wen,C., Wang, X., Shen, Y., and Zhang, A. (2017). "L0 trend filtering", technical report.
set.seed(1) sigma <- 0.5 y0 <- c((10:30)/3, (40:10)/4, 2:8) y <- y0 + sigma*rnorm(length(y0)) re <- ftf(y, k = 1, s = 5)
set.seed(1) sigma <- 0.5 y0 <- c((10:30)/3, (40:10)/4, 2:8) y <- y0 + sigma*rnorm(length(y0)) re <- ftf(y, k = 1, s = 5)
This is a function that adaptively solves the trend filtering problem with L0 penalty via the primal dual active set algorithm. It fits a k-th order piecewise polynomial by minimizing the number of breaks in the (k + 1)-st discrete derivative with the constraints on the least squares error.
ftf.ada(y, k = 1, tau = 1, s.max=20, eps=0.1)
ftf.ada(y, k = 1, tau = 1, s.max=20, eps=0.1)
y |
Numeric vector of inputs. |
k |
An integer specifying the desired order of the piecewise polyomial produced by the solution of the trend filtering problem. Must be non-negative, and the default to 1 (linear trend filtering). |
tau |
Step length for searching the best model, i.e., in the t-th iteration, a model with tau*t knots will be fitted. |
s.max |
The maximum nubmer of knots in the piecewise polynomial(breaks in the (k+1)-st derivative), default is 20 |
eps |
Early stop criterion. The algorithm stops when mean squared error is less than eps |
The L0 trend filtering fits an adaptive piecewise polynomial to linearly ordered observations with contraints on the number of knots, for a chosen integer k >= 0. The knots or the breaks in their (k + 1)-st discrete derivative are chosen adaptively based on the observations.
y |
The observed response vector. Useful for plotting and other methods. |
beta |
Filtered value |
v |
Primal coefficient. The indexes of the nonzero values correspond to the locations of the breaks. |
beta.all |
Solution path of filtered value, beta, corresponding to different degrees of freedom. |
df |
A vector giving an unbiased estimate of the degrees of freedom of the fit, i.e., the number of nonzero values in |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
Wen,C., Wang, X., Shen, Y., and Zhang, A. (2017). "L0 trend filtering", technical report.
ftf
.
set.seed(1) sigma <- 0.5 y0 <- c((10:30)/3, (40:10)/4, 2:8) y <- y0 + sigma*rnorm(length(y0)) re <- ftf.ada(y, k = 1, s.max = 5)
set.seed(1) sigma <- 0.5 y0 <- c((10:30)/3, (40:10)/4, 2:8) y <- y0 + sigma*rnorm(length(y0)) re <- ftf.ada(y, k = 1, s.max = 5)
This is a cpp function used for R function l0fused.
l0fused_c(y, T0, max_steps)
l0fused_c(y, T0, max_steps)
y |
Response sequence to be fitted. |
T0 |
Number of knots in the piecewise constant(breaks in the derivative), i.e., the same as s. |
max_steps |
The maximum number of steps for the algorithm to take before termination, i.e., the same as K.max. |
beta |
Fitted value. |
u |
Dual coefficient. |
z |
Primal coefficient. |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
Wen,C., Wang, X., Shen, Y., and Zhang, A. (2017). "L0 trend filtering", technical report.
This is a cpp function used for R function l0gen.
l0gen_c(y, D, T0, max_steps, ddinv)
l0gen_c(y, D, T0, max_steps, ddinv)
y |
Response sequence to be filtered. |
D |
Penalty matrix on coeffient beta. |
T0 |
Number of knots in the penalized coefficient(breaks in the |
max_steps |
The maximum number of steps for the algorithm to take before termination. Same as K.max. |
ddinv |
The inverse matrix of |
beta |
Fitted value. |
u |
Dual coefficient. |
z |
Primal coefficient. |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
Wen,C., Wang, X., Shen, Y., and Zhang, A. (2017). "L0 trend filtering", technical report.
This is a cpp function used for R function l0tf.
l0tf_c(y, k0, T0, max_steps)
l0tf_c(y, k0, T0, max_steps)
y |
Numeric vector of inputs. |
k0 |
An integer specifying the desired order of the piecewise polyomial produced by the solution of the trend filtering problem. |
T0 |
Number of knots in the piecewise polynomial(breaks in the (k+1)-st derivative). |
max_steps |
The maximum number of steps for the algorithm to take before termination. |
beta |
Fitted value. |
u |
Dual coefficient. |
z |
Primal coefficient. |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
Wen,C., Wang, X., Shen, Y., and Zhang, A. (2017). "L0 trend filtering", technical report.
This is a function that plots the fitted results of L0 method.
plotl0(re)
plotl0(re)
re |
The list generated by functions in FastSF package. For a given degree of freedom, plot the fitted value of L0 method. For adaptive situations, plot the MSE of every model under different degrees of freedom. |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
This is a cpp function used for R function sl0fused.
sl0fused_c(y, T0, T02, max_steps)
sl0fused_c(y, T0, T02, max_steps)
y |
Response sequence to be fitted. |
T0 |
Number of knots in the piecewise constant(breaks in the derivative). |
T02 |
Number of non-zero values in fitted coefficient. |
max_steps |
The maximum number of steps for the algorithm to take before termination. |
beta |
Fitted value. |
u |
Dual coefficient. |
z |
Primal coefficient. |
d |
Dual coefficient. |
Canhong Wen, Xueqin Wang, Yanhe Shen, Aijun Zhang
Wen,C., Wang, X., Shen, Y., and Zhang, A. (2017). "L0 trend filtering", technical report.