diff --git a/DESCRIPTION b/DESCRIPTION index dd63b830..0ea92de6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: bssm Type: Package Title: Bayesian Inference of Non-Linear and Non-Gaussian State Space Models -Version: 1.1.7 +Version: 1.1.7-1 Authors@R: c(person(given = "Jouni", family = "Helske", @@ -41,7 +41,7 @@ Suggests: Imports: checkmate, coda (>= 0.18-1), diagis, Rcpp (>= 0.12.3) LinkingTo: Rcpp, RcppArmadillo, ramcmc, sitmo SystemRequirements: C++11, pandoc (>= 1.12.3, needed for vignettes) -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 VignetteBuilder: knitr BugReports: https://github.com/helske/bssm/issues URL: https://github.com/helske/bssm diff --git a/NEWS b/NEWS index 8d326ac8..934f41c2 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,8 @@ -bssm 1.1.7 (Release date: 2021-09-15) +bssm 1.1.7-1 (Release date: 2021-09-21) +============== + * Fixed an error in automatic tests due to lack of fixed RNG seed. + +bssm 1.1.7 (Release date: 2021-09-20) ============== * Added a function cpp_example_model which can be used to extract and compile some non-linear and SDE models used in the examples and vignettes. diff --git a/R/predict.R b/R/predict.R index c37b86bc..7f999a8b 100644 --- a/R/predict.R +++ b/R/predict.R @@ -22,7 +22,9 @@ #' future, using posterior samples of (theta, alpha_T+1) i.e. the #' posterior samples of hyperparameters and latest states. #' Otherwise it is assumed that \code{model} corresponds to the original model. -#' @param seed Seed for RNG (positive integer). +#' @param seed Seed for RNG (positive integer). Note that this affects only the +#' C++ side, and \code{predict} also uses R side RNG for subsampling, so for +#' replicable results you should call \code{set.seed} before \code{predict}. #' @param ... Ignored. #' @return A \code{data.frame} consisting of samples from the predictive #' posterior distribution. diff --git a/README.md b/README.md index 12fa5309..871c8880 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,22 @@ devtools::install_github("helske/bssm") Recent changes (For all changes, see NEWS file.) ========================================================================== -bssm 1.1.6 (Release date: ) +bssm 1.1.7-1 (Release date: 2021-09-21) +============== + * Fixed an error in automatic tests due to lack of fixed RNG seed. + +bssm 1.1.7 (Release date: 2021-09-20) +============== + * Added a function cpp_example_model which can be used to extract and + compile some non-linear and SDE models used in the examples and vignettes. + * Added as_draws method for run_mcmc output so samples can be analysed using + the posterior package. + * Added more examples. + * Fixed a tolerance of one MCMC test to pass the test on OSX as well. + * Fixed a bug in iterated extended Kalman smoothing which resulted incorrect + estimates. + +bssm 1.1.6 (Release date: 2021-09-06) ============== * Cleaned codes and added more comprehensive tests in line with pkgcheck tests. This resulted in finding and fixing multiple bugs: diff --git a/man/predict.mcmc_output.Rd b/man/predict.mcmc_output.Rd index 27e36f3c..a98e2b67 100644 --- a/man/predict.mcmc_output.Rd +++ b/man/predict.mcmc_output.Rd @@ -37,7 +37,9 @@ future, using posterior samples of (theta, alpha_T+1) i.e. the posterior samples of hyperparameters and latest states. Otherwise it is assumed that \code{model} corresponds to the original model.} -\item{seed}{Seed for RNG (positive integer).} +\item{seed}{Seed for RNG (positive integer). Note that this affects only the +C++ side, and \code{predict} also uses R side RNG for subsampling, so for +replicable results you should call \code{set.seed} before \code{predict}.} \item{...}{Ignored.} } diff --git a/tests/testthat/test_predict.R b/tests/testthat/test_predict.R index daf10d68..639f2a09 100644 --- a/tests/testthat/test_predict.R +++ b/tests/testthat/test_predict.R @@ -14,6 +14,7 @@ test_that("Gaussian predictions work", { mcmc_results <- run_mcmc(model, iter = 1000) future_model <- model future_model$y <- rep(NA, 3) + set.seed(1) pred <- predict(mcmc_results, future_model, type = "mean", nsim = 100) @@ -21,8 +22,10 @@ test_that("Gaussian predictions work", { expect_lt(mean(pred$value[pred$time == 3]), 0.5) # Posterior predictions for past observations: + set.seed(1) expect_error(yrep <- predict(mcmc_results, model, type = "response", future = FALSE, nsim = 100), NA) + set.seed(1) expect_error(meanrep <- predict(mcmc_results, model, type = "mean", future = FALSE, nsim = 100), NA) @@ -58,19 +61,21 @@ test_that("Gaussian predictions work", { mcmc_results2$theta[, 2:3] <- log(mcmc_results2$theta[, 2:3]) future_model2 <- model2 future_model2$y <- matrix(NA, 3, 1) + set.seed(1) expect_error(pred2 <- predict(mcmc_results2, future_model2, type = "mean", nsim = 100), NA) expect_equal(pred, pred2) # Posterior predictions for past observations: + set.seed(1) expect_error(yrep2 <- predict(mcmc_results2, model2, type = "response", future = FALSE, nsim = 100), NA) - expect_error(meanrep2 <- predict(mcmc_results2, model2, type = "mean", + set.seed(1) + expect_error(meanrep2 <- predict(mcmc_results2, model2, type = "mean", future = FALSE, nsim = 100), NA) expect_equal(yrep, yrep2) expect_equal(meanrep, meanrep2) expect_error(predict(mcmc_results2, model, type = "response", future = FALSE, nsim = 100)) - }) test_that("Non-gaussian predictions work", { @@ -85,6 +90,7 @@ test_that("Non-gaussian predictions work", { expect_error(mcmc_results <- run_mcmc(model, iter = 1000, particles = 5), NA) future_model <- model future_model$y <- rep(NA, 3) + set.seed(1) expect_error(pred <- predict(mcmc_results, future_model, type = "mean", nsim = 100), NA) @@ -92,12 +98,14 @@ test_that("Non-gaussian predictions work", { expect_lt(mean(pred$value[pred$time == 3]), 1.5) # Posterior predictions for past observations: + set.seed(1) expect_error(yrep <- predict(mcmc_results, model, type = "response", future = FALSE, nsim = 100), NA) + set.seed(1) expect_error(meanrep <- predict(mcmc_results, model, type = "mean", future = FALSE, nsim = 100), NA) - expect_equal(mean(yrep$value - meanrep$value), 0, tol = 0.1) + expect_equal(mean(yrep$value - meanrep$value), 0, tol = 0.5) update_fn <- function(x) { T <- array(x[1]) @@ -128,12 +136,15 @@ test_that("Non-gaussian predictions work", { future_model2 <- model2 future_model2$y <- rep(NA, 3) + set.seed(1) expect_error(pred2 <- predict(mcmc_results2, future_model2, type = "mean", nsim = 100), NA) expect_equal(pred, pred2) # Posterior predictions for past observations: + set.seed(1) expect_error(yrep2 <- predict(mcmc_results2, model2, type = "response", future = FALSE, nsim = 100), NA) + set.seed(1) expect_error(meanrep2 <- predict(mcmc_results2, model2, type = "mean", future = FALSE, nsim = 100), NA) expect_equal(yrep, yrep2) @@ -173,12 +184,14 @@ test_that("Predictions for nlg_ssm work", { expect_lt(mean(pred$value[pred$time == 3]), 1.5) # Posterior predictions for past observations: + set.seed(1) expect_error(yrep <- predict(mcmc_results, model, type = "response", future = FALSE, nsim = 100), NA) + set.seed(1) expect_error(meanrep <- predict(mcmc_results, model, type = "mean", future = FALSE, nsim = 100), NA) - expect_equal(mean(yrep$value - meanrep$value), 0, tol = 0.1) + expect_equal(mean(yrep$value - meanrep$value), 0, tol = 0.5) }) @@ -221,11 +234,13 @@ test_that("Predictions for mng_ssm work", { expect_lt(max(pred$value), 1000) # Posterior predictions for past observations: + set.seed(1) expect_error(yrep <- predict(mcmc_results, model, type = "response", future = FALSE, nsim = 100), NA) + set.seed(1) expect_error(meanrep <- predict(mcmc_results, model, type = "mean", future = FALSE, nsim = 100), NA) - expect_equal(mean(yrep$value - meanrep$value), 0, tol = 0.1) + expect_equal(mean(yrep$value - meanrep$value), 0, tol = 0.5) })