knitr::opts_chunk$set(echo = TRUE)

Microbenchmark

We want to assess the performance in times of several penalized methods.

Sparse matrix function :

rSpMatrix <- function(nrow, ncol, nnz,
                      rand.x = function(nnz) round(rnorm(nnz), 2))
{
  ## Purpose: random sparse matrix
  ## --------------------------------------------------------------
  ## Arguments: (nrow,ncol): dimension
  ##          nnz  :  number of non-zero entries
  ##         rand.x:  random number generator for 'x' slot
  ## --------------------------------------------------------------
  ## Author: Martin Maechler, Date: 14.-16. May 2007
  stopifnot((nnz <- as.integer(nnz)) >= 0,
            nrow >= 0, ncol >= 0, nnz <= nrow * ncol)
  spMatrix(nrow, ncol,
                   i = sample(nrow, nnz, replace = TRUE),
                   j = sample(ncol, nnz, replace = TRUE),
                   x = rand.x(nnz))
}
set.seed(33)
library(PintMF)
W <- rbind(diag(1, nrow = 3, ncol = 3), diag(1, nrow = 3, ncol = 3))
H1 <- as.matrix(rSpMatrix(3, 100, nnz = 20, rand.x= function(nnz) round(rnorm(nnz, 2, 0.2), 2) ))
Y1 <- as.matrix(W%*%H1 + rnorm(20, sd=1))
library(microbenchmark)
mbm = microbenchmark(
  glmnet = PintMF::get.H(W, Y1, flavor_mod = "glmnet", verbose=TRUE),
  ncvreg = PintMF::get.H(W, Y1, flavor_mod = "ncvreg", verbose=TRUE),
  bigmemory = PintMF::get.H(W, Y1, flavor_mod = "biglasso", verbose=TRUE),
  quadrupen = PintMF::get.H(W, Y1, flavor_mod = "quadrupen", verbose=TRUE),times = 20L
)
library(ggplot2)
g <- autoplot(mbm)+theme_bw()
gg <- g+theme(axis.text.y = element_text(size=15), axis.text.x = element_text(size=15),
         axis.title.x = element_text(size=15))
library(dplyr)
gg %>% ggsave(filename = "../Figs/eval_perf_lasso.pdf", width = 6, height = 6)


CNRGH/pintmf documentation built on Feb. 23, 2022, 12:02 a.m.