void CandidateSet::recomputeLoglOfAllTrees(IQTree &treeObject) { vector<string> allTreeStrings = getBestTreeStrings(); for (vector<string>:: iterator it = allTreeStrings.begin(); it != allTreeStrings.end(); it++) { treeObject.readTreeString(*it); double score = treeObject.optimizeAllBranches(1); update(treeObject.getTreeString(), score); } }
void RateMeyerHaeseler::runIterativeProc(Params ¶ms, IQTree &tree) { int i; if (verbose_mode >= VB_MED) { ofstream out("x"); out.close(); } setTree(&tree); RateHeterogeneity *backup_rate = tree.getRate(); if (backup_rate->getGammaShape() > 0 ) { IntVector pattern_cat; backup_rate->computePatternRates(*this, pattern_cat); double sum = 0.0; for (i = 0; i < size(); i++) sum += at(i) * phylo_tree->aln->at(i).frequency; sum /= phylo_tree->aln->getNSite(); if (fabs(sum - 1.0) > 0.0001) { if (verbose_mode >= VB_MED) cout << "Normalizing Gamma rates (" << sum << ")" << endl; for (i = 0; i < size(); i++) at(i) /= sum; } } tree.getModelFactory()->site_rate = this; tree.setRate(this); //if (empty()) initializeRates(); //setRates(prev_rates); //string rate_file = params.out_prefix; //rate_file += ".mhrate"; double prev_lh = tree.getCurScore(); string dist_file = params.out_prefix; dist_file += ".tdist"; tree.getModelFactory()->stopStoringTransMatrix(); for (i = 2; i < 100; i++) { //DoubleVector prev_rates; //getRates(prev_rates); //writeSiteRates(prev_rates, rate_file.c_str()); tree.setCurScore(optimizeParameters(0.0)); //phylo_tree->aln->printDist(dist_file.c_str(), dist_mat); tree.setCurScore(tree.optimizeAllBranches(i)); cout << "Current Log-likelihood: " << tree.getCurScore() << endl; if (tree.getCurScore() <= prev_lh + 1e-4) { break; } prev_lh = tree.getCurScore(); } cout << "Optimization took " << i-1 << " rounds to finish" << endl; tree.getModelFactory()->startStoringTransMatrix(); //tree.getModelFactory()->site_rate = backup_rate; //tree.setRate(backup_rate); }