Skip to content

Commit

Permalink
[algorithm.initial_rates] dispersal and extinction
Browse files Browse the repository at this point in the history
  • Loading branch information
iago-lito committed Aug 2, 2022
1 parent b2dc0c4 commit e2a4590
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/BioGeoTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/BioGeoTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> * get_true_state(int num);
Expand Down
51 changes: 26 additions & 25 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions tests/input/input/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
18 changes: 9 additions & 9 deletions tests/input/specs/config.clib
Original file line number Diff line number Diff line change
Expand Up @@ -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 ================================================================
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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 ========================================================================
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit e2a4590

Please sign in to comment.