Skip to content

Commit

Permalink
use skip_on_cran for some of test_loo_subsampling
Browse files Browse the repository at this point in the history
need to get under CRAN timing limit
  • Loading branch information
jgabry committed Dec 18, 2019
1 parent bed437f commit b2fd544
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 41 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]", role = c("aut")),
person("Jonah", "Gabry", email = "[email protected]", role = c("cre", "aut")),
person("Mans", "Magnusson", role = c("aut")),
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test_loo_approximate_posterior.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
44 changes: 17 additions & 27 deletions tests/testthat/test_loo_subsampling.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"])
})



13 changes: 2 additions & 11 deletions tests/testthat/test_psis_approximate_posterior.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b2fd544

Please sign in to comment.