Fix some weird bugs for PhyloMOEA parallel version
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1397 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
c78c4c2f6b
commit
2ea4e6d51d
6 changed files with 89 additions and 29 deletions
|
|
@ -29,7 +29,8 @@ string datafile,usertree, expid, path, algotype;
|
|||
double pcrossover, pmutation, kappa, alpha;
|
||||
unsigned int ngenerations, popsize, ncats;
|
||||
ofstream exp_data,evolution_data, best_media_scores, final_trees, final_pareto_trees, clades_pareto, clades_final,final_scores,pareto_scores;
|
||||
|
||||
LikelihoodCalculator *lik_calc_ptr;
|
||||
phylotreeIND *templatetree_ptr;
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
@ -81,6 +82,7 @@ int main(int argc, char *argv[])
|
|||
rn2 = gsl_rng_alloc(gsl_rng_default);
|
||||
rn = new RandomNr(seed);
|
||||
phylotreeIND templatetree( rn, seq, rn2);
|
||||
templatetree_ptr = &templatetree;
|
||||
ParsimonyCalculator parsi_calc(templatetree);
|
||||
SubstModel modelHKY( seq, SubstModel::HKY85);
|
||||
modelHKY.init();
|
||||
|
|
@ -89,14 +91,18 @@ int main(int argc, char *argv[])
|
|||
LikelihoodCalculator lik_calc(templatetree, modelHKY, probmatrixs,ncats);
|
||||
lik_calc.set_alpha(alpha);
|
||||
modelHKY.init();
|
||||
|
||||
PhyloEval byobj( parsi_calc, lik_calc );
|
||||
Phyloraninit initializer(templatetree);
|
||||
eoPop<PhyloMOEO> population(popsize, initializer);
|
||||
|
||||
peoMoeoPopEval <PhyloMOEO> eval(byobj);
|
||||
|
||||
|
||||
// Only the master node read the initial trees and writes ouput files
|
||||
if(getNodeRank()==1)
|
||||
{
|
||||
|
||||
cout << "\n\nReading Initial Trees...";
|
||||
if( usertree.size() >0)
|
||||
{
|
||||
|
|
@ -183,7 +189,7 @@ int main(int argc, char *argv[])
|
|||
if(algotype == "ibea")
|
||||
{
|
||||
moeoAdditiveEpsilonBinaryMetric < ObjectiveVector > metric;
|
||||
moeoIBEA < PhyloMOEO > algo (cp, byobj, operadores, metric);
|
||||
moeoIBEA < PhyloMOEO > algo (cp, eval, operadores, metric);
|
||||
if(getNodeRank()==1){
|
||||
cout << "\n\nRunning IBEA ..." << endl; }
|
||||
peoWrapper parallelEA( algo, population);
|
||||
|
|
@ -194,7 +200,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
else
|
||||
{
|
||||
moeoNSGAII < PhyloMOEO > algo (cp, byobj, operadores);
|
||||
moeoNSGAII < PhyloMOEO > algo (cp, eval, operadores);
|
||||
if(getNodeRank()==1){
|
||||
cout << "\n\nRunning NSGA-II ..." << endl; }
|
||||
peoWrapper parallelEA( algo, population);
|
||||
|
|
@ -218,12 +224,29 @@ int main(int argc, char *argv[])
|
|||
cout << "\nCalculating Final Solutions...";
|
||||
cout << " done\n";
|
||||
|
||||
PhyloMOEOFinalSolutionsArchive finalsolutions;
|
||||
finalsolutions.operator()(population);
|
||||
}
|
||||
|
||||
PhyloMOEOFinalSolutionsArchive finalsolutions;
|
||||
if(getNodeRank()==1)finalsolutions.operator()(population);
|
||||
//cout << "en el nodo " << getNodeRank() << " popsize " << population.size() << endl;
|
||||
//cout << "en el nodo " << getNodeRank() << " archsize " << finalsolutions.size() << endl;
|
||||
//finalsolutions[0].get_tree().printNewick(cout);
|
||||
lik_calc_ptr = &lik_calc;
|
||||
// make the optimization phase also in parallel
|
||||
peo :: init (argc, argv);
|
||||
peoMultiStart <PhyloMOEO> ParallelLKOptimizationInit (optimize_solution);
|
||||
peoWrapper ParallelLKOptimization (ParallelLKOptimizationInit, finalsolutions);
|
||||
ParallelLKOptimizationInit.setOwner(ParallelLKOptimization);
|
||||
if (getNodeRank()==1) cout << "\nOptimizing tree branch lenghts...\n";
|
||||
peo :: run( );
|
||||
peo :: finalize( );
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
|
||||
//remove_final_solutions( population );
|
||||
// optimize remaining solutions
|
||||
cout << "\nOptimizing tree branch lenghts...\n";
|
||||
|
||||
|
||||
//optimize_solutions( finalsolutions, lik_calc );
|
||||
cout << "\nReevaluating individuals \n";
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
#include <PhyloMOEO.h>
|
||||
#include <parsimonycalculator.h>
|
||||
#include <likelihoodcalculator.h>
|
||||
//#include <peo>
|
||||
#include <iostream>
|
||||
|
||||
class PhyloEval : public moeoEvalFunc < PhyloMOEO >
|
||||
{
|
||||
|
|
@ -32,8 +34,9 @@ public:
|
|||
|
||||
void operator () (PhyloMOEO & _sol)
|
||||
{
|
||||
if (_sol.invalidObjectiveVector())
|
||||
{
|
||||
//cout << "hello im evaluating in the node " << getNodeRank() << endl;
|
||||
//if (_sol.invalidObjectiveVector())
|
||||
//{
|
||||
|
||||
ObjectiveVector objVec;
|
||||
//if(! (_sol.get_tree().splits_valid() ) ) _sol.get_tree().calculate_splits();
|
||||
|
|
@ -44,7 +47,7 @@ public:
|
|||
objVec[0] = parseval.fitch();
|
||||
objVec[1] = -likeval.calculate_likelihood();
|
||||
_sol.objectiveVector(objVec);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -14,13 +14,14 @@
|
|||
|
||||
void pack( PhyloMOEO & ind)
|
||||
{
|
||||
cout << "packing individual" << endl;
|
||||
//cout << "packing individual" << endl;
|
||||
phylotreeIND & tree = ind.get_tree();
|
||||
string s = tree.newick_traverse2( false, false);
|
||||
string s = tree.newick_traverse2( true, false);
|
||||
|
||||
::pack(s);
|
||||
|
||||
edge edgeaux = *( tree.taxon_number(0).inout_edges_begin() );
|
||||
/*edge edgeaux = *( tree.taxon_number(0).inout_edges_begin() );
|
||||
node root_traverse = edgeaux.opposite( tree.taxon_number(0) );
|
||||
//tree.convert_graph_to_tree( root_traverse, NULL);
|
||||
postorder_Iterator it = tree.postorder_begin( root_traverse );
|
||||
postorder_Iterator it2 = tree.postorder_end( root_traverse );
|
||||
double *blens = new double[(2*tree.number_of_taxons() -3 )];
|
||||
|
|
@ -34,23 +35,29 @@ void pack( PhyloMOEO & ind)
|
|||
++it;
|
||||
}
|
||||
for(int i=0; i< (2*tree.number_of_taxons() -3 ) ; i++) ::pack(blens[i]);
|
||||
delete [] blens;
|
||||
cout << "packing finished..." << endl;
|
||||
delete [] blens;
|
||||
|
||||
/*cout << "\nenviado " << endl;
|
||||
cout << tree.newick_traverse2(false,false) << endl;*/
|
||||
|
||||
//cout << "packing finished..." << endl;
|
||||
//::pack(blens);
|
||||
}
|
||||
|
||||
void unpack( PhyloMOEO &ind )
|
||||
{
|
||||
cout << "unpacking individual" << endl;
|
||||
phylotreeIND tree = ind.get_tree();
|
||||
|
||||
//cout << "unpacking individual" << endl;
|
||||
string newickstring;
|
||||
::unpack(newickstring);
|
||||
|
||||
//cout << newickstring << endl;
|
||||
ind.set_tree_template( *templatetree_ptr);
|
||||
phylotreeIND &tree = ind.get_tree();
|
||||
|
||||
tree.read_newick2( newickstring );
|
||||
|
||||
edge edgeaux = *( tree.taxon_number(0).inout_edges_begin() );
|
||||
ind.invalidate();
|
||||
/*edge edgeaux = *( tree.taxon_number(0).inout_edges_begin() );
|
||||
node root_traverse = edgeaux.opposite( tree.taxon_number(0) );
|
||||
tree.convert_graph_to_tree( root_traverse, NULL);
|
||||
postorder_Iterator it = tree.postorder_begin( root_traverse );
|
||||
postorder_Iterator it2 = tree.postorder_end( root_traverse );
|
||||
//double blens[2*Tind->number_of_taxons() -3];
|
||||
|
|
@ -60,10 +67,15 @@ void unpack( PhyloMOEO &ind )
|
|||
while(it!=it2)
|
||||
{
|
||||
double blen;
|
||||
::unpack(blen);
|
||||
if( *it != root_traverse )
|
||||
{
|
||||
::unpack(blen);
|
||||
tree.set_branch_length( it.branch(), blen );
|
||||
}
|
||||
++it;
|
||||
}
|
||||
cout << "unpacking finished..." << endl;
|
||||
}
|
||||
/*cout << "\n unpacking finished..." << endl;
|
||||
cout << "recibido \n" << endl;
|
||||
cout << newickstring << endl;
|
||||
cout << tree.newick_traverse2(false,false) << endl; */
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
#include <PhyloMOEO.h>
|
||||
#include <peo>
|
||||
|
||||
extern phylotreeIND * templatetree_ptr;
|
||||
void pack( PhyloMOEO &);
|
||||
void unpack( PhyloMOEO & );
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ extern long seed;
|
|||
extern string datafile,usertree, expid, path;
|
||||
extern double pcrossover, pmutation, kappa, alpha;
|
||||
extern unsigned int ngenerations, popsize, ncats;
|
||||
extern LikelihoodCalculator *lik_calc_ptr;
|
||||
|
||||
void welcome_message()
|
||||
{
|
||||
|
|
@ -62,17 +63,19 @@ void save_exp_params(ostream &of=cout)
|
|||
|
||||
|
||||
|
||||
void optimize_solutions( eoPop<PhyloMOEO> &pop, LikelihoodCalculator &lik_calc)
|
||||
void optimize_solutions( eoPop<PhyloMOEO> &pop)
|
||||
{
|
||||
cout << "entrando a optimize_solutions con " << pop.size() << " arvores " << endl;
|
||||
int n = pop.size();
|
||||
|
||||
for(int i=0; i<n; i++)
|
||||
{
|
||||
phylotreeIND &sol = pop[i].get_tree();
|
||||
lik_calc.set_tree(sol);
|
||||
lik_calc_ptr->set_tree(sol);
|
||||
cout << "\noptimizaing tree " << i+1 << " of " << n;
|
||||
// cout << endl << "likelihood inicial:" << lik_calc->calculate_likelihood() << endl;
|
||||
Newton_LikOptimizer test(lik_calc);
|
||||
test.optimize();
|
||||
Newton_LikOptimizer test(*lik_calc_ptr);
|
||||
//test.optimize();
|
||||
|
||||
pop[i].invalidate();
|
||||
//lik_calc->maximizelikelihood();
|
||||
|
|
@ -83,6 +86,23 @@ void optimize_solutions( eoPop<PhyloMOEO> &pop, LikelihoodCalculator &lik_calc)
|
|||
}
|
||||
|
||||
|
||||
void optimize_solution( PhyloMOEO &indi)
|
||||
{
|
||||
phylotreeIND &sol = indi.get_tree();
|
||||
lik_calc_ptr->set_tree(sol);
|
||||
//cout << "\noptimizaing tree " << i+1 << " of " << n;
|
||||
// cout << endl << "likelihood inicial:" << lik_calc->calculate_likelihood() << endl;
|
||||
Newton_LikOptimizer test(*lik_calc_ptr);
|
||||
test.optimize();
|
||||
indi.invalidate();
|
||||
//pop[i].invalidate();
|
||||
//lik_calc->maximizelikelihood();
|
||||
//lik_calc->set_tree(*sol);
|
||||
// lik_calc->set_tree( *sol);
|
||||
// cout << endl << "likelihood final:" << lik_calc->calculate_likelihood() << endl;
|
||||
//}
|
||||
}
|
||||
|
||||
void readtrees(const char *fname, eoPop<PhyloMOEO> &poptree)
|
||||
{
|
||||
int ntrees;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@
|
|||
|
||||
void welcome_message();
|
||||
void save_exp_params(ostream &);
|
||||
void optimize_solutions( eoPop<PhyloMOEO> &, LikelihoodCalculator &);
|
||||
void optimize_solutions( eoPop<PhyloMOEO> &);
|
||||
void optimize_solution( PhyloMOEO &);
|
||||
void readtrees(const char *, eoPop<PhyloMOEO> &);
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue