Skip to content

Commit

Permalink
version 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Haotian Pang authored and cran-robot committed Apr 19, 2016
1 parent d772dcc commit 189b3e9
Show file tree
Hide file tree
Showing 21 changed files with 1,114 additions and 359 deletions.
24 changes: 12 additions & 12 deletions DESCRIPTION
@@ -1,20 +1,20 @@
Package: fastclime
Type: Package
Title: A Fast Solver for Parameterized Linear Programming Problems and
Constrained L1 Minimization Approach to Sparse Precision Matrix
Estimation
Version: 1.2.5
Date: 2015-04-26
Title: A Fast Solver for Parameterized LP Problems, Constrained L1
Minimization Approach to Sparse Precision Matrix Estimation and
Dantzig Selector
Version: 1.4
Date: 2016-04-18
Author: Haotian Pang, Han Liu and Robert Vanderbei
Maintainer: Haotian Pang <hpang@princeton.edu>
Depends: R (>= 2.15.0), lattice, igraph, MASS, Matrix
Description: An efficient method of recovering precision matrices
by applying the parametric simplex method is provided in this package.
The computation is based on a linear optimization solver.
It also contains a generic Linear Programming solver and a
parameterized Linear Programming solver based on the parametric simplex method.
Description: Provides a method of recovering the precision matrix efficiently
and solving for the dantzig selector by applying the parametric
simplex method. The computation is based on a linear optimization
solver. It also contains a generic LP solver and a parameterized LP
solver using parametric simplex method.
License: GPL-2
Repository: CRAN
Packaged: 2015-04-28 15:09:28 UTC; Haotian
Packaged: 2016-04-18 20:42:46 UTC; diqi
NeedsCompilation: yes
Date/Publication: 2015-04-29 01:00:45
Date/Publication: 2016-04-19 01:03:54
33 changes: 20 additions & 13 deletions MD5
@@ -1,38 +1,45 @@
14f64da498203e5dfa0d0c38e060a879 *DESCRIPTION
91550c718c980cdc013d446f08e2ab43 *NAMESPACE
9e4bf14ea92b98a590d7fa1eac42849f *R/fastclime.R
bbd18b1d4fd1567705b80f2ed105166d *DESCRIPTION
06ad4ba0325b6b4cd1db0527d7d29c84 *NAMESPACE
d73d03f0823c3525f51e536fd2239dbb *R/dantzig.R
160d9f4b55ec7785b4b072462b85e098 *R/dantzig.generator.R
abe951f5b691616b98195f3d79ac2f6f *R/dantzig.selector.R
1f0a64344d4a8e359a343593d6bfccb5 *R/fastclime.R
72e007d2cb34233ade78ee6e2f1f8b76 *R/fastclime.generator.R
8ef3ee31b65f547317d1462094958e44 *R/fastclime.lambda.R
b3963588ea4d8a6a2cd76260cc1d1e4d *R/fastclime.plot.R
47a616773f0890d252a050e8c6fcc8e1 *R/fastclime.selector.R
5c3828535b08a0c1788ed23c83861df0 *R/fastlp.R
536660f46b0c6dc2521f61f909c17c25 *R/paralp.R
76c9cdb8b2cceb78acb824b3638b1b33 *build/vignette.rds
63e519b5961c72e0c7658351fb3768d7 *build/vignette.rds
ec90576375b24e35502847bdd1d85b6e *data/stockdata.rda
9cf23fc8036ec97c902be03c40a08490 *inst/doc/vignette.Rnw
f98003a926cc707a4151fca574f18949 *inst/doc/vignette.pdf
fecc41afd3b960765e9bb14249608699 *man/fastclime-package.Rd
0de78a40947a13893cc690823524fd3b *man/fastclime.Rd
05bb9eae8a1e4a458d4c9630fd907b8d *man/fastclime.generator.Rd
324d7b637a23e7d94cd740ae71269204 *man/fastclime.lambda.Rd
39d6af5a5f954649c45630c36af872bb *man/dantzig.Rd
a548bf97e2058993638ff0b83fee209e *man/dantzig.generator.Rd
c682ad82b538860d45104db2d6548115 *man/dantzig.selector.Rd
2b4e4a37efb71e88c8c028047a614fb3 *man/fastclime-package.Rd
be21f97b1fe5ae2bfd866060d75e305d *man/fastclime.Rd
abbc954825a01b4f8fa520024d267864 *man/fastclime.generator.Rd
64307ab02e80b23986e1f4446aa316c6 *man/fastclime.plot.Rd
a0184c8f7fd1815026131718920df8f6 *man/fastclime.selector.Rd
35a34d4b383d8d9798b754ca6ebd808b *man/fastlp.Rd
e45d01c047c1c70cd41af8adb55ec220 *man/paralp.Rd
4fede98f1e2ad5f3ee859ea58504be85 *man/plot.fastclime.Rd
66a8b6d1673d092cb2d2e15434493e3e *man/plot.sim.Rd
b196c00bb421f420ddd428008f97458b *man/print.fastclime.Rd
fbb7265b9ba8567834e3a326c7b67247 *man/print.sim.Rd
f584effdd8752b5956fea4ac449e7e33 *man/stockdata.Rd
35a63cab361acbbe913b1ed670d0c13f *src/fastlp.c
5a43dc28eb8a09075c5635f6d1f059b4 *src/dantzig.c
727636e2dbade4df49b5b850fdd8ec4f *src/fastlp.c
3d21bc5d49dee6d81d869301b5adbcb0 *src/heap.c
ad5e9b747ce1895e811d2d2e8052eddc *src/heap.h
c5217e444b843a5a358b905e6cb1c975 *src/linalg.c
73f4a0339e3200c93191fb0ca0fd7ec8 *src/linalg.c
73fc5b2f3cf1fd12dab5c3066e43f6d7 *src/linalg.h
7f31e3adcb7ccc095b1276de9a0b528f *src/lu.c
af36d5dada6396e15a3010c505432213 *src/lu.h
abc0a80ca8d0260b12e96ba9f9df608f *src/macros.h
e1be8277ecf906d37bc71e80fb591490 *src/myalloc.h
f71b04cab340901ada6b838edac84ff9 *src/paralp.c
38e3e602e5d4ef2881e1d209050bf5d2 *src/parametric.c
700fdd78e2957c90d1e691643322f8e9 *src/paralp.c
e43295a6e453c3bebe1f5f6e81e9d1c0 *src/parametric.c
38e9ff9c3d2f5b3b832010d120069caf *src/tree.c
ebd8db35929bc9a80f444621e0e0f909 *src/tree.h
0dcd4cce00eb3ef52ec58251b0c62ea4 *vignettes/fastclime.pdf
Expand Down
10 changes: 8 additions & 2 deletions NAMESPACE
@@ -1,13 +1,19 @@
useDynLib("fastclime")
import("Matrix","igraph","lattice","MASS")
importFrom("grDevices", "dev.off", "gray.colors", "postscript")
importFrom("graphics", "par", "plot")
importFrom("stats", "cor", "cov", "rbinom", "rnorm", "runif")
export(fastclime,
fastclime.generator,
fastclime.plot,
fastclime.lambda,
fastclime.selector,
print.fastclime,plot.fastclime,
print.sim,plot.sim,
fastlp,
paralp
paralp,
dantzig,
dantzig.generator,
dantzig.selector
)

S3method("print","sim")
Expand Down
54 changes: 54 additions & 0 deletions R/dantzig.R
@@ -0,0 +1,54 @@
#-------------------------------------------------------------------------------#
# Package: fastclime #
# dantzig(): Dantzig Selector Function #
# Authors: Haotian Pang, Han Liu and Robert Vanderbei #
# Emails: <hpang@princeton.edu>, <hanliu@princeton.edu> and <rvdb@princetonedu> #
# Date: April 25th 2014 #
# Version: 1.2.4 #
#-------------------------------------------------------------------------------#
dantzig <- function(X, y, lambda = 0.01, nlambda = 50)
{
n0<-nrow(X)
d0<-ncol(X)
BETA0<-matrix(0,d0,nlambda)
lambdalist<-matrix(0,nlambda,1)

cat("compute X^TX and X^y \n")

X2=t(X)%*%X
Xy=t(X)%*%y

cat("start recovering \n")

# start.time <- Sys.time()
str=.C("dantzig", as.double(X2), as.double(Xy), as.double(BETA0),
as.integer(d0), as.double(lambda), as.integer(nlambda), as.double(lambdalist), PACKAGE="fastclime")
# end.time <- Sys.time()
# t0 <- end.time - start.time

# ptm <- proc.time()
# cat("prepare the solution path \n")
# proc.time() - ptm
# print(ptm)

rm(X2,Xy)
BETA0<-matrix(unlist(str[3]),d0,nlambda)
lambdalist<-unlist(str[7])

validn<-sum(lambdalist>0)

BETA0<-BETA0[,1:validn]

final_lambda<-lambdalist[validn]
cat("lambdamin is ", final_lambda,"\n")

lambdalist<-lambdalist[1:validn]
result<-list("X" = X, "y"=y, "BETA0"=BETA0, "n0"=n0, "d0"=d0, "validn"=validn, "lambdalist"=lambdalist)

gc()
class(result) = "dantzig"
cat("Done! \n")

return(result)

}
47 changes: 47 additions & 0 deletions R/dantzig.generator.R
@@ -0,0 +1,47 @@

#---------------------------------------------------------------------------------#
# Package: fastclime #
# Dantzig.generator: Generates sparse linear regression model for testing dantzig #
# Authors: Haotian Pang, Han Liu, Robert Vanderbei and Di Qi #
# Emails: <hpang@princeton.edu>, <hanliu@princeton.edu> and <rvdb@princetonedu> #
# Date: April 17th 2016 #
# Version: 1.4.2 #
#---------------------------------------------------------------------------------#

dantzig.generator <- function(n = 50, d = 100, sparsity = 0.1, sigma0=1)
{

if(sparsity<1){
s<-floor(d*sparsity)
}
else{
s<-sparsity
}


BETA<-rep(0,d)
pos<-rep(0,s)

for (i in 1:s)
{

a<-rnorm(1, mean=0, sd=1)
si<-2*(rbinom(1,1,0.5)-0.5)
n1<-floor(runif(1,min=1,max=d+1))
BETA[n1]=si*(1+a)
pos[i]=n1
}

sigma<-rnorm(n, mean=0, sd=sigma0)


X0<-matrix(rnorm(n*d, mean = 0, sd = 1), n,d)
y<-X0%*%BETA+sigma

gc()

sim = list(X0 = X0 , y = y, BETA=BETA, s=s, pos=pos)
class(sim) = "sim"
return(sim)
}

9 changes: 9 additions & 0 deletions R/dantzig.selector.R
@@ -0,0 +1,9 @@
dantzig.selector <- function(lambdalist, BETA0, lambda){
for (i in 1:length(lambdalist)) {
if (lambdalist[i] < lambda) {
break;
}
}
beta0<-BETA0[,i]
return(beta0)
}
5 changes: 3 additions & 2 deletions R/fastclime.R
Expand Up @@ -12,14 +12,15 @@ fastclime <- function(x, lambda.min=0.1, nlambda = 50)
gcinfo(FALSE)
cov.input<-1
SigmaInput<-x
d<-dim(SigmaInput)[2]

if(!isSymmetric(x))
{
SigmaInput<-cor(x)
SigmaInput<-cov(x)*(1-1/d)
cov.input<-0
}

d<-dim(SigmaInput)[2]


cat("Allocating memory \n")
maxnlambda=0
Expand Down
17 changes: 10 additions & 7 deletions R/fastclime.lambda.R → R/fastclime.selector.R
Expand Up @@ -5,14 +5,14 @@
# Version: 1.2.4 #
#------------------------------------------------------------------------------------------#

fastclime.lambda <- function(lambdamtx, icovlist, lambda)
fastclime.selector <- function(lambdamtx, icovlist, lambda)
{

gcinfo(FALSE)
d<-dim(icovlist[[1]])[2]
maxnlambda<-dim(lambdamtx)[1]
icov<-matrix(0,d,d)
path<-matrix(0,d,d)
adaj<-matrix(0,d,d)
seq<-rep(0,d)
threshold<-1e-5
status<-0
Expand All @@ -34,13 +34,16 @@ fastclime.lambda <- function(lambdamtx, icovlist, lambda)

}

icov<-(icov+t(icov))/2
icov <- icov*(abs(icov)<= abs(t(icov)))+ t(icov)*(abs(icov)> abs(t(icov)))
cat("changed to min")
#icov<-(icov+t(icov))/2
tmpicov<-icov
diag(tmpicov)<-0
path<-Matrix(tmpicov>threshold, sparse=TRUE)*1
adaj<-Matrix(tmpicov>threshold, sparse=TRUE)*1



sparsity<-(sum(path))/(d^2-d)
sparsity<-(sum(adaj))/(d^2-d)

if(status==1)
{
Expand All @@ -50,8 +53,8 @@ fastclime.lambda <- function(lambdamtx, icovlist, lambda)
rm(temp_lambda,seq,d,threshold)
gc()

result<-list("icov"=icov, "path"=path,"sparsity"=sparsity)
class(result)="fastclime.lambda"
result<-list("icov"=icov, "adaj"=adaj,"sparsity"=sparsity)
class(result)="fastclime.selector"

return(result)

Expand Down
Binary file modified build/vignette.rds
Binary file not shown.
85 changes: 85 additions & 0 deletions man/dantzig.Rd
@@ -0,0 +1,85 @@
\name{dantzig}
\alias{dantzig}

\title{
A solver for the Dantzig selector estimator
}

\description{
Implementation of the Primal Dual (i.e. Self Dual) Simplex Method on Dantzig selector
}

\usage{
dantzig(X, y, lambda = 0.01, nlambda = 50)
}

\arguments{
\item{X}{
\code{x} is an \code{n} by \code{d} data matrix
}
\item{y}{
\code{y} is a length \code{n} response vector
}
\item{lambda}{
The parametric simplex method will stop when the calculated parameter is smaller than lambda. The default value is \code{0.01}.
}
\item{nlambda}{
This is the number of the maximum path length one would like to achieve. The default length is 50.
}
}

\details{
This program applies the parametric simplex linear programming method to the Dantzig selector to solve for the regression coefficient vector. The solution path of the problem corresponds to the parameter in the parametric simplex method.
}

\note{
The program will stop when either the maximum number of iterations for each column \code{nlambda} is achieved or when the required \code{lambda} is achieved for each column. Note if d is large and nlambda is also large, it is possible that the program will fail to allocate memory for the path.
}



\value{
An object with S3 class \code{"dantzig"} is returned:
\item{X}{
\code{X} is the \code{n} by \code{d} data matrix.
}
\item{y}{
\code{y} is a length \code{n} response vector.
}
\item{BETA0}{
\code{BETA0} is a \code{d} by \code{validn} matrix where each column has an estimated regression coefficient vector given a lambda interval.
}

\item{n0}{
\code{n0} is the number of rows in the \code{n} by \code{d} data matrix.
}
\item{d0}{
\code{d0} is the number of columns in the \code{n} by \code{d} data matrix.
}
\item{validn}{
\code{validn} is the number of solutions along the solution path. The maximum is \code{nlambda}.
}
\item{lambdalist}{
\code{lambdalist} is the decrementing path of the lambda solution values.
}

}

\author{
Haotian Pang, Han Liu, Robert Vanderbei and Di Qi \cr
Maintainer: Haotian Pang<hpang@princeton.edu>
}

\seealso{
\code{\link{dantzig.selector}}
}

\examples{

#generate data
a = dantzig.generator(n = 200, d = 100, sparsity = 0.1)

#regression coefficient estimation
b = dantzig(a$X0, a$y, lambda = 0.1, nlambda = 100)

}

0 comments on commit 189b3e9

Please sign in to comment.