Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c25de08
Showing
48 changed files
with
5,487 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Package: camel | ||
Type: Package | ||
Title: Calibrated Machine Learning | ||
Version: 0.1.0 | ||
Date: 2013-08-23 | ||
Author: Xingguo Li, Tuo Zhao and Han Liu | ||
Maintainer: Xingguo Li <xingguo.leo@gmail.com> | ||
Depends: R (>= 2.15.0), lattice, igraph, MASS, Matrix | ||
Description: The package "camel" provides the implementation of a family of high-dimensional calibrated machine learning toolkits, including a family of Lasso regression and sparse Gaussian graphical model estimation. Lasso variants including Dantzig Selector, LAD Lasso, SQRT Lasso for estimating high dimensional sparse linear model. The sparse Gaussian graphical model estimation includes TIGER and CLIME using L1 penalty. We adopt the combination of the dual smoothing and monotone fast iterative soft-thresholding algorithm (MFISTA). The computation is memory-optimized using the sparse matrix output. | ||
License: GPL-2 | ||
Repository: CRAN | ||
Packaged: 2013-08-24 21:29:54 UTC; leo | ||
NeedsCompilation: yes | ||
Date/Publication: 2013-08-25 00:13:57 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
c6c1d468bd5532b17f7d42a4e2eb05ef *DESCRIPTION | ||
06165c6be8d7a9fae0eded9c7c00d5f0 *NAMESPACE | ||
9958e8d9e85b55285950af607be68eef *R/camel.plot.R | ||
fb2498fc74877b384247bf7fd52b0df3 *R/camel.slim.R | ||
1adfd2a1f5f23b3b1f56e45a12f74873 *R/camel.slim.dantzig.mfista.R | ||
53eb94f850552b2213dbcc8bc2890b96 *R/camel.slim.lad.mfista.R | ||
45046c6cd362cb25932951ca60310e78 *R/camel.slim.sqrt.mfista.R | ||
304545a72d532c9ac26270158b7f5b86 *R/camel.tiger.R | ||
47a609cdd9549d2ecc23d4c594f32d0b *R/camel.tiger.clime.mfista.R | ||
ae9098d97dcfeb32557386ebb2b56c65 *R/camel.tiger.cv.R | ||
b2b2f4dc986804b3f8980db8748a755a *R/camel.tiger.generator.R | ||
c70dbfd1d7c30d7a16d46f0390f458d0 *R/camel.tiger.roc.R | ||
12836cdf1f6a29ba0e62e1f849400f57 *R/camel.tiger.select.R | ||
8dd8c223b0d034bafebfe98cb0c17777 *R/camel.tiger.slasso.mfista.R | ||
2051fe40ab4728502e9d58bf5a7d0f13 *data/datalist | ||
c576332fdc932a03588c412855fbeea5 *data/eyedata.rda | ||
b127c8695c08310e98ca608604c40667 *man/camel-internal.Rd | ||
c853c1315359df4f46343543968140b9 *man/camel-package.Rd | ||
d776509583a10de6055cc32cb3b4438d *man/camel.plot.Rd | ||
828b53f9e193b96c974e7dd62146f810 *man/camel.slim.Rd | ||
97cb61b5685cd325c684349141642a84 *man/camel.tiger.Rd | ||
cd835291bdc1e97aa9d8748dfeab0fec *man/camel.tiger.generator.Rd | ||
5bcd3b95afa003c09540784da9c262ab *man/camel.tiger.roc.Rd | ||
54daab0d5a1b3e4119aa3f4afdbc16b8 *man/camel.tiger.select.Rd | ||
882280dcffe7212276095a336c9abfb5 *man/eyedata.Rd | ||
006534f9a289631f0d5b519617bacdac *man/plot.roc.Rd | ||
e143df31c319d6036f08808d93482ab1 *man/plot.select.Rd | ||
ecf489c7b99d4e042dea5ed811134514 *man/plot.sim.Rd | ||
f2dec375983019e206dbb16aab161a35 *man/plot.slim.Rd | ||
f8cf8908179a4319377d785971811a8b *man/plot.tiger.Rd | ||
1a4639641244f3c2b877768a64e4d6e6 *man/print.roc.Rd | ||
62211d0df49e816154594be356b99532 *man/print.select.Rd | ||
98fd77e4f108859f35d1c6dd5d75ef82 *man/print.sim.Rd | ||
c5ad89b432d2e5f1817e27c10934d51a *man/print.slim.Rd | ||
73a61cfad9357c0f88f50a2b18584235 *man/print.tiger.Rd | ||
63100601c92fa92017717b3669e13e39 *src/SFGen.c | ||
94a9e6ad59748738cbed89a38e19c30f *src/euc_proj.c | ||
e70cd0ed0548012d591ddf517954eb00 *src/mymath.c | ||
c871586e3a2b0ddf9973af51a08f78f3 *src/mymath.h | ||
6059aef3518cf605dd76b8e9bc5003db *src/slim_dantzig_mfista.c | ||
5967917350e7a727dc7b6e7a83ece6d2 *src/slim_lad_mfista.c | ||
6a57b8771c108f5ec2dfb4d99e0658fd *src/slim_lq.c | ||
d90d38070bf0eaa594bfd7d8ab22a7ab *src/slim_sqrt_mfista.c | ||
47468a5824ef23404980884be9addd36 *src/slimh.c | ||
5e2eff79275278b45fc1805b5b2c58ba *src/slimh.h | ||
4b2aac483f54d1b9567bba0354a2cb7f *src/tiger_clime_mfista.c | ||
20924011fe530dde4579df6cdebabb93 *src/tiger_slasso_mfista.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
useDynLib("camel") | ||
import("MASS","igraph","Matrix","lattice") | ||
export("camel.tiger", | ||
"camel.tiger.generator", | ||
"camel.tiger.clime.mfista", | ||
"camel.tiger.slasso.mfista", | ||
"camel.tiger.roc", | ||
"camel.tiger.select", | ||
"camel.slim", | ||
"camel.slim.lad.mfista", | ||
"camel.slim.sqrt.mfista", | ||
"camel.slim.dantzig.mfista", | ||
"camel.plot", | ||
"print.slim", | ||
"print.tiger", | ||
"print.select", | ||
"print.sim", | ||
"plot.slim", | ||
"plot.tiger", | ||
"plot.roc", | ||
"plot.select", | ||
"plot.sim") | ||
S3method("print", "tiger") | ||
S3method("print", "slim") | ||
S3method("print", "roc") | ||
S3method("print", "select") | ||
S3method("print", "sim") | ||
S3method("plot", "tiger") | ||
S3method("plot", "roc") | ||
S3method("plot", "select") | ||
S3method("plot", "sim") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#-----------------------------------------------------------------------------------# | ||
# Package: camel # | ||
# camel.tiger.plot(): graph visualization # | ||
# Author: Xingguo Li # | ||
# Email: <xingguo.leo@gmail.com> # | ||
# Date: Aug 23th, 2013 # | ||
# Version: 0.1.0 # | ||
#-----------------------------------------------------------------------------------# | ||
|
||
camel.plot <- function(G, epsflag = FALSE, graph.name = "default", cur.num = 1, location=NULL){ | ||
gcinfo(FALSE) | ||
if(missing(location)) location = getwd() | ||
setwd(location) | ||
g = graph.adjacency(as.matrix(G!=0), mode="undirected", diag=FALSE) | ||
layout.grid = layout.fruchterman.reingold(g) | ||
|
||
if(epsflag == TRUE) postscript(paste(paste(graph.name, cur.num, sep=""), "eps", sep="."), width = 8.0, height = 8.0) | ||
par(mfrow = c(1,1)) | ||
plot(g, layout=layout.grid, edge.color='gray50',vertex.color="red", vertex.size=2, vertex.label=NA) | ||
rm(g,location) | ||
gc() | ||
if(epsflag == TRUE) dev.off() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
#----------------------------------------------------------------------------------# | ||
# Package: camel # | ||
# camel.slim(): The user interface for slim() # | ||
# Author: Xingguo Li # | ||
# Email: <xingguo.leo@gmail.com> # | ||
# Date: Aug 23th, 2013 # | ||
# Version: 0.1.0 # | ||
#----------------------------------------------------------------------------------# | ||
|
||
camel.slim <- function(X, | ||
Y, | ||
lambda = NULL, | ||
nlambda = NULL, | ||
lambda.min.ratio = NULL, | ||
method="lq", | ||
q = 2, | ||
prec = 1e-4, | ||
max.ite = 1e4, | ||
mu = 0.01, | ||
intercept = TRUE, | ||
verbose = TRUE) | ||
{ | ||
if(method!="dantzig" && method!="lq"){ | ||
cat("\"method\" must be dantzig or lq lasso.\n") | ||
return(NULL) | ||
} | ||
if(method=="lq"){ | ||
if(q!=1 && q!=2){ | ||
cat("q must be either 1 or 2 when method = \"lq\".\n") | ||
return(NULL) | ||
} | ||
} else q=0 | ||
if(verbose) { | ||
cat("Sparse Linear Regression with L1 Regularization.\n") | ||
} | ||
n = nrow(X) | ||
d = ncol(X) | ||
maxdf = max(n,d) | ||
|
||
xm=matrix(rep(.colMeans(X,n,d),n),nrow=n,ncol=d,byrow=T) | ||
x1=X-xm | ||
sdx=sqrt(diag(t(x1)%*%x1)/(n-1)) | ||
Cxinv=diag(1/sdx) | ||
xx=x1%*%Cxinv | ||
ym=mean(Y) | ||
y1=Y-ym | ||
sdy=sqrt(sum(y1^2)/(n-1)) | ||
yy=y1/sdy | ||
corr=cor(xx,yy) | ||
|
||
if(intercept){ | ||
xx = cbind(rep(1, nrow(xx)), xx) | ||
d = d+1 | ||
} | ||
|
||
if(!is.null(lambda)) nlambda = length(lambda) | ||
if(is.null(lambda)){ | ||
if(is.null(nlambda)) | ||
nlambda = 5 | ||
if(is.null(lambda.min.ratio)){ | ||
if(method=="dantzig") | ||
lambda.min.ratio = 0.8 | ||
else | ||
lambda.min.ratio = 0.25 | ||
} | ||
if(method=="dantzig") | ||
lambda.max = max(corr) | ||
else | ||
lambda.max = pi*sqrt(log(d)/n) | ||
|
||
lambda.min = lambda.min.ratio*lambda.max | ||
lambda = exp(seq(log(lambda.max), log(lambda.min), length = nlambda)) | ||
rm(lambda.max,lambda.min,lambda.min.ratio) | ||
gc() | ||
} | ||
begt=Sys.time() | ||
if(method=="dantzig") # dantzig | ||
out = camel.slim.dantzig.mfista(yy, xx, lambda, nlambda, n, d, maxdf, mu, max.ite, prec,intercept,verbose) | ||
|
||
if(method=="lq") { | ||
if(is.null(q)) q=2; | ||
if(q==1) { # lad lasso | ||
out = camel.slim.lad.mfista(Y, xx, lambda*n, nlambda, n, d, maxdf, mu, max.ite, prec,intercept,verbose) | ||
} | ||
if(q==2) { # sqrt lasso | ||
out = camel.slim.sqrt.mfista(Y, xx, lambda*sqrt(n), nlambda, n, d, maxdf, mu, max.ite, prec,intercept,verbose) | ||
} | ||
} | ||
runt=Sys.time()-begt | ||
|
||
sparsity=rep(0,nlambda) | ||
for(i in 1:nlambda) | ||
sparsity[i] = sum(out$beta[[i]]!=0)/d | ||
|
||
est = list() | ||
intcpt=matrix(0,nrow=1,ncol=nlambda) | ||
|
||
if(!intercept){ | ||
beta1=matrix(0,nrow=d,ncol=nlambda) | ||
if(q==1 || q==2){ | ||
for(k in 1:nlambda){ | ||
tmp.beta = out$beta[[k]] | ||
intcpt[k]=-xm[1,]%*%Cxinv%*%tmp.beta | ||
beta1[,k]=Cxinv%*%tmp.beta | ||
} | ||
} | ||
else{ | ||
for(k in 1:nlambda){ | ||
intcpt[k]=ym-xm[1,]%*%Cxinv%*%out$beta[[k]]*sdy | ||
beta1[,k]=Cxinv%*%out$beta[[k]]*sdy | ||
} | ||
} | ||
} else { | ||
beta1=matrix(0,nrow=d-1,ncol=nlambda) | ||
if(q==1 || q==2){ | ||
for(k in 1:nlambda){ | ||
tmp.beta = out$beta[[k]][2:d] | ||
intcpt[k]=out$beta[[k]][1]-xm[1,]%*%Cxinv%*%tmp.beta | ||
beta1[,k]=Cxinv%*%tmp.beta | ||
} | ||
} | ||
else{ | ||
for(k in 1:nlambda){ | ||
tmp.beta = out$beta[[k]][2:d] | ||
intcpt[k]=ym-xm[1,]%*%Cxinv%*%tmp.beta*sdy+out$beta[[k]][1]*sdy | ||
beta1[,k]=Cxinv%*%tmp.beta*sdy | ||
} | ||
} | ||
} | ||
|
||
est$beta = beta1 | ||
est$intercept = intcpt | ||
est$Y = Y | ||
est$X = X | ||
est$lambda = lambda | ||
est$nlambda = nlambda | ||
est$sparsity = sparsity | ||
est$method = method | ||
est$q = q | ||
est$ite =out$ite | ||
est$verbose = verbose | ||
est$runtime = runt | ||
class(est) = "slim" | ||
return(est) | ||
} | ||
|
||
print.slim <- function(x, ...) | ||
{ | ||
cat("\n slim options summary: \n") | ||
cat(x$nlambda, " lambdas used:\n") | ||
print(signif(x$lambda,digits=3)) | ||
cat("Method=", x$method, "\n") | ||
if(x$method=="lq"){ | ||
if(x$q==1){ | ||
cat("q=",x$q," loss, LAD Lasso\n") | ||
} else { | ||
if(x$q==2) | ||
cat("q=",x$q," loss, SQRT Lasso\n") | ||
else | ||
cat("q=",x$q," loss\n") | ||
} | ||
} | ||
cat("Sparsity level:",min(x$sparsity),"----->",max(x$sparsity),"\n") | ||
if(units.difftime(x$runtime)=="secs") unit="secs" | ||
if(units.difftime(x$runtime)=="mins") unit="mins" | ||
if(units.difftime(x$runtime)=="hours") unit="hours" | ||
cat("Runtime:",x$runtime," ",unit,"\n") | ||
} | ||
|
||
plot.slim <- function(x, ...) | ||
{ | ||
matplot(x$lambda, t(x$beta), type="l", main="Regularization Path", | ||
xlab="Regularization Parameter", ylab="Coefficient") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#----------------------------------------------------------------------------------# | ||
# Package: camel # | ||
# camel.slim.dantzig.mfista(): Regression with Dantzig Lasso() # | ||
# Author: Xingguo Li # | ||
# Email: <xingguo.leo@gmail.com> # | ||
# Date: Aug 23th, 2013 # | ||
# Version: 0.1.0 # | ||
#----------------------------------------------------------------------------------# | ||
|
||
camel.slim.dantzig.mfista <- function(Y, X, lambda, nlambda, n, d, maxdf, mu, max.ite, prec,intercept,verbose) | ||
{ | ||
if(verbose==TRUE) | ||
cat("Dantzig Lasso regression via MFISTA.\n") | ||
Y = t(X)%*%Y | ||
X = t(X)%*%X | ||
XX = t(X)%*%X | ||
# L = norm(XX,type="F") | ||
L = eigen(XX)$values[1] | ||
beta = array(0,dim=c(d,nlambda)) | ||
ite.ext.init = rep(0,nlambda) | ||
ite.ext.ex = rep(0,nlambda) | ||
ite.ext.in = rep(0,nlambda) | ||
if(intercept) intercept=1 | ||
else intercept=0 | ||
begt=Sys.time() | ||
str=.C("slim_dantzig_mfista", as.double(Y), as.double(X), | ||
as.double(beta), as.integer(n), as.integer(d), as.double(mu), | ||
as.integer(ite.ext.init), as.integer(ite.ext.ex), | ||
as.integer(ite.ext.in), as.double(lambda), as.integer(nlambda), | ||
as.integer(max.ite), as.double(prec), as.double(L), | ||
as.integer(intercept),PACKAGE="camel") | ||
runt1=Sys.time()-begt | ||
beta.list = vector("list", nlambda) | ||
ite.ext.init = matrix(unlist(str[7]), byrow = FALSE, ncol = nlambda) | ||
ite.ext.ex = matrix(unlist(str[8]), byrow = FALSE, ncol = nlambda) | ||
ite.ext.in = matrix(unlist(str[9]), byrow = FALSE, ncol = nlambda) | ||
ite.ext = vector("list", 3) | ||
ite.ext[[1]] = ite.ext.init | ||
ite.ext[[2]] = ite.ext.ex | ||
ite.ext[[3]] = ite.ext.in | ||
for(i in 1:nlambda){ | ||
beta.i = unlist(str[3])[((i-1)*d+1):(i*d)] | ||
beta.list[[i]] = beta.i | ||
} | ||
|
||
return(list(beta=beta.list, ite=ite.ext, runt=runt1)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#----------------------------------------------------------------------------------# | ||
# Package: camel # | ||
# camel.slim.lad.mfista(): Regression with LAD Lasso() # | ||
# Author: Xingguo Li # | ||
# Email: <xingguo.leo@gmail.com> # | ||
# Date: Aug 23th, 2013 # | ||
# Version: 0.1.0 # | ||
#----------------------------------------------------------------------------------# | ||
|
||
camel.slim.lad.mfista <- function(Y, X, lambda, nlambda, n, d, maxdf, mu, max.ite, prec,intercept, verbose) | ||
{ | ||
if(verbose==TRUE) | ||
cat("LAD Lasso regression via MFISTA.\n") | ||
XX = t(X)%*%X | ||
L = eigen(XX)$values[1] | ||
beta = array(0,dim=c(d,nlambda)) | ||
ite.ext.init = rep(0,nlambda) | ||
ite.ext.ex = rep(0,nlambda) | ||
ite.ext.in = rep(0,nlambda) | ||
if(intercept) intercept=1 | ||
else intercept=0 | ||
str=.C("slim_lad_mfista", as.double(Y), as.double(X), | ||
as.double(beta), as.integer(n), as.integer(d), as.double(mu), | ||
as.integer(ite.ext.init), as.integer(ite.ext.ex), | ||
as.integer(ite.ext.in), as.double(lambda), as.integer(nlambda), | ||
as.integer(max.ite), as.double(prec), as.double(L), | ||
as.integer(intercept),PACKAGE="camel") | ||
|
||
beta.list = vector("list", nlambda) | ||
ite.ext.init = matrix(unlist(str[7]), byrow = FALSE, ncol = nlambda) | ||
ite.ext.ex = matrix(unlist(str[8]), byrow = FALSE, ncol = nlambda) | ||
ite.ext.in = matrix(unlist(str[9]), byrow = FALSE, ncol = nlambda) | ||
ite.ext = vector("list", 3) | ||
ite.ext[[1]] = ite.ext.init | ||
ite.ext[[2]] = ite.ext.ex | ||
ite.ext[[3]] = ite.ext.in | ||
for(i in 1:nlambda){ | ||
beta.i = unlist(str[3])[((i-1)*d+1):(i*d)] | ||
beta.list[[i]] = beta.i | ||
} | ||
|
||
return(list(beta=beta.list, ite=ite.ext)) | ||
} |
Oops, something went wrong.