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)
## Unit: milliseconds
## expr min lq mean
## CVglasso(S = sample, lam = 0.1, trace = "none") 29.60706 42.64544 43.30661
## median uq max neval
## 42.7172 43.70179 70.14059 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") 46.91339 73.53546
## mean median uq max neval
## 74.94168 73.62978 74.56472 128.0984 100
lam
:# 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.55624 1.556322 1.564094 1.55681 1.574553
## max neval
## 1.576546 5
cores = 2
) cross validation:## Unit: seconds
## expr min lq mean median
## CVglasso(X, cores = 2, trace = "none") 2.596927 2.798708 3.676401 2.890247
## uq max neval
## 4.840616 5.255505 5