Skip to content

Commit 42b342e

Browse files
committed
manual
1 parent a618b1a commit 42b342e

File tree

2 files changed

+69
-47
lines changed

2 files changed

+69
-47
lines changed

manual.pdf

109 KB
Binary file not shown.

src/main.cpp

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ int main(int argc, char* argv[]){
7575
bool bayesian = false;
7676
int numreps = 10000;
7777

78+
double dispersal = 0.1;
79+
double extinction = 0.1;
80+
bool estimate = true;
81+
7882
/*
7983
* for stochastic mapping
8084
*/
@@ -278,6 +282,14 @@ int main(int argc, char* argv[]){
278282
if(tokens.size() > 1){
279283
numreps = atoi(tokens[1].c_str());
280284
}
285+
}else if(!strcmp(tokens[0].c_str(), "dispersal")){
286+
dispersal = atof(tokens[1].c_str());
287+
cout << "setting dispersal: " << dispersal << endl;
288+
estimate = false;
289+
}else if(!strcmp(tokens[0].c_str(), "extinction")){
290+
extinction = atof(tokens[1].c_str());
291+
cout << "setting extinction: " << extinction << endl;
292+
estimate = false;
281293
}
282294
}
283295
}
@@ -458,63 +470,73 @@ int main(int argc, char* argv[]){
458470
* optimize likelihood
459471
*/
460472
Superdouble nlnlike = 0;
461-
if(estimate_dispersal_mask == false){
462-
cout << "Optimizing (simplex) -ln likelihood." << endl;
463-
OptimizeBioGeo opt(&bgt,&rm,marginal);
464-
vector<double> disext = opt.optimize_global_dispersal_extinction();
465-
cout << "dis: " << disext[0] << " ext: " << disext[1] << endl;
466-
rm.setup_D(disext[0]);
467-
rm.setup_E(disext[1]);
468-
rm.setup_Q();
469-
bgt.update_default_model(&rm);
470-
bgt.set_store_p_matrices(true);
471-
cout << "final -ln likelihood: "<< double(bgt.eval_likelihood(marginal)) <<endl;
472-
bgt.set_store_p_matrices(false);
473-
}else{//optimize all the dispersal matrix
474-
cout << "Optimizing (simplex) -ln likelihood with all dispersal parameters free." << endl;
475-
//OptimizeBioGeoAllDispersal opt(&bgt,&rm,marginal);
476-
//vector<double> disextrm = opt.optimize_global_dispersal_extinction();
477-
vector<double> disextrm = optimize_dispersal_extinction_all_nlopt(&bgt,&rm);
478-
cout << "dis: " << disextrm[0] << " ext: " << disextrm[1] << endl;
479-
vector<double> cols(rm.get_num_areas(), 0);
480-
vector< vector<double> > rows(rm.get_num_areas(), cols);
481-
vector< vector< vector<double> > > D_mask = vector< vector< vector<double> > > (periods.size(), rows);
482-
int count = 2;
483-
for (unsigned int i=0;i<D_mask.size();i++){
484-
for (unsigned int j=0;j<D_mask[i].size();j++){
485-
D_mask[i][j][j] = 0.0;
486-
for (unsigned int k=0;k<D_mask[i][j].size();k++){
487-
if(k!= j){
488-
D_mask[i][j][k] = disextrm[count];
489-
count += 1;
473+
if (estimate == true){
474+
if(estimate_dispersal_mask == false){
475+
cout << "Optimizing (simplex) -ln likelihood." << endl;
476+
OptimizeBioGeo opt(&bgt,&rm,marginal);
477+
vector<double> disext = opt.optimize_global_dispersal_extinction();
478+
cout << "dis: " << disext[0] << " ext: " << disext[1] << endl;
479+
rm.setup_D(disext[0]);
480+
rm.setup_E(disext[1]);
481+
rm.setup_Q();
482+
bgt.update_default_model(&rm);
483+
bgt.set_store_p_matrices(true);
484+
cout << "final -ln likelihood: "<< double(bgt.eval_likelihood(marginal)) <<endl;
485+
bgt.set_store_p_matrices(false);
486+
}else{//optimize all the dispersal matrix
487+
cout << "Optimizing (simplex) -ln likelihood with all dispersal parameters free." << endl;
488+
//OptimizeBioGeoAllDispersal opt(&bgt,&rm,marginal);
489+
//vector<double> disextrm = opt.optimize_global_dispersal_extinction();
490+
vector<double> disextrm = optimize_dispersal_extinction_all_nlopt(&bgt,&rm);
491+
cout << "dis: " << disextrm[0] << " ext: " << disextrm[1] << endl;
492+
vector<double> cols(rm.get_num_areas(), 0);
493+
vector< vector<double> > rows(rm.get_num_areas(), cols);
494+
vector< vector< vector<double> > > D_mask = vector< vector< vector<double> > > (periods.size(), rows);
495+
int count = 2;
496+
for (unsigned int i=0;i<D_mask.size();i++){
497+
for (unsigned int j=0;j<D_mask[i].size();j++){
498+
D_mask[i][j][j] = 0.0;
499+
for (unsigned int k=0;k<D_mask[i][j].size();k++){
500+
if(k!= j){
501+
D_mask[i][j][k] = disextrm[count];
502+
count += 1;
503+
}
490504
}
491505
}
492506
}
493-
}
494-
cout << "D_mask" <<endl;
495-
for (unsigned int i=0;i<D_mask.size();i++){
496-
cout << periods.at(i) << endl;
497-
cout << "\t";
498-
for(unsigned int j=0;j<D_mask[i].size();j++){
499-
cout << areanames[j] << "\t" ;
500-
}
501-
cout << endl;
502-
for (unsigned int j=0;j<D_mask[i].size();j++){
503-
cout << areanames[j] << "\t" ;
504-
for (unsigned int k=0;k<D_mask[i][j].size();k++){
505-
cout << D_mask[i][j][k] << "\t";
507+
cout << "D_mask" <<endl;
508+
for (unsigned int i=0;i<D_mask.size();i++){
509+
cout << periods.at(i) << endl;
510+
cout << "\t";
511+
for(unsigned int j=0;j<D_mask[i].size();j++){
512+
cout << areanames[j] << "\t" ;
513+
}
514+
cout << endl;
515+
for (unsigned int j=0;j<D_mask[i].size();j++){
516+
cout << areanames[j] << "\t" ;
517+
for (unsigned int k=0;k<D_mask[i][j].size();k++){
518+
cout << D_mask[i][j][k] << "\t";
519+
}
520+
cout << endl;
506521
}
507522
cout << endl;
508523
}
509-
cout << endl;
524+
rm.setup_D_provided(disextrm[0],D_mask);
525+
rm.setup_E(disextrm[1]);
526+
rm.setup_Q();
527+
bgt.update_default_model(&rm);
528+
bgt.set_store_p_matrices(true);
529+
nlnlike = bgt.eval_likelihood(marginal);
530+
cout << "final -ln likelihood: "<< double(nlnlike) <<endl;
531+
bgt.set_store_p_matrices(false);
510532
}
511-
rm.setup_D_provided(disextrm[0],D_mask);
512-
rm.setup_E(disextrm[1]);
533+
}else{
534+
rm.setup_D(dispersal);
535+
rm.setup_E(extinction);
513536
rm.setup_Q();
514537
bgt.update_default_model(&rm);
515538
bgt.set_store_p_matrices(true);
516-
nlnlike = bgt.eval_likelihood(marginal);
517-
cout << "final -ln likelihood: "<< double(nlnlike) <<endl;
539+
cout << "final -ln likelihood: "<< double(bgt.eval_likelihood(marginal)) <<endl;
518540
bgt.set_store_p_matrices(false);
519541
}
520542

0 commit comments

Comments
 (0)