diff --git a/DESCRIPTION b/DESCRIPTION index ca72e16..d258b2d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,19 +1,18 @@ Package: fastclime Type: Package -Title: A fast solver for constrained l1 minimization approach to sparse - precision matrix estimation -Version: 1.1 -Date: 2013-06-18 +Title: A fast solver for parameterized lp problems and constrained l1 + minimization approach to sparse precision matrix estimation +Version: 1.2 +Date: 2013-07-11 Author: Haotian Pang, Han Liu and Robert Vanderbei Maintainer: Haotian Pang Depends: R (>= 2.15.0), lattice, igraph, MASS, Matrix Description: The package "fastclime" provides a method of recover the precision matrix efficiently by applying parametric simplex method. The computation is based on a linear optimization - solver. It also contains a generic LP solver using parametric - simplex method. + solver. It also contains a generic LP solver and a parameterized LP solver using parametric simplex method. License: GPL-2 Repository: CRAN -Packaged: 2013-06-18 23:15:32 UTC; haotian +Packaged: 2013-07-11 18:46:54 UTC; haotian NeedsCompilation: yes -Date/Publication: 2013-06-19 08:49:27 +Date/Publication: 2013-07-12 07:28:25 diff --git a/MD5 b/MD5 index 22f2e71..97ca292 100644 --- a/MD5 +++ b/MD5 @@ -1,20 +1,21 @@ -ef9be5f3e5a7e6bcc107597a7e8fbf94 *DESCRIPTION -8b1385871523f9e979f7b0b69cc720a2 *NAMESPACE -aadbd9dcbf1b733d80f9961eff81e690 *R/fastclime.R -8ebabce6fbf0ec5a5cea556fb5d7ce58 *R/fastclime.generator.R -f7fe243272e90e5599a05566d39e2cc0 *R/fastclime.plot.R -546eeb0435048784d1ec66cb99c38d65 *R/fastclime.roc.R -c2c02d8b30ac90676fbe6179b213d98b *R/fastlp.R +33d765adc24fda3448594a262c6a8e1f *DESCRIPTION +5bbd7fd82971d5bddb5c6d1efa208758 *NAMESPACE +c3338f877a71ecd1bbd93f66d1787ed0 *R/fastclime.R +32de2eb45c5a4cd735f1449870056282 *R/fastclime.generator.R +a179fc740230d2b6702050ae8972757b *R/fastclime.plot.R +46ab6431d4c6b002a6da2cd699a5f9e5 *R/fastclime.roc.R +b9a85abba7b7af3cd0c04bc677563dd1 *R/fastlp.R +b6acdd1a7e73c9908a19e070fbf59a99 *R/paralp.R ec90576375b24e35502847bdd1d85b6e *data/stockdata.rda -18fca9443d532169d44c2d0dcd7fa8f5 *inst/doc/fastclime.pdf 9cf23fc8036ec97c902be03c40a08490 *inst/doc/vignette.Rnw -dfb9b711d987b84cc3523cf27a71b85b *inst/doc/vignette.pdf -457de96fcd3cfdc20abaee85fd75053e *man/fastclime-package.Rd +acb36b4fa4a40327ef852da5a5ffad1c *inst/doc/vignette.pdf +ac3cc2f9c850519fd3916973d120c492 *man/fastclime-package.Rd c964cd215020211b41c9abdaec9a24b3 *man/fastclime.Rd f13eef1099b8dad1091dd5764e6b6eb5 *man/fastclime.generator.Rd 64307ab02e80b23986e1f4446aa316c6 *man/fastclime.plot.Rd 05d72f126d24f37636432aa948c6f48a *man/fastclime.roc.Rd 35a34d4b383d8d9798b754ca6ebd808b *man/fastlp.Rd +e45d01c047c1c70cd41af8adb55ec220 *man/paralp.Rd 4fede98f1e2ad5f3ee859ea58504be85 *man/plot.fastclime.Rd a1d5732ba3621562c4e5d92cd57b1b31 *man/plot.roc.Rd 66a8b6d1673d092cb2d2e15434493e3e *man/plot.sim.Rd @@ -32,6 +33,9 @@ c5217e444b843a5a358b905e6cb1c975 *src/linalg.c f27fb8d738a94ff945bf48498eeee3ab *src/lu.h abc0a80ca8d0260b12e96ba9f9df608f *src/macros.h e1be8277ecf906d37bc71e80fb591490 *src/myalloc.h +dec22a96f3a55c4d15b0e2dcdf0f1e29 *src/paralp.c 236bcdaa0532e3454d61fec79f0648d7 *src/parametric.c 38e9ff9c3d2f5b3b832010d120069caf *src/tree.c ebd8db35929bc9a80f444621e0e0f909 *src/tree.h +cccf1b335989a7951ed1f1f1a80142a1 *vignettes/fastclime.pdf +9cf23fc8036ec97c902be03c40a08490 *vignettes/vignette.Rnw diff --git a/NAMESPACE b/NAMESPACE index c3673e4..aa64fa9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,7 +7,8 @@ export(fastclime, print.fastclime,plot.fastclime, print.roc,plot.roc, print.sim,plot.sim, - fastlp + fastlp, + paralp ) S3method("print","roc") diff --git a/R/fastclime.R b/R/fastclime.R index d62041f..21e9e0e 100644 --- a/R/fastclime.R +++ b/R/fastclime.R @@ -3,8 +3,8 @@ # fastclime(): Main Function # # Authors: Haotian Pang, Han Liu and Robert Vanderbei # # Emails: , and # -# Date: Jun 18th 2013 # -# Version: 1.1 # +# Date: Jul 11th 2013 # +# Version: 1.2 # #-------------------------------------------------------------------------------# fastclime <- function(x, lambda.min.ratio = NULL, nlambda = 50) { diff --git a/R/fastclime.generator.R b/R/fastclime.generator.R index 1f7a724..ffacd10 100644 --- a/R/fastclime.generator.R +++ b/R/fastclime.generator.R @@ -3,8 +3,8 @@ # fastclime.generator(): Data generator # # Authors: Haotian Pang, Han Liu and Robert Vanderbei # # Emails: , and # -# Date: Jun 18th 2013 # -# Version: 1.1 # +# Date: Jul 11th 2013 # +# Version: 1.2 # #-------------------------------------------------------------------------------# ## Main function diff --git a/R/fastclime.plot.R b/R/fastclime.plot.R index 900ce7e..e14dd8d 100644 --- a/R/fastclime.plot.R +++ b/R/fastclime.plot.R @@ -3,8 +3,8 @@ # fastclime.generator(): graph visualization # # Authors: Haotian Pang, Han Liu and Robert Vanderbei # # Emails: , and # -# Date: Jun 18th 2013 # -# Version: 1.1 # +# Date: Jul 11th 2013 # +# Version: 1.2 # #-------------------------------------------------------------------------------# fastclime.plot = function(G, epsflag = FALSE, graph.name = "default", cur.num = 1, location=NULL){ diff --git a/R/fastclime.roc.R b/R/fastclime.roc.R index d9192c6..18e4987 100644 --- a/R/fastclime.roc.R +++ b/R/fastclime.roc.R @@ -4,8 +4,8 @@ # The ground truth is required # # Authors: Haotian Pang, Han Liu and Robert Vanderbei # # Emails: , and # -# Date: Jun 18th 2013 # -# Version: 1.1 # +# Date: Jul 11th 2013 # +# Version: 1.2 # #-------------------------------------------------------------------------------# fastclime.roc = function(path, theta, verbose = TRUE){ diff --git a/R/fastlp.R b/R/fastlp.R index 8eb384c..ca3c689 100644 --- a/R/fastlp.R +++ b/R/fastlp.R @@ -3,8 +3,8 @@ # fastclp(): A parametric simplex LP solver # # Authors: Haotian Pang, Han Liu and Robert Vanderbei # # Emails: , and # -# Date: Jun 18th 2013 # -# Version: 1.1 # +# Date: Jul 11th 2013 # +# Version: 1.2 # #-------------------------------------------------------------------------------# fastlp <- function(obj, mat, rhs,lambda=0){ diff --git a/R/paralp.R b/R/paralp.R new file mode 100644 index 0000000..788a8c2 --- /dev/null +++ b/R/paralp.R @@ -0,0 +1,73 @@ +#-------------------------------------------------------------------------------# +# Package: fastclime # +# fastclp(): A parametric simplex LP solver for parameterized LP problems # +# Authors: Haotian Pang, Han Liu and Robert Vanderbei # +# Emails: , and # +# Date: Jul 11th 2013 # +# Version: 1.2 # +#-------------------------------------------------------------------------------# + +paralp <- function(obj, mat, rhs, obj_bar, rhs_bar, lambda=0){ + + m<-length(rhs) + n<-length(obj) + m1<-length(rhs_bar) + n1<-length(obj_bar) + m0<-dim(mat)[1] + n0<-dim(mat)[2] + + opt<-rep(0,n) + status<-0 + error<-0 + + if (m!=m0 || n!=n0 || m!=m1 || n!=n1){ + cat("Dimensions do not match! \n") + error<-1 + } + + if (any(obj_bar<0) || any(rhs_bar<0)){ + + cat("The pertubation vector obj_bar and rhs_bar must be nonnegative! \n") + error<-2 + + } + + if (error==0){ + str=.C("paralp", as.double(obj), as.double(t(mat)), as.double(rhs), as.integer(m0), as.integer(n0), as.double(opt), as.integer(status), as.double(lambda), as.double(rhs_bar), as.double(obj_bar), PACKAGE="fastclime") + + + opt<-unlist(str[6]) + status<-unlist(str[7]) + + if (status==0){ + cat("optimal solution found! \n") + return(opt) + } + + else if(status ==1){ + cat("The problem is infeasible! \n") + } + + else if(status ==2){ + cat("The problem is unbounded! \n") + } + + } + + +} + + + + + + + + + + + + + + + diff --git a/inst/doc/fastclime.pdf b/inst/doc/fastclime.pdf deleted file mode 100644 index c6c683f..0000000 Binary files a/inst/doc/fastclime.pdf and /dev/null differ diff --git a/inst/doc/vignette.pdf b/inst/doc/vignette.pdf index 4207fa3..ab04b85 100644 Binary files a/inst/doc/vignette.pdf and b/inst/doc/vignette.pdf differ diff --git a/man/fastclime-package.Rd b/man/fastclime-package.Rd index 5b15da5..4f710e3 100644 --- a/man/fastclime-package.Rd +++ b/man/fastclime-package.Rd @@ -2,10 +2,10 @@ \alias{fastclime-package} \docType{package} \title{ -Fast Parametric Simplex Solver for CLIME +Fast Parametric Simplex Solver for CLIME and Linear Programming } \description{ -A package for constrainted l1 minimization approach to sparse precision matrix estimation +A package for generic linear programming, parameterized linear programming and constrainted l1 minimization approach to sparse precision matrix estimation } \details{ \tabular{ll}{ @@ -16,14 +16,16 @@ Date: \tab 2013-05-27\cr License: \tab GPL-2\cr LazyLoad: \tab yes\cr } -The package "fastclime" provides 2 main functions:\cr +The package "fastclime" provides 3 main functions:\cr (1) the data generator creates random samples from multivariate normal distributions with different graph structures. Please refer to \code{\link{fastclime.generator}}.\cr (2) The parametric simplex solver for constrainted l1 minimization approach to sparse precision matrix estimation. Please refer to \code{\link{fastclime}}.\cr +(3) A generic linear programming solver and a parameterized linear programming solver. Please refer to \code{\link{fastlp}} and \code{\link{paralp}}.\cr } \author{ Haotian Pang, Han Liu and Robert Vanderbei \cr Maintainer: Haotan Pang; } + \seealso{ -\code{\link{fastclime.generator}}, \code{\link{fastclime}}, \code{\link{fastclime.plot}} and \code{\link{fastclime.roc}} +\code{\link{fastclime.generator}}, \code{\link{fastclime}}, \code{\link{fastclime.plot}} and \code{\link{fastclime.roc}}, \code{\link{fastlp}}, \code{\link{paralp}} } diff --git a/man/paralp.Rd b/man/paralp.Rd new file mode 100644 index 0000000..f0914eb --- /dev/null +++ b/man/paralp.Rd @@ -0,0 +1,66 @@ +\name{paralp} +\alias{paralp} + +\title{ +A solver for parameterized LP problems +} + +\description{ +A parameterized linear programming solver using parametric simplex method +} + +\usage{ +paralp(obj,mat,rhs,obj_bar,rhs_bar,lambda=0) +} + +\arguments{ + \item{obj}{ +The objective vector of the coefficient with length n. +} + \item{mat}{ +The constraint matrix of the linear programming with dimension m*n. Note this argument must be in matrix form even it is a vector. +} + \item{rhs}{ +The right hand side vector of the constraint with length m. +} + + \item{obj_bar}{ +The vector used to time the parameter and added to the objective vector, with length n. This pertubation vector must be nonnegative. +} + + \item{rhs_bar}{ +The vector used to time the parameter and added to the right hand side vector, with length m. This pertubation vector must be nonnegative. +} + + \item{lambda}{ +The parametric simplex method will stop when the calculated paramter is smaller than lambda. The default value is zero and it corresponds to the optimal value. +} +} + +\details{ +This function is used to solve a general linear programming in standard inequality form: "maximize obj*x+obj_bar*lambda, subject to: mat*x<=rhs+rhs_bar*lambda, x>=0" +} + + +\value{ +The optimal value will be returned if it exists with a proper value of chosen lambda. Otherwise the function will indicate the problem is infeasible or unbounded. +} + +\author{ +Haotian Pang, Han Liu and Robert Vanderbei \cr +Maintainer: Haotan Pang +} + +\seealso{ +\code{\link{fastclime}} and \code{\link{fastclime-package}} +} + +\examples{ +#generate an LP problem and solve it +A=matrix(c(-1,-1,0,1,-2,1),nrow=3) +b=c(-1,-2,1) +c=c(-2,3) +b_bar=c(1,1,1) +c_bar=c(1,1) +paralp(c,A,b,c_bar,b_bar) +} diff --git a/src/paralp.c b/src/paralp.c new file mode 100644 index 0000000..85d3b0a --- /dev/null +++ b/src/paralp.c @@ -0,0 +1,521 @@ +/***************************************************************************** + + Implementation of the + Primal Dual (i.e. Self Dual) Simplex Method Linear Programming Solver for R + R. Vanderbei & H. Pang, June 2013 + +******************************************************************************/ +#include +#include +#include +#include + +#include "myalloc.h" +#include "lu.h" +#include "linalg.h" +#include "macros.h" + + +#define EPS1 1.0e-8 +#define EPS2 1.0e-12 +#define EPS3 1.0e-5 +#define MAX_ITER 1000000 + +static int status0; +static int lambda0; +static double *x; +static double pi = 3.14159265359; +static double *c_bar; +static double *b_bar; + +int ratio_test1( + double *dy, + int *idy, + int ndy, + double *y, + double *ybar, + double mu +); + + +void solver21( + int m, /* number of constraints */ + int n, /* number of variables */ + int nz, /* number of nonzeros in sparse constraint matrix */ + int *ia, /* array row indices */ + int *ka, /* array of indices into ia and a */ + double *a, /* array of nonzeros in the constraint matrix */ + double *b, /* right-hand side */ + double *c /* objective coefficients */ + ); + + + +void paralp(double *obj, double *mat, double *rhs, int *m0 , int *n0, double *opt, int *status, double *lambda, double *rhs_bar, double *obj_bar) +{ + + int m=*m0; /* number of constraints */ + int n=*n0; /* number of variables */ + int nz=0; /* number of nonzeros in sparse constraint matrix */ + int *ia; /* array row indices */ + int *ka; /* array of indices into ia and a */ + double *a; /* array of nonzeros in the constraint matrix */ + double *b; /* right-hand side */ + double *c; /* objective coefficients */ + int i, j, k; + status0 = *status; + lambda0 = *lambda; + + if(lambda0<=EPS3){ + lambda0=EPS3; + } + + + MALLOC( a, m*n+m, double ); + MALLOC( ia, m*n+m, int ); + MALLOC( ka, n+m+1, int ); + MALLOC( c, n, double ); + MALLOC( b, m, double ); + MALLOC( c_bar, n, double ); + MALLOC( b_bar, m, double ); + + /***************************************************************** + * Structure of the problem: + + ***************************************************************/ + + for (i=0;i EPS2) { + if ( mu < -y_N[j]/ybar_N[j] ) { + mu = -y_N[j]/ybar_N[j]; + col_in = j; + } + } + } + col_out = -1; + + for (i=0; i EPS2) { + if ( mu < -x_B[i]/xbar_B[i] ) { + mu = -x_B[i]/xbar_B[i]; + col_out = i; + col_in = -1; + } + } + } + + if ( mu <= lambda0 ) { /* optimal */ + status0=0; + break; + + } + + /************************************************************* + * -1 t * + * step 2: compute dy = -(b n) e * + * n i * + * where i = col_out * + *************************************************************/ + if ( col_out >= 0 ) { + vec[0] = -1.0; + ivec[0] = col_out; + nvec = 1; + + btsolve( m, vec, ivec, &nvec ); + Nt_times_y( N, at, iat, kat, basicflag, vec, ivec, nvec, + dy_N, idy_N, &ndy_N ); + + col_in = ratio_test0( dy_N, idy_N, ndy_N, y_N, ybar_N,mu ); + + /************************************************************* + * STEP 3: Ratio test to find entering column * + *************************************************************/ + + if (col_in == -1) { /* infeasible */ + status0 = 1; + break; + } + + /************************************************************* + * -1 * + * step 4: compute dx = b n e * + * b j * + * * + *************************************************************/ + + j = nonbasics[col_in]; + for (i=0, k=ka[j]; k=1){ + Nt_times_y( -1, at, iat, kat, basicflag, vec, ivec, nvec, + dy_N, idy_N, &ndy_N ); + } + + + /**************************************************************** + * free work space * + ****************************************************************/ + + FREE( vec ); + FREE( ivec ); + FREE( x_B ); + FREE( y_N ); + FREE( dx_B ); + FREE(idx_B ); + FREE( dy_N ); + FREE(idy_N ); + FREE(xbar_B); + FREE(ybar_N); + FREE( nonbasics ); + FREE( basics ); + FREE(at); + FREE(iat); + FREE(basicflag); + FREE(kat); + + if(iter>=1){ + lu_clo(); + btsolve(0, vec, ivec, &nvec); + bsolve(0, vec, ivec, &nvec); + } + + +} + + + +int ratio_test1( + double *dy, + int *idy, + int ndy, + double *y, + double *ybar, + double mu +) +{ + int j, jj = -1, k; + double min = HUGE_VAL; + + for (k=0; k EPS1 ) { + j = idy[k]; + if ( (y[j] + mu*ybar[j])/dy[k] < min ) { + min = (y[j] + mu*ybar[j])/dy[k]; + jj = j; + } + } + } + + return jj; +} + + + + + + + + + + + + diff --git a/vignettes/fastclime.pdf b/vignettes/fastclime.pdf new file mode 100644 index 0000000..b865cd8 Binary files /dev/null and b/vignettes/fastclime.pdf differ diff --git a/vignettes/vignette.Rnw b/vignettes/vignette.Rnw new file mode 100644 index 0000000..97fa934 --- /dev/null +++ b/vignettes/vignette.Rnw @@ -0,0 +1,10 @@ +% \VignetteIndexEntry{vignette} +% \VignetteKeywords{keywords here} +% \VignettePackage{package name} + +\documentclass[a4paper]{article} +\usepackage{hyperref} +\usepackage{pdfpages} +\begin{document} +\includepdf[fitpaper=true,pages=-]{fastclime.pdf} +\end{document}