Skip to content

Commit

Permalink
Pass multiple random seeds to pops-core (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrasovaa authored Apr 29, 2024
1 parent 96b83ad commit 38a19e3
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ random_seeds_file_checks <- function(x, number_of_iterations = 1) {

if (checks_passed) {
random_seeds <- read.table(x, sep = ",", header = TRUE)
if (base::ncol(random_seeds) != 9 || base::nrow(random_seeds) <= number_of_iterations) {
if (base::ncol(random_seeds) != 10 || base::nrow(random_seeds) <= number_of_iterations) {
checks_passed <- FALSE
failed_check <- random_seeds_dimensions_error
}
Expand Down
1 change: 1 addition & 0 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ create_random_seeds <- function(n) {
anthropogenic_dispersal = sample(1:999999999999, n, replace = FALSE),
establishment = sample(1:999999999, n, replace = FALSE),
weather = sample(1:999999999, n, replace = FALSE),
lethal_temperature = sample(1:999999999, n, replace = FALSE),
movement = sample(1:999999999, n, replace = FALSE),
overpopulation = sample(1:999999999, n, replace = FALSE),
survival_rate = sample(1:999999999, n, replace = FALSE),
Expand Down
8 changes: 4 additions & 4 deletions R/pops_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
#' of dispersers that fall to the soil and survive.
#' @param soil_reservoirs list of matrices with soil pests created from soil_pest_file.
#' @param random_seeds vector of random seeds in the order of "disperser_generation",
#' "natural_dispersal", "anthropogenic_dispersal", "establishment", "weather", "movement",
#' "overpopulation", "survival_rate", "soil"
#' "natural_dispersal", "anthropogenic_dispersal", "establishment", "weather",
#' "lethal_temperature", "movement", "overpopulation", "survival_rate", "soil"
#'
#' @return list of vector matrices of infected and susceptible hosts per
#' simulated year and associated statistics (e.g. spread rate)
Expand Down Expand Up @@ -218,8 +218,8 @@ pops_model <-

data <-
suppressWarnings(pops_model_cpp(random_seed = random_seed,
multiple_random_seeds,
random_seeds,
multiple_random_seeds = multiple_random_seeds,
random_seeds = random_seeds,
lethal_temperature = lethal_temperature,
lethal_temperature_month = lethal_temperature_month,
host_pools = host_pools,
Expand Down
8 changes: 4 additions & 4 deletions inst/extdata/simple2x2/randoms.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"disperser_generation","natural_dispersal","anthropogenic_dispersal","establishment","weather","movement","overpopulation","survival_rate","soil"
996292699,421557257,385173832685,233255382,277700357,5882493,141871612,243207946,297251982
339502238,794154015,385173832685,868856436,605415172,268034709,468192168,938812543,964803710
709470618,221623141,385173832685,137416076,182481148,728626102,535321254,54098512,597436749
"disperser_generation","natural_dispersal","anthropogenic_dispersal","establishment","weather","lethal_temperature","movement","overpopulation","survival_rate","soil"
996292699,421557257,385173832685,233255382,277700357,609919634,5882493,141871612,243207946,297251982
339502238,794154015,385173832685,868856436,605415172,609919634,268034709,468192168,938812543,964803710
709470618,221623141,385173832685,137416076,182481148,609919634,728626102,535321254,54098512,597436749
4 changes: 2 additions & 2 deletions inst/include/PoPS_RcppExports.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ namespace PoPS {
}
}

inline List pops_model_cpp(int random_seed, bool multiple_random_seeds, std::vector<int> random_seeds, double lethal_temperature, int lethal_temperature_month, std::vector<List> host_pools, IntegerMatrix total_populations, std::vector<std::vector<double>> competency_table, std::vector<std::vector<double>> pest_host_table, IntegerMatrix quarantine_areas, std::string quarantine_directions, std::vector<NumericMatrix> treatment_maps, std::vector<std::string> treatment_dates, std::vector<int> pesticide_duration, std::vector<std::vector<int>> movements, std::vector<std::string> movements_dates, std::vector<NumericMatrix> temperature, std::vector<NumericMatrix> survival_rates, std::vector<NumericMatrix> weather_coefficient, std::vector<NumericMatrix> weather_coefficient_sd, List bbox, List res, List rows_cols, std::vector<IntegerMatrix> soil_reservoirs, double reproductive_rate, std::vector<std::vector<int>> spatial_indices, List season_month_start_end, List frequency_config, List bool_config, std::string start_date = "2018-01-01", std::string end_date = "2018-12-31", std::string treatment_method = "ratio", std::string natural_kernel_type = "cauchy", std::string anthropogenic_kernel_type = "cauchy", double percent_natural_dispersal = 0.0, double natural_distance_scale = 21, double anthropogenic_distance_scale = 0.0, std::string natural_dir = "NONE", double natural_kappa = 0, std::string anthropogenic_dir = "NONE", double anthropogenic_kappa = 0, Nullable<List> frequencies_n_config = R_NilValue, std::string model_type_ = "SI", int latency_period = 0, double establishment_probability = 0, double dispersal_percentage = 0.99, int survival_rate_month = 0, int survival_rate_day = 0, Nullable<List> overpopulation_config = R_NilValue, Nullable<List> network_config = R_NilValue, Nullable<List> network_data_config = R_NilValue, int weather_size = 0, std::string weather_type = "deterministic", double dispersers_to_soils_percentage = 0) {
inline List pops_model_cpp(int random_seed, bool multiple_random_seeds, std::vector<unsigned> random_seeds, double lethal_temperature, int lethal_temperature_month, std::vector<List> host_pools, IntegerMatrix total_populations, std::vector<std::vector<double>> competency_table, std::vector<std::vector<double>> pest_host_table, IntegerMatrix quarantine_areas, std::string quarantine_directions, std::vector<NumericMatrix> treatment_maps, std::vector<std::string> treatment_dates, std::vector<int> pesticide_duration, std::vector<std::vector<int>> movements, std::vector<std::string> movements_dates, std::vector<NumericMatrix> temperature, std::vector<NumericMatrix> survival_rates, std::vector<NumericMatrix> weather_coefficient, std::vector<NumericMatrix> weather_coefficient_sd, List bbox, List res, List rows_cols, std::vector<IntegerMatrix> soil_reservoirs, double reproductive_rate, std::vector<std::vector<int>> spatial_indices, List season_month_start_end, List frequency_config, List bool_config, std::string start_date = "2018-01-01", std::string end_date = "2018-12-31", std::string treatment_method = "ratio", std::string natural_kernel_type = "cauchy", std::string anthropogenic_kernel_type = "cauchy", double percent_natural_dispersal = 0.0, double natural_distance_scale = 21, double anthropogenic_distance_scale = 0.0, std::string natural_dir = "NONE", double natural_kappa = 0, std::string anthropogenic_dir = "NONE", double anthropogenic_kappa = 0, Nullable<List> frequencies_n_config = R_NilValue, std::string model_type_ = "SI", int latency_period = 0, double establishment_probability = 0, double dispersal_percentage = 0.99, int survival_rate_month = 0, int survival_rate_day = 0, Nullable<List> overpopulation_config = R_NilValue, Nullable<List> network_config = R_NilValue, Nullable<List> network_data_config = R_NilValue, int weather_size = 0, std::string weather_type = "deterministic", double dispersers_to_soils_percentage = 0) {
typedef SEXP(*Ptr_pops_model_cpp)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP);
static Ptr_pops_model_cpp p_pops_model_cpp = NULL;
if (p_pops_model_cpp == NULL) {
validateSignature("List(*pops_model_cpp)(int,bool,std::vector<int>,double,int,std::vector<List>,IntegerMatrix,std::vector<std::vector<double>>,std::vector<std::vector<double>>,IntegerMatrix,std::string,std::vector<NumericMatrix>,std::vector<std::string>,std::vector<int>,std::vector<std::vector<int>>,std::vector<std::string>,std::vector<NumericMatrix>,std::vector<NumericMatrix>,std::vector<NumericMatrix>,std::vector<NumericMatrix>,List,List,List,std::vector<IntegerMatrix>,double,std::vector<std::vector<int>>,List,List,List,std::string,std::string,std::string,std::string,std::string,double,double,double,std::string,double,std::string,double,Nullable<List>,std::string,int,double,double,int,int,Nullable<List>,Nullable<List>,Nullable<List>,int,std::string,double)");
validateSignature("List(*pops_model_cpp)(int,bool,std::vector<unsigned>,double,int,std::vector<List>,IntegerMatrix,std::vector<std::vector<double>>,std::vector<std::vector<double>>,IntegerMatrix,std::string,std::vector<NumericMatrix>,std::vector<std::string>,std::vector<int>,std::vector<std::vector<int>>,std::vector<std::string>,std::vector<NumericMatrix>,std::vector<NumericMatrix>,std::vector<NumericMatrix>,std::vector<NumericMatrix>,List,List,List,std::vector<IntegerMatrix>,double,std::vector<std::vector<int>>,List,List,List,std::string,std::string,std::string,std::string,std::string,double,double,double,std::string,double,std::string,double,Nullable<List>,std::string,int,double,double,int,int,Nullable<List>,Nullable<List>,Nullable<List>,int,std::string,double)");
p_pops_model_cpp = (Ptr_pops_model_cpp)R_GetCCallable("PoPS", "_PoPS_pops_model_cpp");
}
RObject rcpp_result_gen;
Expand Down
6 changes: 3 additions & 3 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// pops_model_cpp
List pops_model_cpp(int random_seed, bool multiple_random_seeds, std::vector<int> random_seeds, double lethal_temperature, int lethal_temperature_month, std::vector<List> host_pools, IntegerMatrix total_populations, std::vector<std::vector<double>> competency_table, std::vector<std::vector<double>> pest_host_table, IntegerMatrix quarantine_areas, std::string quarantine_directions, std::vector<NumericMatrix> treatment_maps, std::vector<std::string> treatment_dates, std::vector<int> pesticide_duration, std::vector<std::vector<int>> movements, std::vector<std::string> movements_dates, std::vector<NumericMatrix> temperature, std::vector<NumericMatrix> survival_rates, std::vector<NumericMatrix> weather_coefficient, std::vector<NumericMatrix> weather_coefficient_sd, List bbox, List res, List rows_cols, std::vector<IntegerMatrix> soil_reservoirs, double reproductive_rate, std::vector<std::vector<int>> spatial_indices, List season_month_start_end, List frequency_config, List bool_config, std::string start_date, std::string end_date, std::string treatment_method, std::string natural_kernel_type, std::string anthropogenic_kernel_type, double percent_natural_dispersal, double natural_distance_scale, double anthropogenic_distance_scale, std::string natural_dir, double natural_kappa, std::string anthropogenic_dir, double anthropogenic_kappa, Nullable<List> frequencies_n_config, std::string model_type_, int latency_period, double establishment_probability, double dispersal_percentage, int survival_rate_month, int survival_rate_day, Nullable<List> overpopulation_config, Nullable<List> network_config, Nullable<List> network_data_config, int weather_size, std::string weather_type, double dispersers_to_soils_percentage);
List pops_model_cpp(int random_seed, bool multiple_random_seeds, std::vector<unsigned> random_seeds, double lethal_temperature, int lethal_temperature_month, std::vector<List> host_pools, IntegerMatrix total_populations, std::vector<std::vector<double>> competency_table, std::vector<std::vector<double>> pest_host_table, IntegerMatrix quarantine_areas, std::string quarantine_directions, std::vector<NumericMatrix> treatment_maps, std::vector<std::string> treatment_dates, std::vector<int> pesticide_duration, std::vector<std::vector<int>> movements, std::vector<std::string> movements_dates, std::vector<NumericMatrix> temperature, std::vector<NumericMatrix> survival_rates, std::vector<NumericMatrix> weather_coefficient, std::vector<NumericMatrix> weather_coefficient_sd, List bbox, List res, List rows_cols, std::vector<IntegerMatrix> soil_reservoirs, double reproductive_rate, std::vector<std::vector<int>> spatial_indices, List season_month_start_end, List frequency_config, List bool_config, std::string start_date, std::string end_date, std::string treatment_method, std::string natural_kernel_type, std::string anthropogenic_kernel_type, double percent_natural_dispersal, double natural_distance_scale, double anthropogenic_distance_scale, std::string natural_dir, double natural_kappa, std::string anthropogenic_dir, double anthropogenic_kappa, Nullable<List> frequencies_n_config, std::string model_type_, int latency_period, double establishment_probability, double dispersal_percentage, int survival_rate_month, int survival_rate_day, Nullable<List> overpopulation_config, Nullable<List> network_config, Nullable<List> network_data_config, int weather_size, std::string weather_type, double dispersers_to_soils_percentage);
static SEXP _PoPS_pops_model_cpp_try(SEXP random_seedSEXP, SEXP multiple_random_seedsSEXP, SEXP random_seedsSEXP, SEXP lethal_temperatureSEXP, SEXP lethal_temperature_monthSEXP, SEXP host_poolsSEXP, SEXP total_populationsSEXP, SEXP competency_tableSEXP, SEXP pest_host_tableSEXP, SEXP quarantine_areasSEXP, SEXP quarantine_directionsSEXP, SEXP treatment_mapsSEXP, SEXP treatment_datesSEXP, SEXP pesticide_durationSEXP, SEXP movementsSEXP, SEXP movements_datesSEXP, SEXP temperatureSEXP, SEXP survival_ratesSEXP, SEXP weather_coefficientSEXP, SEXP weather_coefficient_sdSEXP, SEXP bboxSEXP, SEXP resSEXP, SEXP rows_colsSEXP, SEXP soil_reservoirsSEXP, SEXP reproductive_rateSEXP, SEXP spatial_indicesSEXP, SEXP season_month_start_endSEXP, SEXP frequency_configSEXP, SEXP bool_configSEXP, SEXP start_dateSEXP, SEXP end_dateSEXP, SEXP treatment_methodSEXP, SEXP natural_kernel_typeSEXP, SEXP anthropogenic_kernel_typeSEXP, SEXP percent_natural_dispersalSEXP, SEXP natural_distance_scaleSEXP, SEXP anthropogenic_distance_scaleSEXP, SEXP natural_dirSEXP, SEXP natural_kappaSEXP, SEXP anthropogenic_dirSEXP, SEXP anthropogenic_kappaSEXP, SEXP frequencies_n_configSEXP, SEXP model_type_SEXP, SEXP latency_periodSEXP, SEXP establishment_probabilitySEXP, SEXP dispersal_percentageSEXP, SEXP survival_rate_monthSEXP, SEXP survival_rate_daySEXP, SEXP overpopulation_configSEXP, SEXP network_configSEXP, SEXP network_data_configSEXP, SEXP weather_sizeSEXP, SEXP weather_typeSEXP, SEXP dispersers_to_soils_percentageSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::traits::input_parameter< int >::type random_seed(random_seedSEXP);
Rcpp::traits::input_parameter< bool >::type multiple_random_seeds(multiple_random_seedsSEXP);
Rcpp::traits::input_parameter< std::vector<int> >::type random_seeds(random_seedsSEXP);
Rcpp::traits::input_parameter< std::vector<unsigned> >::type random_seeds(random_seedsSEXP);
Rcpp::traits::input_parameter< double >::type lethal_temperature(lethal_temperatureSEXP);
Rcpp::traits::input_parameter< int >::type lethal_temperature_month(lethal_temperature_monthSEXP);
Rcpp::traits::input_parameter< std::vector<List> >::type host_pools(host_poolsSEXP);
Expand Down Expand Up @@ -105,7 +105,7 @@ RcppExport SEXP _PoPS_pops_model_cpp(SEXP random_seedSEXP, SEXP multiple_random_
static int _PoPS_RcppExport_validate(const char* sig) {
static std::set<std::string> signatures;
if (signatures.empty()) {
signatures.insert("List(*pops_model_cpp)(int,bool,std::vector<int>,double,int,std::vector<List>,IntegerMatrix,std::vector<std::vector<double>>,std::vector<std::vector<double>>,IntegerMatrix,std::string,std::vector<NumericMatrix>,std::vector<std::string>,std::vector<int>,std::vector<std::vector<int>>,std::vector<std::string>,std::vector<NumericMatrix>,std::vector<NumericMatrix>,std::vector<NumericMatrix>,std::vector<NumericMatrix>,List,List,List,std::vector<IntegerMatrix>,double,std::vector<std::vector<int>>,List,List,List,std::string,std::string,std::string,std::string,std::string,double,double,double,std::string,double,std::string,double,Nullable<List>,std::string,int,double,double,int,int,Nullable<List>,Nullable<List>,Nullable<List>,int,std::string,double)");
signatures.insert("List(*pops_model_cpp)(int,bool,std::vector<unsigned>,double,int,std::vector<List>,IntegerMatrix,std::vector<std::vector<double>>,std::vector<std::vector<double>>,IntegerMatrix,std::string,std::vector<NumericMatrix>,std::vector<std::string>,std::vector<int>,std::vector<std::vector<int>>,std::vector<std::string>,std::vector<NumericMatrix>,std::vector<NumericMatrix>,std::vector<NumericMatrix>,std::vector<NumericMatrix>,List,List,List,std::vector<IntegerMatrix>,double,std::vector<std::vector<int>>,List,List,List,std::string,std::string,std::string,std::string,std::string,double,double,double,std::string,double,std::string,double,Nullable<List>,std::string,int,double,double,int,int,Nullable<List>,Nullable<List>,Nullable<List>,int,std::string,double)");
}
return signatures.find(sig) != signatures.end();
}
Expand Down
6 changes: 5 additions & 1 deletion src/pops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct OutputHostPool {
List pops_model_cpp(
int random_seed,
bool multiple_random_seeds,
std::vector<int> random_seeds,
std::vector<unsigned> random_seeds,
double lethal_temperature,
int lethal_temperature_month,
std::vector<List> host_pools,
Expand Down Expand Up @@ -117,6 +117,10 @@ List pops_model_cpp(
{
Config config;
config.random_seed = random_seed;
config.multiple_random_seeds = multiple_random_seeds;
if (multiple_random_seeds) {
config.read_seeds(random_seeds);
}
config.rows = rows_cols["num_rows"];
config.cols = rows_cols["num_cols"];
config.ew_res = res["ew_res"];
Expand Down

0 comments on commit 38a19e3

Please sign in to comment.