Benchmarks

This is a short effort to give users an idea of how long the functions take to process. The benchmarks were performed using the default R install on Travis CI.

We will be estimating a tri-diagonal precision matrix with dimension p = 100:


library(CVglasso)
library(microbenchmark)

#  generate data from tri-diagonal (sparse) matrix
# compute covariance matrix (can confirm inverse is tri-diagonal)
S = matrix(0, nrow = 100, ncol = 100)

for (i in 1:100){
  for (j in 1:100){
    S[i, j] = 0.7^(abs(i - j))
  }
}

# generate 1000 x 100 matrix with rows drawn from iid N_p(0, S)
set.seed(123)
Z = matrix(rnorm(1000*100), nrow = 1000, ncol = 100)
out = eigen(S, symmetric = TRUE)
S.sqrt = out$vectors %*% diag(out$values^0.5) %*% t(out$vectors)
X = Z %*% S.sqrt

# calculate sample covariance matrix
sample = (nrow(X) - 1)/nrow(X)*cov(X)



# benchmark CVglasso - defaults
microbenchmark(CVglasso(S = sample, lam = 0.1, trace = "none"))
## Unit: milliseconds
##                                             expr     min       lq     mean
##  CVglasso(S = sample, lam = 0.1, trace = "none") 33.6526 42.90989 43.23009
##   median      uq      max neval
##  42.9649 43.9012 46.71001   100



# benchmark CVglasso - tolerance 1e-6
microbenchmark(CVglasso(S = sample, lam = 0.1, tol = 1e-6, trace = "none"))
## Unit: milliseconds
##                                                          expr      min       lq
##  CVglasso(S = sample, lam = 0.1, tol = 1e-06, trace = "none") 49.07459 75.15099
##      mean   median       uq      max neval
##  75.89949 75.22105 76.14677 126.3361   100



# benchmark CVglasso CV - default parameter grid
microbenchmark(CVglasso(X, trace = "none"), times = 5)
## Unit: seconds
##                         expr     min       lq     mean   median       uq
##  CVglasso(X, trace = "none") 1.59354 1.593694 1.614119 1.600722 1.624241
##       max neval
##  1.658398     5



# benchmark CVglasso parallel CV
microbenchmark(CVglasso(X, cores = 2, trace = "none"), times = 5)
## Unit: seconds
##                                    expr     min       lq     mean   median
##  CVglasso(X, cores = 2, trace = "none") 3.60557 3.787998 7.213642 4.919538
##        uq      max neval
##  10.19912 13.55599     5