From e2a4590093be9bf35b01c58e19a73aec8d798596 Mon Sep 17 00:00:00 2001 From: Iago-lito Date: Tue, 2 Aug 2022 16:16:22 +0200 Subject: [PATCH] [algorithm.initial_rates] dispersal and extinction --- src/BioGeoTree.cpp | 4 +-- src/BioGeoTree.h | 4 +-- src/main.cpp | 51 ++++++++++++++++++----------------- tests/input/input/config.toml | 8 ++++++ tests/input/specs/config.clib | 18 ++++++------- 5 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/BioGeoTree.cpp b/src/BioGeoTree.cpp index dbe0bb2e..99685c52 100644 --- a/src/BioGeoTree.cpp +++ b/src/BioGeoTree.cpp @@ -970,12 +970,12 @@ double BioGeoTree::getSim_E() return sim_E; } -void BioGeoTree::setSim_D(double & disp) +void BioGeoTree::setSim_D(const double disp) { sim_D = disp; } -void BioGeoTree::setSim_E(double & ext) +void BioGeoTree::setSim_E(const double ext) { sim_E = ext; } diff --git a/src/BioGeoTree.h b/src/BioGeoTree.h index db893118..0d15202c 100644 --- a/src/BioGeoTree.h +++ b/src/BioGeoTree.h @@ -129,8 +129,8 @@ class BioGeoTree{ void simulate(Node & node); double getSim_D(); double getSim_E(); - void setSim_D(double & disp); - void setSim_E(double & ext); + void setSim_D(const double disp); + void setSim_E(const double ext); void read_true_states(string truestatesfile); vector * get_true_state(int num); diff --git a/src/main.cpp b/src/main.cpp index c0cf3443..f45669a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -118,6 +118,32 @@ int main(int argc, char* argv[]){ config.step_up(); + // Algorithm table (optional) ------------------------------------------------ + // Default values here, possibly overwritten with configuration. + double D{0.1}; + double E{0.1}; + int M{1000}; + double S{0.0001}; + + if (config.seek_table("algorithm", true).has_value()) { + const auto& m{config.seek_integer("max_iterations", false)}; + const auto& s{config.seek_float("stopping_precision", false)}; + if (m.has_value()) { M = *m; } + if (s.has_value()) { S = *s; } + if (config.seek_table("initial_rates", true).has_value()) { + const auto& d{config.seek_float("dispersal", false)}; + const auto& e{config.seek_float("extinction", false)}; + if (d.has_value()) { D = *d; } + if (e.has_value()) { E = *e; } + config.step_up(); + } + config.step_up(); + } + const double dispersal{D}; + const double extinction{E}; + const int maxiterations{M}; + const double stoppingprecision{S}; + // Geographical parameters --------------------------------------------------- config.require_table("areas", true); @@ -223,11 +249,6 @@ int main(int argc, char* argv[]){ bool LHOODS = false; bool NodeLHOODS = false; - int maxiterations = 1000; - double stoppingprecision = 0.0001; - - double dispersal = 0.1; - double extinction = 0.1; bool estimate = true; bool simulate = false; int simNum = 1; @@ -349,26 +370,6 @@ int main(int argc, char* argv[]){ if(tokens.size() > 1){ numreps = atoi(tokens[1].c_str()); } - }else if ((!strcmp(tokens[0].c_str(), "dispersal")) || (!strcmp(tokens[0].c_str(), "sim_dispersal"))){ - if(tokens.size() > 1){ - dispersal = atof(tokens[1].c_str()); - cout << "setting dispersal: " << dispersal << endl; - if (!strcmp(tokens[0].c_str(), "sim_dispersal")) - estimate = false; - } - }else if ((!strcmp(tokens[0].c_str(), "extinction")) || (!strcmp(tokens[0].c_str(), "sim_extinction"))){ - if(tokens.size() > 1){ - extinction = atof(tokens[1].c_str()); - cout << "setting extinction: " << extinction << endl; - if (!strcmp(tokens[0].c_str(), "sim_extinction")) - estimate = false; - } - }else if(!strcmp(tokens[0].c_str(), "maxiterations")){ - maxiterations = atoi(tokens[1].c_str()); - cout << "setting maxiterations: " << maxiterations << endl; - }else if(!strcmp(tokens[0].c_str(), "stoppingprecision")){ - stoppingprecision = atof(tokens[1].c_str()); - cout << "setting stoppingprecision: " << stoppingprecision << endl; }else if(!strcmp(tokens[0].c_str(), "simbiogeotree")){ simulate = true; if(tokens.size() > 1) diff --git a/tests/input/input/config.toml b/tests/input/input/config.toml index 9990d182..0cc93f45 100644 --- a/tests/input/input/config.toml +++ b/tests/input/input/config.toml @@ -16,6 +16,14 @@ rapid_anagenesis = false durations = [5.33, 17.7, 10.87, 22.1, 14.0] +[algorithm] +max_iterations = 1000 +stopping_precision = 0.0001 + +[algorithm.initial_rates] +dispersal = 0.1 +extinction = 0.1 + # --- Geographical parameters -------------------------------------------------- [areas] # names = ["WP", "EP", "WN", "EN", "CA", "SA", "AF", "MD", "IN", "WA", "AU"] diff --git a/tests/input/specs/config.clib b/tests/input/specs/config.clib index 3ff14bd1..a7288cd5 100644 --- a/tests/input/specs/config.clib +++ b/tests/input/specs/config.clib @@ -138,8 +138,8 @@ test: No areas table. edit (config.toml): PREFIX (#1) [areas] failure (1):: EOE - Configuration error: table contains unexpected parameter 'names'. - ('parameters' line 11, column 1 of 'config.toml') + Configuration error: 'names' is required, but not given. + ('areas' line 32, column 1 of 'config.toml') EOE # Distributions ================================================================ @@ -151,7 +151,7 @@ edit (config.toml): failure (1):: EOE Unknown area name in distribution: 'wrong'. (known areas: 'WP' 'EP' 'WN' 'EN' 'CA' 'SA' 'AF' 'MD' 'IN' 'WA' 'AU') - ('areas:distributions:set:1' line 28, column 3 of 'config.toml') + ('areas:distributions:set:1' line 36, column 3 of 'config.toml') EOE test: Catch missing area in binary distribution. @@ -161,7 +161,7 @@ edit (config.toml): failure (1):: EOE Invalid binary specification of a distribution: '1101011010' contains 10 digits but there are 11 areas. - ('areas:distributions:set:3' line 30, column 3 of 'config.toml') + ('areas:distributions:set:3' line 38, column 3 of 'config.toml') EOE test: Catch extra area in binary distribution. @@ -171,7 +171,7 @@ edit (config.toml): failure (1):: EOE Invalid binary specification of a distribution: '110101101011' contains 12 digits but there are 11 areas. - ('areas:distributions:set:3' line 30, column 3 of 'config.toml') + ('areas:distributions:set:3' line 38, column 3 of 'config.toml') EOE test: Catch the ambiguous case. @@ -184,7 +184,7 @@ failure (1):: EOE Ambiguous distribution specification: '101' could either represent the single area '101' or a binary set of other areas.. Now be honest: you did that on purpose, right? - ('areas:distributions:set:1' line 28, column 3 of 'config.toml') + ('areas:distributions:set:1' line 36, column 3 of 'config.toml') EOE # MRCAs ======================================================================== @@ -194,7 +194,7 @@ edit (config.toml): REPLACE (age = 15.8) BY r'# \1' failure (1):: EOE Configuration error: 'age' is required, but not given. - ('mrca:Gavialidae' line 36, column 1 of 'config.toml') + ('mrca:Gavialidae' line 44, column 1 of 'config.toml') EOE test: Catch invalid area. @@ -203,7 +203,7 @@ edit (config.toml): ~ 'area = "wrong"' failure (1):: EOE Unknown area 'wrong' provided. - ('mrca:Gavialidae:area' line 39, column 8 of 'config.toml') + ('mrca:Gavialidae:area' line 47, column 8 of 'config.toml') EOE test: Catch invalid MRCA type specification. @@ -213,7 +213,7 @@ edit (config.toml): failure (1):: EOE Unknown MRCA type: 'fixed branch'. Supported types are 'fixed node', 'fossil node' and 'fossil branch'. - ('mrca:Caiman:type' line 43, column 8 of 'config.toml') + ('mrca:Caiman:type' line 51, column 8 of 'config.toml') EOE # Clear for later tests specs.