From b2fd5448fdaa580e62c7044302bbc0244b691c21 Mon Sep 17 00:00:00 2001 From: jgabry Date: Wed, 18 Dec 2019 12:15:12 -0500 Subject: [PATCH] use skip_on_cran for some of test_loo_subsampling need to get under CRAN timing limit --- DESCRIPTION | 2 +- .../testthat/test_loo_approximate_posterior.R | 3 +- tests/testthat/test_loo_subsampling.R | 44 +++++++------------ .../test_psis_approximate_posterior.R | 13 +----- 4 files changed, 21 insertions(+), 41 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 19daadff..624af812 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: loo Type: Package Title: Efficient Leave-One-Out Cross-Validation and WAIC for Bayesian Models Version: 2.2.0 -Date: 2019-12-16 +Date: 2019-12-18 Authors@R: c(person("Aki", "Vehtari", email = "Aki.Vehtari@aalto.fi", role = c("aut")), person("Jonah", "Gabry", email = "jsg2201@columbia.edu", role = c("cre", "aut")), person("Mans", "Magnusson", role = c("aut")), diff --git a/tests/testthat/test_loo_approximate_posterior.R b/tests/testthat/test_loo_approximate_posterior.R index c9b6d738..e3adf791 100644 --- a/tests/testthat/test_loo_approximate_posterior.R +++ b/tests/testthat/test_loo_approximate_posterior.R @@ -49,7 +49,6 @@ for(j in 1:N){ test_that("loo_approximate_posterior.array works as loo_approximate_posterior.matrix", { - skip_if_not_installed("checkmate") # Create array with two "chains" log_p_mat <- matrix(log_p, nrow = (S/2), ncol = 2) @@ -86,7 +85,7 @@ test_that("loo_approximate_posterior.array works as loo_approximate_posterior.ma }) test_that("loo_approximate_posterior.function works as loo_approximate_posterior.matrix", { - skip_if_not_installed("checkmate") + # Compute aploo expect_silent(aploo1 <- loo_approximate_posterior.matrix(x = ll, log_p = log_p, log_g = log_g)) diff --git a/tests/testthat/test_loo_subsampling.R b/tests/testthat/test_loo_subsampling.R index 9c5a8c48..81ec8061 100644 --- a/tests/testthat/test_loo_subsampling.R +++ b/tests/testthat/test_loo_subsampling.R @@ -4,8 +4,6 @@ options(mc.cores = 1) context("loo_subsampling") test_that("overall loo_subampling works as expected (compared with loo) for diff_est", { - skip_if_not_installed("checkmate") - set.seed(123) N <- 1000; K <- 10; S <- 1000; a0 <- 3; b0 <- 2 p <- 0.7 @@ -91,8 +89,6 @@ test_that("overall loo_subampling works as expected (compared with loo) for diff }) test_that("loo with subsampling of all observations works as ordinary loo.", { - skip_if_not_installed("checkmate") - set.seed(123) N <- 1000; K <- 10; S <- 1000; a0 <- 3; b0 <- 2 p <- 0.7 @@ -122,8 +118,6 @@ test_that("loo with subsampling of all observations works as ordinary loo.", { }) test_that("overall loo_subsample works with diff_srs as expected (compared with loo)", { - skip_if_not_installed("checkmate") - set.seed(123) N <- 1000; K <- 10; S <- 1000; a0 <- 3; b0 <- 2 p <- 0.7 @@ -143,8 +137,6 @@ test_that("overall loo_subsample works with diff_srs as expected (compared with }) test_that("Test the srs estimator with 'none' approximation", { - skip_if_not_installed("checkmate") - set.seed(123) N <- 1000; K <- 10; S <- 1000; a0 <- 3; b0 <- 2 p <- 0.7 @@ -186,8 +178,6 @@ test_that("Test the srs estimator with 'none' approximation", { }) test_that("Test the Hansen-Hurwitz estimator", { - skip_if_not_installed("checkmate") - set.seed(123) N <- 1000; K <- 10; S <- 1000; a0 <- 3; b0 <- 2 p <- 0.7 @@ -245,7 +235,7 @@ test_that("Test the Hansen-Hurwitz estimator", { test_that("update.psis_loo_ss works as expected (compared with loo)", { - skip_if_not_installed("checkmate") + set.seed(123) N <- 1000; K <- 10; S <- 1000; a0 <- 3; b0 <- 2 @@ -344,7 +334,7 @@ test_that("update.psis_loo_ss works as expected (compared with loo)", { context("loo_subsampling_approximations") test_that("elpd_loo_approximation works as expected", { - skip_if_not_installed("checkmate") + set.seed(123) N <- 10; K <- 10; S <- 1000; a0 <- 3; b0 <- 2 @@ -396,7 +386,7 @@ test_that("elpd_loo_approximation works as expected", { test_that("Test loo_approximation_draws", { - skip_if_not_installed("checkmate") + set.seed(123) N <- 1000; K <- 10; S <- 1000; a0 <- 3; b0 <- 2 @@ -432,7 +422,7 @@ test_that("Test loo_approximation_draws", { test_that("waic using delta method and gradient", { - skip_if_not_installed("checkmate") + if (FALSE){ # Code to generate testdata - saved and loaded to avoid dependency of mvtnorm @@ -488,7 +478,7 @@ test_that("waic using delta method and gradient", { }) test_that("waic using delta 2nd order method", { - skip_if_not_installed("checkmate") + if (FALSE){ # Code to generate testdata - saved and loaded to avoid dependency of MCMCPack @@ -575,7 +565,7 @@ test_that("waic using delta 2nd order method", { context("loo_subsampling_estimation") test_that("whhest works as expected", { - skip_if_not_installed("checkmate") + N <- 100 m <- 10 @@ -636,7 +626,7 @@ test_that("whhest works as expected", { test_that("srs_diff_est works as expected", { - skip_if_not_installed("checkmate") + set.seed(1234) N <- 1000 @@ -672,7 +662,7 @@ test_that("srs_diff_est works as expected", { }) test_that("srs_est works as expected", { - skip_if_not_installed("checkmate") + set.seed(1234) # Cochran 1976 example Table 2.2 @@ -725,7 +715,8 @@ test_that("srs_est works as expected", { context("loo_subsampling cases") test_that("Test loo_subsampling and loo_approx with radon data", { - skip_if_not_installed("checkmate") + skip_on_cran() # avoid going over time limit for tests + load(test_path("test_radon_laplace_loo.rda")) # Rename to spot variable leaking errors llfun_test <- llfun @@ -833,13 +824,14 @@ test_that("Test loo_subsampling and loo_approx with radon data", { test_that("Test the vignette", { - skip_if_not_installed("checkmate") + skip_on_cran() + # NOTE # If any of these test fails, the vignette probably needs to be updated - if (FALSE){ - # Generate vignett test case + if (FALSE) { + # Generate vignette test case library("rstan") stan_code <- " data { @@ -986,7 +978,7 @@ test_that("Test the vignette", { context("loo_compare_subsample") test_that("loo_compare_subsample", { - skip_if_not_installed("checkmate") + skip_on_cran() # to get under cran check time limit set.seed(123) N <- 1000 @@ -1067,9 +1059,10 @@ test_that("loo_compare_subsample", { }) +context("subsample with tis, sis") test_that("Test 'tis' and 'sis'", { - skip_if_not_installed("checkmate") + skip_on_cran() set.seed(123) N <- 1000; K <- 10; S <- 1000; a0 <- 3; b0 <- 2 @@ -1160,6 +1153,3 @@ test_that("Test 'tis' and 'sis'", { expect_gt(loo_ss_sis_S10$estimates["elpd_loo", "Estimate"] + SEs*loo_ss_sis_S10$estimates["elpd_loo", "subsampling SE"], loo_ss_full$estimates["elpd_loo", "Estimate"]) expect_lt(loo_ss_sis_S10$estimates["elpd_loo", "Estimate"] - SEs*loo_ss_sis_S10$estimates["elpd_loo", "subsampling SE"], loo_ss_full$estimates["elpd_loo", "Estimate"]) }) - - - diff --git a/tests/testthat/test_psis_approximate_posterior.R b/tests/testthat/test_psis_approximate_posterior.R index e169f443..ab0160ae 100644 --- a/tests/testthat/test_psis_approximate_posterior.R +++ b/tests/testthat/test_psis_approximate_posterior.R @@ -5,7 +5,6 @@ context("psis_approximate_posterior") load(test_path("test_data_psis_approximate_posterior.rda")) test_that("Laplace approximation, independent posterior", { - skip_if_not_installed("checkmate") log_p <- test_data_psis_approximate_posterior$laplace_independent$log_p log_g <- test_data_psis_approximate_posterior$laplace_independent$log_q ll <- test_data_psis_approximate_posterior$laplace_independent$log_liks @@ -26,7 +25,6 @@ test_that("Laplace approximation, independent posterior", { test_that("Laplace approximation, correlated posterior", { - skip_if_not_installed("checkmate") log_p <- test_data_psis_approximate_posterior$laplace_correlated$log_p log_g <- test_data_psis_approximate_posterior$laplace_correlated$log_q ll <- test_data_psis_approximate_posterior$laplace_correlated$log_liks @@ -46,7 +44,6 @@ test_that("Laplace approximation, correlated posterior", { }) test_that("Laplace approximation, normal model", { - skip_if_not_installed("checkmate") log_p <- test_data_psis_approximate_posterior$laplace_normal$log_p log_g <- test_data_psis_approximate_posterior$laplace_normal$log_q ll <- test_data_psis_approximate_posterior$laplace_normal$log_liks @@ -68,7 +65,6 @@ test_that("Laplace approximation, normal model", { test_that("ADVI fullrank approximation, independent posterior", { - skip_if_not_installed("checkmate") log_p <- test_data_psis_approximate_posterior$fullrank_independent$log_p log_g <- test_data_psis_approximate_posterior$fullrank_independent$log_q ll <- test_data_psis_approximate_posterior$fullrank_independent$log_liks @@ -89,7 +85,6 @@ test_that("ADVI fullrank approximation, independent posterior", { test_that("ADVI fullrank approximation, correlated posterior", { - skip_if_not_installed("checkmate") log_p <- test_data_psis_approximate_posterior$fullrank_correlated$log_p log_g <- test_data_psis_approximate_posterior$fullrank_correlated$log_q ll <- test_data_psis_approximate_posterior$fullrank_correlated$log_liks @@ -109,7 +104,6 @@ test_that("ADVI fullrank approximation, correlated posterior", { }) test_that("ADVI fullrank approximation, correlated posterior", { - skip_if_not_installed("checkmate") log_p <- test_data_psis_approximate_posterior$fullrank_normal$log_p log_g <- test_data_psis_approximate_posterior$fullrank_normal$log_q ll <- test_data_psis_approximate_posterior$fullrank_normal$log_liks @@ -130,7 +124,6 @@ test_that("ADVI fullrank approximation, correlated posterior", { test_that("ADVI meanfield approximation, independent posterior", { - skip_if_not_installed("checkmate") log_p <- test_data_psis_approximate_posterior$meanfield_independent$log_p log_g <- test_data_psis_approximate_posterior$meanfield_independent$log_q ll <- test_data_psis_approximate_posterior$meanfield_independent$log_liks @@ -151,7 +144,6 @@ test_that("ADVI meanfield approximation, independent posterior", { test_that("ADVI meanfield approximation, correlated posterior", { - skip_if_not_installed("checkmate") log_p <- test_data_psis_approximate_posterior$meanfield_correlated$log_p log_g <- test_data_psis_approximate_posterior$meanfield_correlated$log_q ll <- test_data_psis_approximate_posterior$meanfield_correlated$log_liks @@ -172,7 +164,6 @@ test_that("ADVI meanfield approximation, correlated posterior", { }) test_that("ADVI meanfield approximation, normal model", { - skip_if_not_installed("checkmate") log_p <- test_data_psis_approximate_posterior$meanfield_normal$log_p log_g <- test_data_psis_approximate_posterior$meanfield_normal$log_q ll <- test_data_psis_approximate_posterior$meanfield_normal$log_liks @@ -193,7 +184,7 @@ test_that("ADVI meanfield approximation, normal model", { test_that("ADVI meanfield approximation, normal model", { - skip_if_not_installed("checkmate") + log_p <- test_data_psis_approximate_posterior$meanfield_normal$log_p log_g <- test_data_psis_approximate_posterior$meanfield_normal$log_q ll <- test_data_psis_approximate_posterior$meanfield_normal$log_liks @@ -214,7 +205,7 @@ test_that("ADVI meanfield approximation, normal model", { test_that("Deprecation of log_q argument", { - skip_if_not_installed("checkmate") + log_p <- test_data_psis_approximate_posterior$laplace_independent$log_p log_g <- test_data_psis_approximate_posterior$laplace_independent$log_q ll <- test_data_psis_approximate_posterior$laplace_independent$log_liks