Skip to content

Commit

Permalink
Merge pull request #64 from mrc-ide/mrc-5159
Browse files Browse the repository at this point in the history
Rename from mcstate2 to monty
  • Loading branch information
richfitz authored Aug 21, 2024
2 parents e974ffa + ecef2cd commit 3405cf3
Show file tree
Hide file tree
Showing 148 changed files with 2,256 additions and 2,257 deletions.
16 changes: 8 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
Package: mcstate2
Title: Next Generation mcstate
Version: 0.1.9
Package: monty
Title: Monte Carlo Models
Version: 0.2.0
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Imperial College of Science, Technology and Medicine",
role = "cph"))
Description: Experimental sources for the next generation of mcstate,
which will support much of the old mcstate functionality but new
things like better parameter interfaces, Hamiltonian Monte Carlo,
and other features.
now called 'monty', which will support much of the old mcstate
functionality but new things like better parameter interfaces,
Hamiltonian Monte Carlo, and other features.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
URL: https://mrc-ide.github.io/mcstate2, https://github.com/mrc-ide/mcstate2
BugReports: https://github.com/mrc-ide/mcstate2/issues
URL: https://mrc-ide.github.io/monty, https://github.com/mrc-ide/monty
BugReports: https://github.com/mrc-ide/monty/issues
Imports:
R6,
cli,
Expand Down
80 changes: 40 additions & 40 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
# Generated by roxygen2: do not edit by hand

S3method("+",mcstate_model)
S3method(cnd_footer,mcstate2_parse_error)
S3method(coda::as.mcmc.list,mcstate_samples)
S3method(posterior::as_draws_array,mcstate_samples)
S3method(posterior::as_draws_df,mcstate_samples)
S3method(print,mcstate_model)
S3method(print,mcstate_observer)
S3method(print,mcstate_packer)
S3method(print,mcstate_runner)
S3method(print,mcstate_sampler)
S3method(print,mcstate_samples)
export(mcstate_differentiation)
export(mcstate_domain_expand)
export(mcstate_dsl)
export(mcstate_dsl_distributions)
export(mcstate_dsl_error_explain)
export(mcstate_dsl_parse_distribution)
export(mcstate_model)
export(mcstate_model_combine)
export(mcstate_model_density)
export(mcstate_model_direct_sample)
export(mcstate_model_gradient)
export(mcstate_model_properties)
export(mcstate_observer)
export(mcstate_packer)
export(mcstate_rng)
export(mcstate_rng_distributed_pointer)
export(mcstate_rng_distributed_state)
export(mcstate_rng_pointer)
export(mcstate_runner_parallel)
export(mcstate_runner_serial)
export(mcstate_runner_simultaneous)
export(mcstate_sample)
export(mcstate_sample_continue)
export(mcstate_sampler_adaptive)
export(mcstate_sampler_hmc)
export(mcstate_sampler_nested_adaptive)
export(mcstate_sampler_nested_random_walk)
export(mcstate_sampler_random_walk)
S3method("+",monty_model)
S3method(cnd_footer,monty_parse_error)
S3method(coda::as.mcmc.list,monty_samples)
S3method(posterior::as_draws_array,monty_samples)
S3method(posterior::as_draws_df,monty_samples)
S3method(print,monty_model)
S3method(print,monty_observer)
S3method(print,monty_packer)
S3method(print,monty_runner)
S3method(print,monty_sampler)
S3method(print,monty_samples)
export(monty_differentiation)
export(monty_domain_expand)
export(monty_dsl)
export(monty_dsl_distributions)
export(monty_dsl_error_explain)
export(monty_dsl_parse_distribution)
export(monty_model)
export(monty_model_combine)
export(monty_model_density)
export(monty_model_direct_sample)
export(monty_model_gradient)
export(monty_model_properties)
export(monty_observer)
export(monty_packer)
export(monty_rng)
export(monty_rng_distributed_pointer)
export(monty_rng_distributed_state)
export(monty_rng_pointer)
export(monty_runner_parallel)
export(monty_runner_serial)
export(monty_runner_simultaneous)
export(monty_sample)
export(monty_sample_continue)
export(monty_sampler_adaptive)
export(monty_sampler_hmc)
export(monty_sampler_nested_adaptive)
export(monty_sampler_nested_random_walk)
export(monty_sampler_random_walk)
export(with_trace_random)
importFrom(R6,R6Class)
importFrom(rlang,cnd_footer)
useDynLib(mcstate2, .registration = TRUE)
useDynLib(monty, .registration = TRUE)
26 changes: 13 additions & 13 deletions R/combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
##'
##' The `model` field will be an ordered, unnamed, list containing the
##' two elements corresponding to the first and second model (not the
##' `mcstate_model`, but the underlying model, perhaps?). This is the
##' `monty_model`, but the underlying model, perhaps?). This is the
##' only part that makes a distinction between the two models here;
##' for all components above they are equivalent.
##'
Expand All @@ -51,7 +51,7 @@
##'
##' @param b The second model
##'
##' @param properties An [mcstate_model_properties] object, used to
##' @param properties A [monty_model_properties] object, used to
##' control (or enforce) properties of the combined model.
##'
##' @param name_a Name of the first model (defaulting to 'a'); you can
Expand All @@ -62,14 +62,14 @@
##' use this to make error messages nicer to read, but it has no
##' other practical effect.
##'
##' @return An [mcstate_model] object
##' @return A [monty_model] object
##'
##' @export
mcstate_model_combine <- function(a, b, properties = NULL,
name_a = "a", name_b = "b") {
monty_model_combine <- function(a, b, properties = NULL,
name_a = "a", name_b = "b") {
call <- environment()
require_mcstate_model(a)
require_mcstate_model(b)
require_monty_model(a)
require_monty_model(b)
properties <- validate_model_properties(properties, call)

parameters <- union(a$parameters, b$parameters)
Expand All @@ -84,7 +84,7 @@ mcstate_model_combine <- function(a, b, properties = NULL,
stochastic <- model_combine_stochastic(
a, b, properties)

mcstate_model(
monty_model(
list(model = list(a, b),
parameters = parameters,
domain = domain,
Expand All @@ -98,13 +98,13 @@ mcstate_model_combine <- function(a, b, properties = NULL,


##' @export
`+.mcstate_model` <- function(x, y) {
if (!inherits(y, "mcstate_model")) {
`+.monty_model` <- function(x, y) {
if (!inherits(y, "monty_model")) {
cli::cli_abort(
paste("Addition via '+' is only defined for 'mcstate_model'",
"with other 'mcstate_model' objects"))
paste("Addition via '+' is only defined for 'monty_model'",
"with other 'monty_model' objects"))
}
mcstate_model_combine(x, y, properties = NULL, name_a = "lhs", name_b = "rhs")
monty_model_combine(x, y, properties = NULL, name_a = "lhs", name_b = "rhs")
}


Expand Down
88 changes: 44 additions & 44 deletions R/cpp11.R
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
# Generated by cpp11: do not edit by hand

mcstate_rng_alloc <- function(r_seed, n_streams, deterministic, is_float) {
.Call(`_mcstate2_mcstate_rng_alloc`, r_seed, n_streams, deterministic, is_float)
monty_rng_alloc <- function(r_seed, n_streams, deterministic, is_float) {
.Call(`_monty_monty_rng_alloc`, r_seed, n_streams, deterministic, is_float)
}

mcstate_rng_jump <- function(ptr, is_float) {
invisible(.Call(`_mcstate2_mcstate_rng_jump`, ptr, is_float))
monty_rng_jump <- function(ptr, is_float) {
invisible(.Call(`_monty_monty_rng_jump`, ptr, is_float))
}

mcstate_rng_long_jump <- function(ptr, is_float) {
invisible(.Call(`_mcstate2_mcstate_rng_long_jump`, ptr, is_float))
monty_rng_long_jump <- function(ptr, is_float) {
invisible(.Call(`_monty_monty_rng_long_jump`, ptr, is_float))
}

mcstate_rng_random_real <- function(ptr, n, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_random_real`, ptr, n, n_threads, is_float)
monty_rng_random_real <- function(ptr, n, n_threads, is_float) {
.Call(`_monty_monty_rng_random_real`, ptr, n, n_threads, is_float)
}

mcstate_rng_random_normal <- function(ptr, n, n_threads, algorithm, is_float) {
.Call(`_mcstate2_mcstate_rng_random_normal`, ptr, n, n_threads, algorithm, is_float)
monty_rng_random_normal <- function(ptr, n, n_threads, algorithm, is_float) {
.Call(`_monty_monty_rng_random_normal`, ptr, n, n_threads, algorithm, is_float)
}

mcstate_rng_uniform <- function(ptr, n, r_min, r_max, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_uniform`, ptr, n, r_min, r_max, n_threads, is_float)
monty_rng_uniform <- function(ptr, n, r_min, r_max, n_threads, is_float) {
.Call(`_monty_monty_rng_uniform`, ptr, n, r_min, r_max, n_threads, is_float)
}

mcstate_rng_exponential_rate <- function(ptr, n, r_rate, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_exponential_rate`, ptr, n, r_rate, n_threads, is_float)
monty_rng_exponential_rate <- function(ptr, n, r_rate, n_threads, is_float) {
.Call(`_monty_monty_rng_exponential_rate`, ptr, n, r_rate, n_threads, is_float)
}

mcstate_rng_exponential_mean <- function(ptr, n, r_mean, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_exponential_mean`, ptr, n, r_mean, n_threads, is_float)
monty_rng_exponential_mean <- function(ptr, n, r_mean, n_threads, is_float) {
.Call(`_monty_monty_rng_exponential_mean`, ptr, n, r_mean, n_threads, is_float)
}

mcstate_rng_normal <- function(ptr, n, r_mean, r_sd, n_threads, algorithm, is_float) {
.Call(`_mcstate2_mcstate_rng_normal`, ptr, n, r_mean, r_sd, n_threads, algorithm, is_float)
monty_rng_normal <- function(ptr, n, r_mean, r_sd, n_threads, algorithm, is_float) {
.Call(`_monty_monty_rng_normal`, ptr, n, r_mean, r_sd, n_threads, algorithm, is_float)
}

mcstate_rng_binomial <- function(ptr, n, r_size, r_prob, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_binomial`, ptr, n, r_size, r_prob, n_threads, is_float)
monty_rng_binomial <- function(ptr, n, r_size, r_prob, n_threads, is_float) {
.Call(`_monty_monty_rng_binomial`, ptr, n, r_size, r_prob, n_threads, is_float)
}

mcstate_rng_nbinomial <- function(ptr, n, r_size, r_prob, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_nbinomial`, ptr, n, r_size, r_prob, n_threads, is_float)
monty_rng_nbinomial <- function(ptr, n, r_size, r_prob, n_threads, is_float) {
.Call(`_monty_monty_rng_nbinomial`, ptr, n, r_size, r_prob, n_threads, is_float)
}

mcstate_rng_hypergeometric <- function(ptr, n, r_n1, r_n2, r_k, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_hypergeometric`, ptr, n, r_n1, r_n2, r_k, n_threads, is_float)
monty_rng_hypergeometric <- function(ptr, n, r_n1, r_n2, r_k, n_threads, is_float) {
.Call(`_monty_monty_rng_hypergeometric`, ptr, n, r_n1, r_n2, r_k, n_threads, is_float)
}

mcstate_rng_gamma_scale <- function(ptr, n, r_shape, r_scale, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_gamma_scale`, ptr, n, r_shape, r_scale, n_threads, is_float)
monty_rng_gamma_scale <- function(ptr, n, r_shape, r_scale, n_threads, is_float) {
.Call(`_monty_monty_rng_gamma_scale`, ptr, n, r_shape, r_scale, n_threads, is_float)
}

mcstate_rng_gamma_rate <- function(ptr, n, r_shape, r_rate, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_gamma_rate`, ptr, n, r_shape, r_rate, n_threads, is_float)
monty_rng_gamma_rate <- function(ptr, n, r_shape, r_rate, n_threads, is_float) {
.Call(`_monty_monty_rng_gamma_rate`, ptr, n, r_shape, r_rate, n_threads, is_float)
}

mcstate_rng_poisson <- function(ptr, n, r_lambda, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_poisson`, ptr, n, r_lambda, n_threads, is_float)
monty_rng_poisson <- function(ptr, n, r_lambda, n_threads, is_float) {
.Call(`_monty_monty_rng_poisson`, ptr, n, r_lambda, n_threads, is_float)
}

mcstate_rng_cauchy <- function(ptr, n, r_location, r_scale, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_cauchy`, ptr, n, r_location, r_scale, n_threads, is_float)
monty_rng_cauchy <- function(ptr, n, r_location, r_scale, n_threads, is_float) {
.Call(`_monty_monty_rng_cauchy`, ptr, n, r_location, r_scale, n_threads, is_float)
}

mcstate_rng_beta <- function(ptr, n, r_a, r_b, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_beta`, ptr, n, r_a, r_b, n_threads, is_float)
monty_rng_beta <- function(ptr, n, r_a, r_b, n_threads, is_float) {
.Call(`_monty_monty_rng_beta`, ptr, n, r_a, r_b, n_threads, is_float)
}

mcstate_rng_multinomial <- function(ptr, n, r_size, r_prob, n_threads, is_float) {
.Call(`_mcstate2_mcstate_rng_multinomial`, ptr, n, r_size, r_prob, n_threads, is_float)
monty_rng_multinomial <- function(ptr, n, r_size, r_prob, n_threads, is_float) {
.Call(`_monty_monty_rng_multinomial`, ptr, n, r_size, r_prob, n_threads, is_float)
}

mcstate_rng_state <- function(ptr, is_float) {
.Call(`_mcstate2_mcstate_rng_state`, ptr, is_float)
monty_rng_state <- function(ptr, is_float) {
.Call(`_monty_monty_rng_state`, ptr, is_float)
}

mcstate_rng_pointer_init <- function(n_streams, seed, long_jump, algorithm) {
.Call(`_mcstate2_mcstate_rng_pointer_init`, n_streams, seed, long_jump, algorithm)
monty_rng_pointer_init <- function(n_streams, seed, long_jump, algorithm) {
.Call(`_monty_monty_rng_pointer_init`, n_streams, seed, long_jump, algorithm)
}

mcstate_rng_pointer_sync <- function(obj, algorithm) {
invisible(.Call(`_mcstate2_mcstate_rng_pointer_sync`, obj, algorithm))
monty_rng_pointer_sync <- function(obj, algorithm) {
invisible(.Call(`_monty_monty_rng_pointer_sync`, obj, algorithm))
}

test_rng_pointer_get <- function(obj, n_streams) {
.Call(`_mcstate2_test_rng_pointer_get`, obj, n_streams)
.Call(`_monty_test_rng_pointer_get`, obj, n_streams)
}

test_xoshiro_run <- function(obj) {
.Call(`_mcstate2_test_xoshiro_run`, obj)
.Call(`_monty_test_xoshiro_run`, obj)
}
20 changes: 10 additions & 10 deletions R/domain.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
##' Check and expand a domain, where it is used alongside a
##' [mcstate_packer] object. This can be used to expand domains for
##' [monty_packer] object. This can be used to expand domains for
##' logical parameters (e.g. a vector `b`) into its specific names
##' (e.g., `b[1]`, `b[2]`, etc) without having to rely on the
##' internals about how these names are constructed.
##'
##' @title Expand (and check) domain against a packer
##'
##' @param domain A two-column matrix as defined in [mcstate_model],
##' @param domain A two-column matrix as defined in [monty_model],
##' with row names corresponding to either logical names (e.g., `b`)
##' or specific names `b[1]` that are present in your packer.
##' `NULL` is allowed where all parameters are defined over the
##' entire real line.
##'
##' @param packer A [mcstate_packer] object
##' @param packer A [monty_packer] object
##'
##' @return A two dimensional matrix representing your domain, or
##' `NULL` if `domain` was given as `NULL`.
##'
##' @export
##' @examples
##'
##' packer <- mcstate_packer(c("a", "b"), list(x = 3, y = c(2, 2)))
##' mcstate_domain_expand(NULL, packer)
##' mcstate_domain_expand(rbind(x = c(0, 1)), packer)
##' mcstate_domain_expand(rbind(x = c(0, 1), "x[2]" = c(0, Inf)), packer)
##' mcstate_domain_expand(rbind(x = c(0, 1), "y" = c(0, Inf)), packer)
mcstate_domain_expand <- function(domain, packer) {
assert_is(packer, "mcstate_packer")
##' packer <- monty_packer(c("a", "b"), list(x = 3, y = c(2, 2)))
##' monty_domain_expand(NULL, packer)
##' monty_domain_expand(rbind(x = c(0, 1)), packer)
##' monty_domain_expand(rbind(x = c(0, 1), "x[2]" = c(0, Inf)), packer)
##' monty_domain_expand(rbind(x = c(0, 1), "y" = c(0, Inf)), packer)
monty_domain_expand <- function(domain, packer) {
assert_is(packer, "monty_packer")
if (is.null(domain)) {
return(domain)
}
Expand Down
4 changes: 2 additions & 2 deletions R/dsl-adjoint.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dsl_parse_adjoint <- function(parameters, exprs, required, call = NULL) {
exprs <- adjoint_rewrite_stochastic(parameters, exprs)
rlang::try_fetch(
adjoint_create(parameters, exprs),
mcstate2_parse_error = function(e) {
monty_parse_error = function(e) {
if (is.null(required)) {
## TODO: this might change as #52 is merged, to print slightly
## more nicely. At present we need one extra parent on this
Expand Down Expand Up @@ -96,7 +96,7 @@ adjoint_create <- function(parameters, exprs, call = NULL) {
differentiate_or_rethrow <- function(eq, nm) {
rlang::try_fetch(
differentiate(eq$rhs, nm),
mcstate_differentiation_failure = function(e) {
monty_differentiation_failure = function(e) {
expr <- (eq$original %||% eq)$expr
dsl_parse_error("Failed to differentiate this model",
"E206", expr, call = call, parent = e)
Expand Down
Loading

0 comments on commit 3405cf3

Please sign in to comment.