Skip to content

Commit

Permalink
v0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimonen committed Jul 3, 2023
1 parent c30abf1 commit a177259
Show file tree
Hide file tree
Showing 34 changed files with 567 additions and 513 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: odemodeling
Title: Building, fitting, and validating Bayesian ODE models in 'Stan'
Version: 0.2.1
Version: 0.2.2
Authors@R:
person(given = "Juho",
family = "Timonen",
Expand All @@ -15,7 +15,7 @@ License: BSD_3_clause + file LICENCE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
SystemRequirements: CmdStan (https://mc-stan.org/users/interfaces/cmdstan)
Imports:
methods,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(bdf_list)
export(ckrk)
export(compute_reliability_metrics)
export(euler)
export(example_ode_model)
export(log_ratios)
export(max_abs_loglik_diff)
export(max_abs_odesol_diff)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Version 0.2

## odemodeling 0.2.2
* Improves documentation.
* Exports `example_ode_model()`.

## odemodeling 0.2.0
* Adds the `$diagnose()` method for the `OdeModel` class.
* Stores the results of `diagnose` and `stansummary`in the
Expand Down
1 change: 0 additions & 1 deletion R/classes-fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ OdeModelMCMC <- R6::R6Class("OdeModelMCMC",
solver = NULL,
fitted_params = NULL,
...) {

# Handle input
t0 <- replace_if_null(t0, self$t0)
t <- replace_if_null(t, self$t)
Expand Down
5 changes: 1 addition & 4 deletions R/classes-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ OdeModel <- R6::R6Class("OdeModel", list(
solver = rk45(),
params = NULL,
...) {

# Full Stan data
model <- self
sd <- create_standata(model, t0, t, solver)
Expand Down Expand Up @@ -166,7 +165,6 @@ OdeModel <- R6::R6Class("OdeModel", list(
data = list(),
solver = rk45(),
...) {

# Check and handle input
sd <- create_standata(self, t0, t, solver)
full_data <- c(sd, data)
Expand Down Expand Up @@ -212,7 +210,6 @@ OdeModel <- R6::R6Class("OdeModel", list(
error = Inf,
epsilon = 1e-6,
...) {

# Check and handle input
sd <- create_standata(self, t0, t, solver)
full_data <- c(sd, data)
Expand Down Expand Up @@ -273,7 +270,7 @@ OdeModel <- R6::R6Class("OdeModel", list(
fit <- model$sample(
t0 = t0,
t = t,
data = data,
data = data,
solver = solver,
chains = chains,
...
Expand Down
1 change: 0 additions & 1 deletion R/classes-standecl.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' A Stan variable declaration (an abstract base class)
#'
#' @field name name of the variable
Expand Down
4 changes: 1 addition & 3 deletions R/main-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#' \item `"lv"` - Lotka-Volterra model
#' }
#' @return An object of class `OdeModel`.
#' @export
#' @family model constructor functions
example_ode_model <- function(name, prior_only = FALSE, ...) {
choices <- c("gsir", "tmdd", "lv")
Expand All @@ -29,7 +30,6 @@ example_ode_model <- function(name, prior_only = FALSE, ...) {

# Group-stratified SIR example model
example_ode_model_gsir <- function(prior_only, ...) {

# Time points
N <- stan_dim("N", lower = 0) # number of timepoints

Expand Down Expand Up @@ -134,7 +134,6 @@ example_ode_model_gsir <- function(prior_only, ...) {

# TMDD example model
example_ode_model_tmdd <- function(prior_only, ...) {

# Dimensions and other data
N <- stan_dim("N", lower = 1) # number of time points
D <- stan_dim("D", lower = 1) # ODE system dimension
Expand Down Expand Up @@ -205,7 +204,6 @@ example_ode_model_tmdd <- function(prior_only, ...) {

# Lotka-Volterra example model
example_ode_model_lv <- function(prior_only = FALSE, ...) {

# Dimensions and other data
N <- stan_dim("N", lower = 1) # number of time points
D <- stan_dim("D", lower = 1) # ODE system dimension
Expand Down
1 change: 0 additions & 1 deletion R/main-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ ode_model <- function(N,
verbose = FALSE,
compile = TRUE,
sig_figs = 18) {

# Argument checks
choices_vars <- c("StanParameter", "StanTransformation", "StanDeclaration")
checkmate::assert_class(N, "StanDimension")
Expand Down
27 changes: 27 additions & 0 deletions R/odemodeling-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,33 @@
#' \item See \code{\link{compare_odefits}} for functions to compare
#' different ODE model simulations and fits.
#' }
#' @section Importance sampling for reliable and efficient inference in Bayesian ODE models:
#' Our proposed workflow is to
#' \enumerate{
#' \item Select an initial ODE solver M.
#' \item Sample the parameter posterior using MCMC with M as the ODE solver.
#' \item Compute certain metrics using a more accurate solver M∗.
#' \item Increase the accuracy of M∗ and repeat Step 3 until the metrics converge.
#' If the Pareto-k metric converges to a value larger than 0.7, increase the accuracy
#' of M and go back to Step 2.
#' \item Compute any posterior estimates using final importance weights. See
#' Timonen et al. (2022) below.
#' }
#' The algorithm can be used to validate the reliability, and correct the errors
#' of a given method M, which can be for example a software default. On the other hand,
#' a smart initial selection of M can provide speed gains
#' compared to often rather conservatively set software defaults, while still maintaining
#' reliability of the inferences.
#'
#' We generally recommend selecting M initially so that sampling is as fast as possible.
#' For example, for non-adaptive ODE solvers, one can first try using the smallest
#' sensible number of steps that does not result in immediate failure.
#' Selecting a good M is more difficult in the case of adaptive solvers.
#' We have
#' observed that tolerances on the order of 1e-4 to 1e-3 generally work well.
#'
#' See the \code{reliability()} method of the \code{\link{OdeModelMCMC}} class.
#'
#' @section Tutorial:
#' See the tutorial vignette.
#' @references
Expand Down
1 change: 0 additions & 1 deletion R/utils-create_input.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Create full Stan data for sampling or gq
create_standata <- function(model, t0, t, solver) {
checkmate::assert_class(model, "OdeModel")
Expand Down
42 changes: 21 additions & 21 deletions man/AdaptiveOdeSolver.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions man/FixedNumStepsOdeSolver.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a177259

Please sign in to comment.