From 4398f7a8676255774fdb6794f55b94f890efc18e Mon Sep 17 00:00:00 2001 From: KeithJF82 Date: Tue, 25 Jun 2024 18:28:27 +0100 Subject: [PATCH] Further tidying Option for exponential MCMC prior removed (unused); package recompiled with new version of odin.dust to get rid of error. --- R/dust.R | 2 +- R/mcmc.R | 42 ++++++++++++++++++++------------------ inst/dust/SEIRV_Model.cpp | 4 ++-- man/MCMC.Rd | 8 +++++--- man/mcmc_FOI_R0_setup.Rd | 8 +++++--- man/mcmc_checks.Rd | 8 +++++--- man/mcmc_prelim_fit.Rd | 8 +++++--- src/SEIRV_Model.cpp | 4 ++-- src/SEIRV_Model.o | Bin 4524349 -> 4524349 bytes src/YEP.dll | Bin 6380744 -> 6380744 bytes src/cpp11.o | Bin 275586 -> 275586 bytes 11 files changed, 47 insertions(+), 37 deletions(-) diff --git a/R/dust.R b/R/dust.R index 04f777a..74143c6 100644 --- a/R/dust.R +++ b/R/dust.R @@ -281,7 +281,7 @@ SEIRV_Model <- R6::R6Class( } )) class(SEIRV_Model) <- c("dust_generator", class(SEIRV_Model)) -## Generated by odin.dust (version 0.3.10) - do not edit +## Generated by odin.dust (version 0.3.11) - do not edit SEIRV_Model$set("public", "transform_variables", function(y) { info <- self$info() set_dim <- function(x, dimx) { diff --git a/R/mcmc.R b/R/mcmc.R index 156abed..aa4e5b8 100644 --- a/R/mcmc.R +++ b/R/mcmc.R @@ -36,10 +36,12 @@ #' If type = "zero", prior probability is always zero \cr #' If type = "flat", prior probability is zero if log parameter values in designated ranges log_params_min and log_params_max, \cr #' -Inf otherwise; log_params_min and log_params_max included in prior_settings as vectors of same length as log_params_ini -#' If type = "exp", prior probability is given by dexp calculation on FOI/R0 values \cr #' If type = "norm", prior probability is given by dnorm calculation on parameter values with settings based on vectors of values -#' in prior_settings; norm_params_mean and norm_params_sd (mean and standard deviation values applied to log FOI/R0 -#' parameters and to actual values of additional parameters) + R0_mean + R0_sd (mean + standard deviation of computed R0, single values) +#' in prior_settings: \cr +#' norm_params_mean and norm_params_sd (vectors of mean and standard deviation values applied to log FOI/R0 +#' parameters and to actual values of additional parameters) \cr +#' + FOI_mean + FOI_sd (mean + standard deviation of computed FOI, single values) \cr +#' + R0_mean + R0_sd (mean + standard deviation of computed R0, single values) \cr #' @param dt time increment in days (must be 1 or 5) #' @param n_reps Number of times to repeat calculations to get average likelihood at each step #' @param enviro_data Data frame containing values of environmental covariates @@ -287,10 +289,12 @@ single_posterior_calc <- function(log_params_prop = c(), input_data = list(), ob #' If type = "zero", prior probability is always zero \cr #' If type = "flat", prior probability is zero if log parameter values in designated ranges log_params_min and log_params_max, #' -Inf otherwise; log_params_min and log_params_max included in prior_settings as vectors of same length as log_params_ini \cr -#' If type = "exp", prior probability is given by dexp calculation on FOI/R0 values \cr #' If type = "norm", prior probability is given by dnorm calculation on parameter values with settings based on vectors of values -#' in prior_settings; norm_params_mean and norm_params_sd (mean and standard deviation values applied to log FOI/R0 -#' parameters and to actual values of additional parameters) + R0_mean + R0_sd (mean + standard deviation of computed R0, single values) +#' in prior_settings: \cr +#' norm_params_mean and norm_params_sd (vectors of mean and standard deviation values applied to log FOI/R0 +#' parameters and to actual values of additional parameters) \cr +#' + FOI_mean + FOI_sd (mean + standard deviation of computed FOI, single values) \cr +#' + R0_mean + R0_sd (mean + standard deviation of computed R0, single values) \cr #' @param enviro_data Values of environmental covariates #' @param add_values List of parameters in addition to those governing FOI/R0, either giving a fixed value or giving NA to #' indicate that they are part of the parameter set to be estimated \cr @@ -309,7 +313,7 @@ mcmc_checks <- function(log_params_ini = c(), n_regions = 1, prior_settings = li param_names = names(log_params_ini) n_params = length(log_params_ini) assert_that(is.null(param_names) == FALSE, msg = "Parameters should be named using create_param_labels") - assert_that(prior_settings$type %in% c("zero", "flat", "exp", "norm"), msg = "Check prior_settings$type") + assert_that(prior_settings$type %in% c("zero", "flat", "norm"), msg = "Check prior_settings$type") if(prior_settings$type == "flat"){ assert_that(length(prior_settings$log_params_min) == n_params, msg = "Check prior_settings$log_params_min") assert_that(length(prior_settings$log_params_max) == n_params, msg = "Check prior_settings$log_params_max") @@ -391,10 +395,12 @@ param_prop_setup <- function(log_params = c(), chain_cov = 1, adapt = 0){ #' If type = "zero", prior probability is always zero \cr #' If type = "flat", prior probability is zero if log parameter values in designated ranges log_params_min and log_params_max, #' -Inf otherwise; log_params_min and log_params_max included in prior_settings as vectors of same length as log_params_ini \cr -#' If type = "exp", prior probability is given by dexp calculation on FOI/R0 values \cr #' If type = "norm", prior probability is given by dnorm calculation on parameter values with settings based on vectors of values -#' in prior_settings; norm_params_mean and norm_params_sd (mean and standard deviation values applied to log FOI/R0 -#' parameters and to actual values of additional parameters) + R0_mean + R0_sd (mean + standard deviation of computed R0, single values) +#' in prior_settings: \cr +#' norm_params_mean and norm_params_sd (vectors of mean and standard deviation values applied to log FOI/R0 +#' parameters and to actual values of additional parameters) \cr +#' + FOI_mean + FOI_sd (mean + standard deviation of computed FOI, single values) \cr +#' + R0_mean + R0_sd (mean + standard deviation of computed R0, single values) \cr #' @param regions Vector of region names #' @param log_params_prop Proposed values of parameters (natural logarithm of actual parameters) #' @param enviro_data Environmental data frame, containing only relevant environmental covariate values @@ -427,12 +433,6 @@ mcmc_FOI_R0_setup <- function(prior_settings = list(type = "zero"), regions = "" if(log_params_prop[i]prior_settings$log_params_max[i]){prior = -Inf} } - } else { - if(prior_settings$type == "exp"){ - prior_FOI = dexp(FOI_values, rate = 1, log = TRUE) - prior_R0 = dexp(R0_values, rate = 1, log = TRUE) - prior = prior+sum(prior_FOI)+sum(prior_R0) - } } } @@ -468,10 +468,12 @@ mcmc_FOI_R0_setup <- function(prior_settings = list(type = "zero"), regions = "" #' If type = "zero", prior probability is always zero \cr #' If type = "flat", prior probability is zero if log parameter values in designated ranges log_params_min and log_params_max, #' -Inf otherwise; log_params_min and log_params_max included in prior_settings as vectors of same length as log_params_ini \cr -#' If type = "exp", prior probability is given by dexp calculation on FOI/R0 values \cr #' If type = "norm", prior probability is given by dnorm calculation on parameter values with settings based on vectors of values -#' in prior_settings; norm_params_mean and norm_params_sd (mean and standard deviation values applied to log FOI/R0 -#' parameters and to actual values of additional parameters) + R0_mean + R0_sd (mean + standard deviation of computed R0, single values) +#' in prior_settings: \cr +#' norm_params_mean and norm_params_sd (vectors of mean and standard deviation values applied to log FOI/R0 +#' parameters and to actual values of additional parameters) \cr +#' + FOI_mean + FOI_sd (mean + standard deviation of computed FOI, single values) \cr +#' + R0_mean + R0_sd (mean + standard deviation of computed R0, single values) \cr #' @param dt time increment in days (must be 1 or 5) #' @param n_reps Number of repetitions #' @param enviro_data Values of environmental variables (if in use) @@ -499,7 +501,7 @@ mcmc_prelim_fit <- function(n_iterations = 1, n_param_sets = 1, n_bounds = 1, lo #TODO - Add assertthat functions assert_that(mode_start %in% c(0, 1, 3), msg = "mode_start must have value 0, 1 or 3") assert_that(length(log_params_min) == length(log_params_max), msg = "Parameter limit vectors must have same lengths") - assert_that(prior_settings$type %in% c("zero", "exp", "norm"), msg = "Prior type must be 'zero', 'exp' or 'norm'") + assert_that(prior_settings$type %in% c("zero", "norm"), msg = "Prior type must be 'zero', or 'norm'") best_fit_results = list() n_params = length(log_params_min) diff --git a/inst/dust/SEIRV_Model.cpp b/inst/dust/SEIRV_Model.cpp index d9b84ab..ffe0c1f 100644 --- a/inst/dust/SEIRV_Model.cpp +++ b/inst/dust/SEIRV_Model.cpp @@ -1,4 +1,4 @@ -// Generated by odin.dust (version 0.3.10) - do not edit +// Generated by odin.dust (version 0.3.11) - do not edit template __host__ __device__ real_type odin_sum1(const container x, size_t from, size_t to); template @@ -325,7 +325,7 @@ void user_check_array_dim(cpp11::sexp x, const char *name, cpp11::integers dim = cpp11::as_cpp(x.attr("dim")); for (size_t i = 0; i < N; ++i) { if (dim[(int)i] != dim_expected[i]) { - Rf_error("Incorrect size of dimension %d of '%s' (expected %d)", + Rf_error("Incorrect size of dimension %zu of '%s' (expected %d)", i + 1, name, dim_expected[i]); } } diff --git a/man/MCMC.Rd b/man/MCMC.Rd index 16febc0..344f7a7 100644 --- a/man/MCMC.Rd +++ b/man/MCMC.Rd @@ -61,10 +61,12 @@ If mode_start = 3, shift some non-vaccinated individuals into recovered to give If type = "zero", prior probability is always zero \cr If type = "flat", prior probability is zero if log parameter values in designated ranges log_params_min and log_params_max, \cr -Inf otherwise; log_params_min and log_params_max included in prior_settings as vectors of same length as log_params_ini -If type = "exp", prior probability is given by dexp calculation on FOI/R0 values \cr If type = "norm", prior probability is given by dnorm calculation on parameter values with settings based on vectors of values - in prior_settings; norm_params_mean and norm_params_sd (mean and standard deviation values applied to log FOI/R0 - parameters and to actual values of additional parameters) + R0_mean + R0_sd (mean + standard deviation of computed R0, single values)} + in prior_settings: \cr + norm_params_mean and norm_params_sd (vectors of mean and standard deviation values applied to log FOI/R0 + parameters and to actual values of additional parameters) \cr + + FOI_mean + FOI_sd (mean + standard deviation of computed FOI, single values) \cr + + R0_mean + R0_sd (mean + standard deviation of computed R0, single values) \cr} \item{dt}{time increment in days (must be 1 or 5)} diff --git a/man/mcmc_FOI_R0_setup.Rd b/man/mcmc_FOI_R0_setup.Rd index 8b891d0..2635615 100644 --- a/man/mcmc_FOI_R0_setup.Rd +++ b/man/mcmc_FOI_R0_setup.Rd @@ -16,10 +16,12 @@ mcmc_FOI_R0_setup( If type = "zero", prior probability is always zero \cr If type = "flat", prior probability is zero if log parameter values in designated ranges log_params_min and log_params_max, -Inf otherwise; log_params_min and log_params_max included in prior_settings as vectors of same length as log_params_ini \cr -If type = "exp", prior probability is given by dexp calculation on FOI/R0 values \cr If type = "norm", prior probability is given by dnorm calculation on parameter values with settings based on vectors of values - in prior_settings; norm_params_mean and norm_params_sd (mean and standard deviation values applied to log FOI/R0 - parameters and to actual values of additional parameters) + R0_mean + R0_sd (mean + standard deviation of computed R0, single values)} + in prior_settings: \cr + norm_params_mean and norm_params_sd (vectors of mean and standard deviation values applied to log FOI/R0 + parameters and to actual values of additional parameters) \cr + + FOI_mean + FOI_sd (mean + standard deviation of computed FOI, single values) \cr + + R0_mean + R0_sd (mean + standard deviation of computed R0, single values) \cr} \item{regions}{Vector of region names} diff --git a/man/mcmc_checks.Rd b/man/mcmc_checks.Rd index c17c66e..25b9a6d 100644 --- a/man/mcmc_checks.Rd +++ b/man/mcmc_checks.Rd @@ -23,10 +23,12 @@ mcmc_checks( If type = "zero", prior probability is always zero \cr If type = "flat", prior probability is zero if log parameter values in designated ranges log_params_min and log_params_max, -Inf otherwise; log_params_min and log_params_max included in prior_settings as vectors of same length as log_params_ini \cr -If type = "exp", prior probability is given by dexp calculation on FOI/R0 values \cr If type = "norm", prior probability is given by dnorm calculation on parameter values with settings based on vectors of values - in prior_settings; norm_params_mean and norm_params_sd (mean and standard deviation values applied to log FOI/R0 - parameters and to actual values of additional parameters) + R0_mean + R0_sd (mean + standard deviation of computed R0, single values)} + in prior_settings: \cr + norm_params_mean and norm_params_sd (vectors of mean and standard deviation values applied to log FOI/R0 + parameters and to actual values of additional parameters) \cr + + FOI_mean + FOI_sd (mean + standard deviation of computed FOI, single values) \cr + + R0_mean + R0_sd (mean + standard deviation of computed R0, single values) \cr} \item{enviro_data}{Values of environmental covariates} diff --git a/man/mcmc_prelim_fit.Rd b/man/mcmc_prelim_fit.Rd index 6b7564b..61a0f2c 100644 --- a/man/mcmc_prelim_fit.Rd +++ b/man/mcmc_prelim_fit.Rd @@ -57,10 +57,12 @@ If mode_start = 3, shift some non-vaccinated individuals into recovered to give If type = "zero", prior probability is always zero \cr If type = "flat", prior probability is zero if log parameter values in designated ranges log_params_min and log_params_max, -Inf otherwise; log_params_min and log_params_max included in prior_settings as vectors of same length as log_params_ini \cr -If type = "exp", prior probability is given by dexp calculation on FOI/R0 values \cr If type = "norm", prior probability is given by dnorm calculation on parameter values with settings based on vectors of values - in prior_settings; norm_params_mean and norm_params_sd (mean and standard deviation values applied to log FOI/R0 - parameters and to actual values of additional parameters) + R0_mean + R0_sd (mean + standard deviation of computed R0, single values)} + in prior_settings: \cr + norm_params_mean and norm_params_sd (vectors of mean and standard deviation values applied to log FOI/R0 + parameters and to actual values of additional parameters) \cr + + FOI_mean + FOI_sd (mean + standard deviation of computed FOI, single values) \cr + + R0_mean + R0_sd (mean + standard deviation of computed R0, single values) \cr} \item{dt}{time increment in days (must be 1 or 5)} diff --git a/src/SEIRV_Model.cpp b/src/SEIRV_Model.cpp index 45c4958..3ac13fa 100644 --- a/src/SEIRV_Model.cpp +++ b/src/SEIRV_Model.cpp @@ -72,7 +72,7 @@ void dust_cpu_SEIRV_Model_set_stochastic_schedule(SEXP ptr, SEXP time); SEXP dust_cpu_SEIRV_Model_ode_statistics(SEXP ptr); #include -// Generated by odin.dust (version 0.3.10) - do not edit +// Generated by odin.dust (version 0.3.11) - do not edit template __host__ __device__ real_type odin_sum1(const container x, size_t from, size_t to); template @@ -399,7 +399,7 @@ void user_check_array_dim(cpp11::sexp x, const char *name, cpp11::integers dim = cpp11::as_cpp(x.attr("dim")); for (size_t i = 0; i < N; ++i) { if (dim[(int)i] != dim_expected[i]) { - Rf_error("Incorrect size of dimension %d of '%s' (expected %d)", + Rf_error("Incorrect size of dimension %zu of '%s' (expected %d)", i + 1, name, dim_expected[i]); } } diff --git a/src/SEIRV_Model.o b/src/SEIRV_Model.o index ba471a677f453d128e91400f964040daef49e49d..2e299aa748b63d3bad9ca2942abeb78e166cb784 100644 GIT binary patch delta 335 zcmWm5xlRH>0Dxh3-5EqY00qGv@Td67Z~pad&hgS&;e7TV~biyr!T(392R G$N2~Onw#+e delta 334 zcmWm5J5B;Y0Dxf@c1BP^dHI?Z6c${;1>XuPENVwV1w9D~hp?g8ghV=H!aWShR2;&J z!iLUk@Kb!{H~;z$&N1>0Kj?>ib0#chrma9=8gIy|?kMqDHwM$cu4s)_PiWPX_J?6> z?^pf{!`040wj-vy4*j7_jVDWq4TKTFCbqDRC}P;bF5*ZaiS ER!B;lVE_OC diff --git a/src/YEP.dll b/src/YEP.dll index 441d06dd31cf4b04d0816645b17cd903338ed9ba..4bac6beb7c92ac92337b549a6feedcd4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