From c1734b7b7682b5534832bc265f3318e8631a3d32 Mon Sep 17 00:00:00 2001 From: njtierney Date: Wed, 21 Aug 2024 16:41:44 +1000 Subject: [PATCH 01/11] test posteriors for release --- tests/testthat/test_posteriors.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_posteriors.R b/tests/testthat/test_posteriors.R index a919cf1d..80488f60 100644 --- a/tests/testthat/test_posteriors.R +++ b/tests/testthat/test_posteriors.R @@ -1,4 +1,4 @@ -# Sys.setenv("RELEASE_CANDIDATE" = "true") +Sys.setenv("RELEASE_CANDIDATE" = "true") test_that("posterior is correct (binomial)", { skip_if_not(check_tf_version()) From 34d6bddfcf0b489c22e20f4909c690e5ab777f60 Mon Sep 17 00:00:00 2001 From: njtierney Date: Wed, 21 Aug 2024 16:44:03 +1000 Subject: [PATCH 02/11] news polish --- NEWS.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9bbc51a8..f52f1655 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,8 @@ -# greta 0.4.5.9000 (development version) +# greta 0.5.0 -## Features - -* This version of greta uses Tensorflow 2.0.0, which comes with it a host of new very exciting features! +This version of greta uses Tensorflow 2.0.0, which comes with it a host of new very exciting features! -### Optimizers +## Optimizers The latest interface to optimizers in tensorflow are now used, these changes are described. @@ -46,14 +44,17 @@ This release provides a few improvements to installation in greta. It should now * Added `destroy_greta_deps()` function to remove miniconda and python conda environment * Improved `write_greta_install_log()` and `read_greta_install_log()` to use `tools::R_user_dir()` to always write to a file location. `read_greta_install_log()` will open one found from an environment variable or go to the default location. (#703) +## New Print methods + +* New print method for `greta_mcmc_list`. This means MCMC output will be shorter and more informative. (#644) +* greta arrays now have a print method that stops them from printing too many rows into the console. Similar to MCMC print method, you can control the print output with the `n` argument: `print(object, n = )`. (#644) + ## Minor -* `greta_sitrep()` now checks for minimum versions of software, instead of exact versions. It requires at least Python version 3.8, TensorFlow 2.8.0, and Tensorflow Probability 0.14.0. -* slice sampler no longer needs precision = "single" to work. +* `greta_sitrep()` now checks for installations of Python, TF, and TFP +* Slice sampler no longer needs precision = "single" to work. * greta now depends on R 4.1.0, which was released May 2021, over 3 years ago. * export `is.greta_array()` and `is.greta_mcmc_list()` -* greta arrays now have a print method that stops them from printing too many rows into the console. Similar to MCMC print method, you can control the print output with the `n` argument: `print(object, n = )`. (#644) -* New print method for `greta_mcmc_list`. This means MCMC output will be shorter and more informative. (#644) * `restart` argument for `install_greta_deps()` and `reinstall_greta_deps()` to automatically restart R (#523) ## Internals From e3663000b07ea1a0c41baff1737c39ae1d8cfa4d Mon Sep 17 00:00:00 2001 From: njtierney Date: Wed, 21 Aug 2024 16:51:25 +1000 Subject: [PATCH 03/11] fixing some URLs --- R/optimisers.R | 8 ++++---- man/optimisers.Rd | 8 ++++---- vignettes/example_models.Rmd | 2 +- vignettes/get_started.Rmd | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/R/optimisers.R b/R/optimisers.R index 440acf56..02f3d492 100644 --- a/R/optimisers.R +++ b/R/optimisers.R @@ -142,27 +142,27 @@ define_tfp_optimiser <- function(name, #' `initial_vertex`. This parameter controls the scaling of the reflected #' vertex. See, [Press et al(2007)](http://numerical.recipes/cpppages/chap0sel.pdf) #' for details. If not specified, uses the dimension dependent prescription of -#' [Gao and Han(2012)](https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be?p2df) +#' [Gao and Han(2012)](https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be) #' @param expansion (optional) Positive Scalar Tensor of same dtype as #' `initial_vertex`. Should be greater than 1 and reflection. This parameter #' controls the expanded scaling of a reflected vertex.See, #' [Press et al(2007)](http://numerical.recipes/cpppages/chap0sel.pdf) for #' details. If not specified, uses the dimension dependent prescription of -#' [Gao and Han(2012)](https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be?p2df) +#' [Gao and Han(2012)](https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be) #' @param contraction (optional) Positive scalar Tensor of same dtype as #' `initial_vertex`. Must be between 0 and 1. This parameter controls the #' contraction of the reflected vertex when the objective function at the #' reflected point fails to show sufficient decrease. See, #' [Press et al(2007)](http://numerical.recipes/cpppages/chap0sel.pdf) for #' details. If not specified, uses the dimension dependent prescription of -#' [Gao and Han(2012)](https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be?p2df) +#' [Gao and Han(2012)](https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be) #' @param shrinkage (Optional) Positive scalar Tensor of same dtype as #' `initial_vertex`. Must be between 0 and 1. This parameter is the scale by #' which the simplex is shrunk around the best point when the other steps fail #' to produce improvements. See, #' [Press et al(2007)](http://numerical.recipes/cpppages/chap0sel.pdf) for #' details. If not specified, uses the dimension dependent prescription of -#' [Gao and Han(2012)](https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be?p2df) +#' [Gao and Han(2012)](https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be) #' #' @export #' diff --git a/man/optimisers.Rd b/man/optimisers.Rd index 044ffb57..4c4eb59b 100644 --- a/man/optimisers.Rd +++ b/man/optimisers.Rd @@ -153,14 +153,14 @@ is below this threshold.} \code{initial_vertex}. This parameter controls the scaling of the reflected vertex. See, \href{http://numerical.recipes/cpppages/chap0sel.pdf}{Press et al(2007)} for details. If not specified, uses the dimension dependent prescription of -\href{https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be?p2df}{Gao and Han(2012)}} +\href{https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be}{Gao and Han(2012)}} \item{expansion}{(optional) Positive Scalar Tensor of same dtype as \code{initial_vertex}. Should be greater than 1 and reflection. This parameter controls the expanded scaling of a reflected vertex.See, \href{http://numerical.recipes/cpppages/chap0sel.pdf}{Press et al(2007)} for details. If not specified, uses the dimension dependent prescription of -\href{https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be?p2df}{Gao and Han(2012)}} +\href{https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be}{Gao and Han(2012)}} \item{contraction}{(optional) Positive scalar Tensor of same dtype as \code{initial_vertex}. Must be between 0 and 1. This parameter controls the @@ -168,7 +168,7 @@ contraction of the reflected vertex when the objective function at the reflected point fails to show sufficient decrease. See, \href{http://numerical.recipes/cpppages/chap0sel.pdf}{Press et al(2007)} for details. If not specified, uses the dimension dependent prescription of -\href{https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be?p2df}{Gao and Han(2012)}} +\href{https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be}{Gao and Han(2012)}} \item{shrinkage}{(Optional) Positive scalar Tensor of same dtype as \code{initial_vertex}. Must be between 0 and 1. This parameter is the scale by @@ -176,7 +176,7 @@ which the simplex is shrunk around the best point when the other steps fail to produce improvements. See, \href{http://numerical.recipes/cpppages/chap0sel.pdf}{Press et al(2007)} for details. If not specified, uses the dimension dependent prescription of -\href{https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be?p2df}{Gao and Han(2012)}} +\href{https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be}{Gao and Han(2012)}} \item{value_and_gradients_function}{A function that accepts a point as a real Tensor and returns a tuple of Tensors of real dtype containing the diff --git a/vignettes/example_models.Rmd b/vignettes/example_models.Rmd index e9d98fc6..1278f8ae 100644 --- a/vignettes/example_models.Rmd +++ b/vignettes/example_models.Rmd @@ -115,7 +115,7 @@ Below are some more advanced examples implemented in greta. The BUGS project provide a number of example models written in the BUGS modelling language. These models will run in WinBUGS and OpenBUGS, and likely also in JAGS. The [Stan wiki](https://github.com/stan-dev/example-models/wiki/BUGS-Examples-Sorted-Alphabetically) provides Stan implementations of these models. -The following sections provide greta implementations of some of these example models, alongside the BUGS code from [WinBUGS examples volume 2](https://www.mrc-bsu.cam.ac.uk/wp-content/uploads/WinBUGS_Vol2.pdf) (pdf) and Stan code and an R version of the data from the [Stan example models wiki](https://github.com/stan-dev/example-models/wiki). +The following sections provide greta implementations of some of these example models, alongside the BUGS code from [WinBUGS examples volume 2](https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=56b11079d6495501c84932c0a7a372ca6bc370ae) (pdf) and Stan code and an R version of the data from the [Stan example models wiki](https://github.com/stan-dev/example-models/wiki).
diff --git a/vignettes/get_started.Rmd b/vignettes/get_started.Rmd index 38f7f643..c05cfea2 100644 --- a/vignettes/get_started.Rmd +++ b/vignettes/get_started.Rmd @@ -100,7 +100,7 @@ reticulate::conda_install( ### DiagrammeR -greta's [plotting functionality](#plotting) depends on the [DiagrammeR package](http://rich-iannone.github.io/DiagrammeR/). Because DiagrammeR depends on the [igraph](https://igraph.org/r/) package, which contains a large amount of code that needs to be compiled, DiagrammeR often takes a long time to install. So, DiagrammeR isn’t installed automatically with greta. If you want to plot greta models, you can install igraph and DiagrammeR from CRAN. +greta's [plotting functionality](#plotting) depends on the [DiagrammeR package](https://rich-iannone.github.io/DiagrammeR/). Because DiagrammeR depends on the [igraph](https://igraph.org/r/) package, which contains a large amount of code that needs to be compiled, DiagrammeR often takes a long time to install. So, DiagrammeR isn’t installed automatically with greta. If you want to plot greta models, you can install igraph and DiagrammeR from CRAN. ```{r install_diagrammer, eval = FALSE} install.packages("igraph") From 001193aa3197478efcd9e4b21d2109970c7a4c53 Mon Sep 17 00:00:00 2001 From: njtierney Date: Thu, 22 Aug 2024 12:18:27 +1000 Subject: [PATCH 04/11] fixing more URLs --- R/greta_model_class.R | 2 +- R/optimisers.R | 16 ++++++++-------- man/model.Rd | 2 +- man/optimisers.Rd | 16 ++++++++-------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/R/greta_model_class.R b/R/greta_model_class.R index d07e0646..db01889a 100644 --- a/R/greta_model_class.R +++ b/R/greta_model_class.R @@ -24,7 +24,7 @@ NULL #' instability during sampling. #' #' @param compile whether to apply -#' [XLA JIT compilation](https://www.tensorflow.org/xla) to +#' [XLA JIT compilation](https://openxla.org/xla) to #' the TensorFlow graph representing the model. This may slow down model #' definition, and speed up model evaluation. #' diff --git a/R/optimisers.R b/R/optimisers.R index 02f3d492..b8053012 100644 --- a/R/optimisers.R +++ b/R/optimisers.R @@ -140,29 +140,29 @@ define_tfp_optimiser <- function(name, #' is below this threshold. #' @param reflection (optional) Positive Scalar Tensor of same dtype as #' `initial_vertex`. This parameter controls the scaling of the reflected -#' vertex. See, [Press et al(2007)](http://numerical.recipes/cpppages/chap0sel.pdf) +#' vertex. See, [Press et al(2007)](https://numerical.recipes/book.html) #' for details. If not specified, uses the dimension dependent prescription of -#' [Gao and Han(2012)](https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be) +#' [Gao and Han(2012)](https://api.semanticscholar.org/CorpusID:9211872) #' @param expansion (optional) Positive Scalar Tensor of same dtype as #' `initial_vertex`. Should be greater than 1 and reflection. This parameter #' controls the expanded scaling of a reflected vertex.See, -#' [Press et al(2007)](http://numerical.recipes/cpppages/chap0sel.pdf) for +#' [Press et al(2007)](https://numerical.recipes/book.html) for #' details. If not specified, uses the dimension dependent prescription of -#' [Gao and Han(2012)](https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be) +#' [Gao and Han(2012)](https://api.semanticscholar.org/CorpusID:9211872) #' @param contraction (optional) Positive scalar Tensor of same dtype as #' `initial_vertex`. Must be between 0 and 1. This parameter controls the #' contraction of the reflected vertex when the objective function at the #' reflected point fails to show sufficient decrease. See, -#' [Press et al(2007)](http://numerical.recipes/cpppages/chap0sel.pdf) for +#' [Press et al(2007)](https://numerical.recipes/book.html) for #' details. If not specified, uses the dimension dependent prescription of -#' [Gao and Han(2012)](https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be) +#' [Gao and Han(2012)](https://api.semanticscholar.org/CorpusID:9211872) #' @param shrinkage (Optional) Positive scalar Tensor of same dtype as #' `initial_vertex`. Must be between 0 and 1. This parameter is the scale by #' which the simplex is shrunk around the best point when the other steps fail #' to produce improvements. See, -#' [Press et al(2007)](http://numerical.recipes/cpppages/chap0sel.pdf) for +#' [Press et al(2007)](https://numerical.recipes/book.html) for #' details. If not specified, uses the dimension dependent prescription of -#' [Gao and Han(2012)](https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be) +#' [Gao and Han(2012)](https://api.semanticscholar.org/CorpusID:9211872) #' #' @export #' diff --git a/man/model.Rd b/man/model.Rd index 9a046b4d..6047d436 100644 --- a/man/model.Rd +++ b/man/model.Rd @@ -26,7 +26,7 @@ decrease the computation time but increase the risk of numerical instability during sampling.} \item{compile}{whether to apply -\href{https://www.tensorflow.org/xla}{XLA JIT compilation} to +\href{https://openxla.org/xla}{XLA JIT compilation} to the TensorFlow graph representing the model. This may slow down model definition, and speed up model evaluation.} diff --git a/man/optimisers.Rd b/man/optimisers.Rd index 4c4eb59b..37e2bda5 100644 --- a/man/optimisers.Rd +++ b/man/optimisers.Rd @@ -151,32 +151,32 @@ is below this threshold.} \item{reflection}{(optional) Positive Scalar Tensor of same dtype as \code{initial_vertex}. This parameter controls the scaling of the reflected -vertex. See, \href{http://numerical.recipes/cpppages/chap0sel.pdf}{Press et al(2007)} +vertex. See, \href{https://numerical.recipes/book.html}{Press et al(2007)} for details. If not specified, uses the dimension dependent prescription of -\href{https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be}{Gao and Han(2012)}} +\href{https://www.semanticscholar.org/paper/15b4c4aa7437df4d032c6ee6ce98d6030dd627be}{Gao and Han(2012)}} \item{expansion}{(optional) Positive Scalar Tensor of same dtype as \code{initial_vertex}. Should be greater than 1 and reflection. This parameter controls the expanded scaling of a reflected vertex.See, -\href{http://numerical.recipes/cpppages/chap0sel.pdf}{Press et al(2007)} for +\href{https://numerical.recipes/book.html}{Press et al(2007)} for details. If not specified, uses the dimension dependent prescription of -\href{https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be}{Gao and Han(2012)}} +\href{https://api.semanticscholar.org/CorpusID:9211872}{Gao and Han(2012)}} \item{contraction}{(optional) Positive scalar Tensor of same dtype as \code{initial_vertex}. Must be between 0 and 1. This parameter controls the contraction of the reflected vertex when the objective function at the reflected point fails to show sufficient decrease. See, -\href{http://numerical.recipes/cpppages/chap0sel.pdf}{Press et al(2007)} for +\href{https://numerical.recipes/book.html}{Press et al(2007)} for details. If not specified, uses the dimension dependent prescription of -\href{https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be}{Gao and Han(2012)}} +\href{https://api.semanticscholar.org/CorpusID:9211872}{Gao and Han(2012)}} \item{shrinkage}{(Optional) Positive scalar Tensor of same dtype as \code{initial_vertex}. Must be between 0 and 1. This parameter is the scale by which the simplex is shrunk around the best point when the other steps fail to produce improvements. See, -\href{http://numerical.recipes/cpppages/chap0sel.pdf}{Press et al(2007)} for +\href{https://numerical.recipes/book.html}{Press et al(2007)} for details. If not specified, uses the dimension dependent prescription of -\href{https://www.semanticscholar.org/paper/Implementing-the-Nelder-Mead-simplex-algorithm-with-Gao-Han/15b4c4aa7437df4d032c6ee6ce98d6030dd627be}{Gao and Han(2012)}} +\href{https://api.semanticscholar.org/CorpusID:9211872}{Gao and Han(2012)}} \item{value_and_gradients_function}{A function that accepts a point as a real Tensor and returns a tuple of Tensors of real dtype containing the From e4bd9f495685652da371708ea6d9e7e7b8bb16dd Mon Sep 17 00:00:00 2001 From: njtierney Date: Wed, 28 Aug 2024 16:03:36 +1000 Subject: [PATCH 05/11] use DOIs instead of URL for Gao + Han. (Thanks @maelle!) --- R/optimisers.R | 8 ++++---- README.md | 2 +- man/optimisers.Rd | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/R/optimisers.R b/R/optimisers.R index b8053012..0baa015b 100644 --- a/R/optimisers.R +++ b/R/optimisers.R @@ -142,27 +142,27 @@ define_tfp_optimiser <- function(name, #' `initial_vertex`. This parameter controls the scaling of the reflected #' vertex. See, [Press et al(2007)](https://numerical.recipes/book.html) #' for details. If not specified, uses the dimension dependent prescription of -#' [Gao and Han(2012)](https://api.semanticscholar.org/CorpusID:9211872) +#' Gao and Han (2012) \doi{10.1007/s10589-010-9329-3} #' @param expansion (optional) Positive Scalar Tensor of same dtype as #' `initial_vertex`. Should be greater than 1 and reflection. This parameter #' controls the expanded scaling of a reflected vertex.See, #' [Press et al(2007)](https://numerical.recipes/book.html) for #' details. If not specified, uses the dimension dependent prescription of -#' [Gao and Han(2012)](https://api.semanticscholar.org/CorpusID:9211872) +#' Gao and Han (2012) \doi{10.1007/s10589-010-9329-3} #' @param contraction (optional) Positive scalar Tensor of same dtype as #' `initial_vertex`. Must be between 0 and 1. This parameter controls the #' contraction of the reflected vertex when the objective function at the #' reflected point fails to show sufficient decrease. See, #' [Press et al(2007)](https://numerical.recipes/book.html) for #' details. If not specified, uses the dimension dependent prescription of -#' [Gao and Han(2012)](https://api.semanticscholar.org/CorpusID:9211872) +#' Gao and Han (2012) \doi{10.1007/s10589-010-9329-3} #' @param shrinkage (Optional) Positive scalar Tensor of same dtype as #' `initial_vertex`. Must be between 0 and 1. This parameter is the scale by #' which the simplex is shrunk around the best point when the other steps fail #' to produce improvements. See, #' [Press et al(2007)](https://numerical.recipes/book.html) for #' details. If not specified, uses the dimension dependent prescription of -#' [Gao and Han(2012)](https://api.semanticscholar.org/CorpusID:9211872) +#' Gao and Han (2012) \doi{10.1007/s10589-010-9329-3} #' #' @export #' diff --git a/README.md b/README.md index 3e9a722f..2b7c59c1 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ CRAN: install.packages("greta") ``` -Or install the development version of `greta` from [r-universe](http://greta-dev.r-universe.dev/ui/): +Or install the development version of `greta` from [r-universe](http://greta-dev.r-universe.dev/): ```r # Enable this universe diff --git a/man/optimisers.Rd b/man/optimisers.Rd index 37e2bda5..fa3c2455 100644 --- a/man/optimisers.Rd +++ b/man/optimisers.Rd @@ -153,14 +153,14 @@ is below this threshold.} \code{initial_vertex}. This parameter controls the scaling of the reflected vertex. See, \href{https://numerical.recipes/book.html}{Press et al(2007)} for details. If not specified, uses the dimension dependent prescription of -\href{https://www.semanticscholar.org/paper/15b4c4aa7437df4d032c6ee6ce98d6030dd627be}{Gao and Han(2012)}} +Gao and Han (2012) \doi{10.1007/s10589-010-9329-3}} \item{expansion}{(optional) Positive Scalar Tensor of same dtype as \code{initial_vertex}. Should be greater than 1 and reflection. This parameter controls the expanded scaling of a reflected vertex.See, \href{https://numerical.recipes/book.html}{Press et al(2007)} for details. If not specified, uses the dimension dependent prescription of -\href{https://api.semanticscholar.org/CorpusID:9211872}{Gao and Han(2012)}} +Gao and Han (2012) \doi{10.1007/s10589-010-9329-3}} \item{contraction}{(optional) Positive scalar Tensor of same dtype as \code{initial_vertex}. Must be between 0 and 1. This parameter controls the @@ -168,7 +168,7 @@ contraction of the reflected vertex when the objective function at the reflected point fails to show sufficient decrease. See, \href{https://numerical.recipes/book.html}{Press et al(2007)} for details. If not specified, uses the dimension dependent prescription of -\href{https://api.semanticscholar.org/CorpusID:9211872}{Gao and Han(2012)}} +Gao and Han (2012) \doi{10.1007/s10589-010-9329-3}} \item{shrinkage}{(Optional) Positive scalar Tensor of same dtype as \code{initial_vertex}. Must be between 0 and 1. This parameter is the scale by @@ -176,7 +176,7 @@ which the simplex is shrunk around the best point when the other steps fail to produce improvements. See, \href{https://numerical.recipes/book.html}{Press et al(2007)} for details. If not specified, uses the dimension dependent prescription of -\href{https://api.semanticscholar.org/CorpusID:9211872}{Gao and Han(2012)}} +Gao and Han (2012) \doi{10.1007/s10589-010-9329-3}} \item{value_and_gradients_function}{A function that accepts a point as a real Tensor and returns a tuple of Tensors of real dtype containing the From 9d6960cded5004430920d266f86e2a6dd4c0516b Mon Sep 17 00:00:00 2001 From: njtierney Date: Wed, 28 Aug 2024 16:04:56 +1000 Subject: [PATCH 06/11] Add GitHub links to DESCRIPTION --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index dc9e3062..d4c5d413 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,7 +28,7 @@ Description: Write statistical models in R and fit them by MCMC and including tutorials, examples, package documentation, and the greta forum. License: Apache License 2.0 -URL: https://greta-stats.org +URL: https://greta-stats.org, https://github.com/greta-dev/greta BugReports: https://github.com/greta-dev/greta/issues Depends: R (>= 4.1.0) From bae9d1b0d9b85c435d05bb8d101811512c47e445 Mon Sep 17 00:00:00 2001 From: njtierney Date: Wed, 28 Aug 2024 16:06:20 +1000 Subject: [PATCH 07/11] note skipping geweke tests for the moment --- tests/testthat/test_posteriors.R | 127 ++++++++++++++++--------------- 1 file changed, 64 insertions(+), 63 deletions(-) diff --git a/tests/testthat/test_posteriors.R b/tests/testthat/test_posteriors.R index 80488f60..d22760e2 100644 --- a/tests/testthat/test_posteriors.R +++ b/tests/testthat/test_posteriors.R @@ -97,66 +97,67 @@ test_that("samplers are unbiased for Wishart", { check_samples(x, iid, one_by_one = TRUE) }) - -test_that("samplers pass geweke tests", { - skip_if_not(check_tf_version()) - - skip_if_not_release() - - # nolint start - # run geweke tests on this model: - # theta ~ normal(mu1, sd1) - # x[i] ~ normal(theta, sd2) - # for i in N - # nolint end - - n <- 10 - mu1 <- rnorm(1, 0, 3) - sd1 <- rlnorm(1) - sd2 <- rlnorm(1) - - # prior (n draws) - p_theta <- function(n) { - rnorm(n, mu1, sd1) - } - - # likelihood - p_x_bar_theta <- function(theta) { - rnorm(n, theta, sd2) - } - - # define the greta model (single precision for slice sampler) - x <- as_data(rep(0, n)) - greta_theta <- normal(mu1, sd1) - distribution(x) <- normal(greta_theta, sd2) - model <- model(greta_theta, precision = "single") - - # run tests on all available samplers - check_geweke( - sampler = hmc(), - model = model, - data = x, - p_theta = p_theta, - p_x_bar_theta = p_x_bar_theta, - title = "HMC Geweke test" - ) - - check_geweke( - sampler = rwmh(), - model = model, - data = x, - p_theta = p_theta, - p_x_bar_theta = p_x_bar_theta, - warmup = 2000, - title = "RWMH Geweke test" - ) - - check_geweke( - sampler = slice(), - model = model, - data = x, - p_theta = p_theta, - p_x_bar_theta = p_x_bar_theta, - title = "slice sampler Geweke test" - ) -}) +## TF1/2 - method for this test needs to be updated for TF2 +## Passing this along to version 0.6.0 now +# test_that("samplers pass geweke tests", { +# skip_if_not(check_tf_version()) +# +# skip_if_not_release() +# +# # nolint start +# # run geweke tests on this model: +# # theta ~ normal(mu1, sd1) +# # x[i] ~ normal(theta, sd2) +# # for i in N +# # nolint end +# +# n <- 10 +# mu1 <- rnorm(1, 0, 3) +# sd1 <- rlnorm(1) +# sd2 <- rlnorm(1) +# +# # prior (n draws) +# p_theta <- function(n) { +# rnorm(n, mu1, sd1) +# } +# +# # likelihood +# p_x_bar_theta <- function(theta) { +# rnorm(n, theta, sd2) +# } +# +# # define the greta model (single precision for slice sampler) +# x <- as_data(rep(0, n)) +# greta_theta <- normal(mu1, sd1) +# distribution(x) <- normal(greta_theta, sd2) +# model <- model(greta_theta, precision = "single") +# +# # run tests on all available samplers +# check_geweke( +# sampler = hmc(), +# model = model, +# data = x, +# p_theta = p_theta, +# p_x_bar_theta = p_x_bar_theta, +# title = "HMC Geweke test" +# ) +# +# check_geweke( +# sampler = rwmh(), +# model = model, +# data = x, +# p_theta = p_theta, +# p_x_bar_theta = p_x_bar_theta, +# warmup = 2000, +# title = "RWMH Geweke test" +# ) +# +# check_geweke( +# sampler = slice(), +# model = model, +# data = x, +# p_theta = p_theta, +# p_x_bar_theta = p_x_bar_theta, +# title = "slice sampler Geweke test" +# ) +# }) From 3a18bb1f1dd86e28aa1928747ee3c38f7686ba5b Mon Sep 17 00:00:00 2001 From: njtierney Date: Wed, 28 Aug 2024 16:11:54 +1000 Subject: [PATCH 08/11] * update URLs * update pkg version --- DESCRIPTION | 2 +- man/greta.Rd | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d4c5d413..827b80dd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: greta Title: Simple and Scalable Statistical Modelling in R -Version: 0.4.5.9000 +Version: 0.5.0 Authors@R: c( person("Nick", "Golding", , "nick.golding.research@gmail.com", role = "aut", comment = c(ORCID = "0000-0001-8916-5570")), diff --git a/man/greta.Rd b/man/greta.Rd index 23c7ab06..d7dc1d84 100644 --- a/man/greta.Rd +++ b/man/greta.Rd @@ -42,6 +42,7 @@ draws <- mcmc(m, n_samples = 100) Useful links: \itemize{ \item \url{https://greta-stats.org} + \item \url{https://github.com/greta-dev/greta} \item Report bugs at \url{https://github.com/greta-dev/greta/issues} } From c2d86637bf836305a15a803dbf04ed4117dc35ad Mon Sep 17 00:00:00 2001 From: njtierney Date: Fri, 30 Aug 2024 11:53:44 +0100 Subject: [PATCH 09/11] set the RELEASE_CANDIDATE env to false to avoid timeout on tests --- tests/testthat/test_posteriors.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test_posteriors.R b/tests/testthat/test_posteriors.R index d22760e2..173e539f 100644 --- a/tests/testthat/test_posteriors.R +++ b/tests/testthat/test_posteriors.R @@ -1,4 +1,4 @@ -Sys.setenv("RELEASE_CANDIDATE" = "true") +Sys.setenv("RELEASE_CANDIDATE" = "false") test_that("posterior is correct (binomial)", { skip_if_not(check_tf_version()) @@ -66,7 +66,7 @@ test_that("samplers are unbiased for standard uniform", { check_samples(x, iid) }) - +## This one is failing test_that("samplers are unbiased for LKJ", { skip_if_not(check_tf_version()) From 756e11b64c045ebc1b55b38a559cf64087b1d6a8 Mon Sep 17 00:00:00 2001 From: njtierney Date: Wed, 9 Oct 2024 14:26:02 +1100 Subject: [PATCH 10/11] Improve naming of helper functions inside of `get_enough_draws()` * not_finished --> need_more_samples * not_timed_out --> still_have_time * Use `&&` instead of `&` --- tests/testthat/helpers.R | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/testthat/helpers.R b/tests/testthat/helpers.R index cbca3eff..7472208d 100644 --- a/tests/testthat/helpers.R +++ b/tests/testthat/helpers.R @@ -703,7 +703,7 @@ p_theta_greta <- function( # test mcmc for models with analytic posteriors -not_finished <- function(draws, target_samples = 5000) { +need_more_samples <- function(draws, target_samples = 5000) { neff <- coda::effectiveSize(draws) rhats <- coda::gelman.diag( x = draws, @@ -722,7 +722,7 @@ new_samples <- function(draws, target_samples = 5000) { 1.2 * (target_samples - neff) / efficiency } -not_timed_out <- function(start_time, time_limit = 300) { +still_have_time <- function(start_time, time_limit = 300) { elapsed <- Sys.time() - start_time elapsed < time_limit } @@ -743,8 +743,8 @@ get_enough_draws <- function( one_by_one = one_by_one ) - while (not_finished(draws, n_effective) & - not_timed_out(start_time, time_limit)) { + while (need_more_samples(draws, n_effective) && + still_have_time(start_time, time_limit)) { n_samples <- new_samples(draws, n_effective) draws <- extra_samples( draws, @@ -754,7 +754,7 @@ get_enough_draws <- function( ) } - if (not_finished(draws, n_effective)) { + if (need_more_samples(draws, n_effective)) { stop("could not draws enough effective samples within the time limit") } @@ -847,15 +847,17 @@ check_samples <- function( sampler = hmc(), n_effective = 3000, title = NULL, - one_by_one = FALSE + one_by_one = FALSE, + time_limit = 300 ) { m <- model(x, precision = "single") draws <- get_enough_draws( - m, + model = m, sampler = sampler, n_effective = n_effective, verbose = FALSE, - one_by_one = one_by_one + one_by_one = one_by_one, + time_limit = time_limit ) neff <- coda::effectiveSize(draws) From 92d6cfca2ec3c92d3a1a4db7e280f49378554f83 Mon Sep 17 00:00:00 2001 From: njtierney Date: Thu, 10 Oct 2024 12:58:39 +1100 Subject: [PATCH 11/11] Define `n_samples` as `sampler_burst_length`. This is a small bug we did not catch. --- R/inference_class.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/inference_class.R b/R/inference_class.R index 7eb97814..4075706b 100644 --- a/R/inference_class.R +++ b/R/inference_class.R @@ -787,6 +787,8 @@ sampler <- R6Class( # tryCatch handling for numerical errors dag <- self$model$dag tfe <- dag$tf_environment + # legacy: previously we used `n_samples` not `sampler_burst_length` + n_samples <- sampler_burst_length result <- cleanly( self$tf_evaluate_sample_batch(