First parallel version of PhyloMOEA
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1390 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
4e1826a94c
commit
7feb972a77
1 changed files with 180 additions and 138 deletions
|
|
@ -1,11 +1,13 @@
|
||||||
#include <eo>
|
#include <eo>
|
||||||
#include <moeo>
|
#include <moeo>
|
||||||
|
#include <peo>
|
||||||
#include <PhyloMOEO.h>
|
#include <PhyloMOEO.h>
|
||||||
#include <PhyloMOEO_operators.h>
|
#include <PhyloMOEO_operators.h>
|
||||||
#include <PhyloMOEO_init.h>
|
#include <PhyloMOEO_init.h>
|
||||||
#include <PhyloMOEO_eval.h>
|
#include <PhyloMOEO_eval.h>
|
||||||
#include <PhyloMOEO_archive.h>
|
#include <PhyloMOEO_archive.h>
|
||||||
#include <PhyloMOEOProbMatrixContainerUpdater.h>
|
#include <PhyloMOEOProbMatrixContainerUpdater.h>
|
||||||
|
#include <PhyloMOEO_packunpack.h>
|
||||||
#include <moeoNSGAII2.h>
|
#include <moeoNSGAII2.h>
|
||||||
#include <utils/moeoBestObjVecStat.h>
|
#include <utils/moeoBestObjVecStat.h>
|
||||||
#include <utils/moeoAverageObjVecStat.h>
|
#include <utils/moeoAverageObjVecStat.h>
|
||||||
|
|
@ -13,6 +15,7 @@
|
||||||
#include <eoCountedFileMonitor.h>
|
#include <eoCountedFileMonitor.h>
|
||||||
#include <eoSingleFileCountedStateSaver.h>
|
#include <eoSingleFileCountedStateSaver.h>
|
||||||
#include <vectorSortIndex.h>
|
#include <vectorSortIndex.h>
|
||||||
|
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <apply.h>
|
#include <apply.h>
|
||||||
|
|
@ -28,13 +31,17 @@ 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;
|
ofstream exp_data,evolution_data, best_media_scores, final_trees, final_pareto_trees, clades_pareto, clades_final,final_scores,pareto_scores;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
welcome_message();
|
|
||||||
|
peo :: init( argc, argv );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
eoParser parser(argc, argv);
|
eoParser parser(argc, argv);
|
||||||
|
|
||||||
|
|
||||||
seed = parser.createParam((unsigned int)(time(NULL)), "seed", "Random Seed", 's',"Param").value();
|
seed = parser.createParam((unsigned int)(time(NULL)), "seed", "Random Seed", 's',"Param").value();
|
||||||
|
|
||||||
popsize = parser.createParam((unsigned int)(50), "popSize", "Population size", 'n',"Param").value();
|
popsize = parser.createParam((unsigned int)(50), "popSize", "Population size", 'n',"Param").value();
|
||||||
|
|
@ -52,18 +59,22 @@ int main(int argc, char *argv[])
|
||||||
convert << seed;
|
convert << seed;
|
||||||
expid = parser.createParam(convert.str(), "expid", "Experiment ID", 'e',"Param").value();
|
expid = parser.createParam(convert.str(), "expid", "Experiment ID", 'e',"Param").value();
|
||||||
|
|
||||||
|
if(getNodeRank()==1) welcome_message();
|
||||||
if( datafile.size()==0 )
|
if( datafile.size()==0 )
|
||||||
{
|
{
|
||||||
parser.printHelp( cout );
|
|
||||||
|
if(getNodeRank()==1) parser.printHelp( cout );
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// all nodes read datafile and prepares likelihood and parsimony calculation
|
||||||
string filename = path + datafile;
|
string filename = path + datafile;
|
||||||
cout << "\n\nReading Sequence Datafile...";
|
cout << "\n\nReading Sequence Datafile...";
|
||||||
Sequences seq(filename.c_str());
|
Sequences seq(filename.c_str());
|
||||||
cout << " done.\n";
|
cout << " done.\n";
|
||||||
// calculate datafile
|
// calculate datafile
|
||||||
|
cout << "calculating pattersn..." << getNodeRank() << endl;
|
||||||
seq.calculate_patterns();
|
seq.calculate_patterns();
|
||||||
seq.calculate_frequences();
|
seq.calculate_frequences();
|
||||||
|
|
||||||
|
|
@ -73,177 +84,208 @@ int main(int argc, char *argv[])
|
||||||
ParsimonyCalculator parsi_calc(templatetree);
|
ParsimonyCalculator parsi_calc(templatetree);
|
||||||
SubstModel modelHKY( seq, SubstModel::HKY85);
|
SubstModel modelHKY( seq, SubstModel::HKY85);
|
||||||
modelHKY.init();
|
modelHKY.init();
|
||||||
modelHKY.set_kappa(kappa); // banco_grande
|
modelHKY.set_kappa(kappa);
|
||||||
ProbMatrixContainer probmatrixs(modelHKY);
|
ProbMatrixContainer probmatrixs(modelHKY);
|
||||||
LikelihoodCalculator lik_calc(templatetree, modelHKY, probmatrixs,ncats);
|
LikelihoodCalculator lik_calc(templatetree, modelHKY, probmatrixs,ncats);
|
||||||
lik_calc.set_alpha(alpha);
|
lik_calc.set_alpha(alpha);
|
||||||
modelHKY.init();
|
modelHKY.init();
|
||||||
PhyloEval byobj( parsi_calc, lik_calc );
|
PhyloEval byobj( parsi_calc, lik_calc );
|
||||||
|
|
||||||
Phyloraninit initializer(templatetree);
|
Phyloraninit initializer(templatetree);
|
||||||
|
|
||||||
eoState state;
|
|
||||||
|
|
||||||
//eoPop <PhyloMOEO> &population = state.takeOwnership(eoPop<PhyloMOEO>(popsize, initializer));
|
|
||||||
|
|
||||||
eoPop<PhyloMOEO> population(popsize, initializer);
|
eoPop<PhyloMOEO> population(popsize, initializer);
|
||||||
//state.registerObject( population );
|
peoMoeoPopEval <PhyloMOEO> eval(byobj);
|
||||||
|
|
||||||
cout << "\n\nReading Initial Trees...";
|
// Only the master node read the initial trees and writes ouput files
|
||||||
if( usertree.size() >0)
|
if(getNodeRank()==1)
|
||||||
{
|
{
|
||||||
filename = path + usertree;
|
cout << "\n\nReading Initial Trees...";
|
||||||
readtrees(filename.c_str(), population);
|
if( usertree.size() >0)
|
||||||
}
|
|
||||||
cout << " done.\n";
|
|
||||||
|
|
||||||
|
|
||||||
cout << "\n\nCreating output files...";
|
|
||||||
|
|
||||||
try{
|
|
||||||
filename = path + datafile + "_exp_param_" + expid + ".txt";
|
|
||||||
exp_data.open(filename.c_str());
|
|
||||||
exp_data.precision(15);
|
|
||||||
exp_data.setf(ios::fixed);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if( !exp_data.is_open() )
|
|
||||||
{
|
{
|
||||||
throw( ExceptionManager(12) );
|
filename = path + usertree;
|
||||||
|
readtrees(filename.c_str(), population);
|
||||||
}
|
}
|
||||||
cout << " done.\n";
|
cout << " done.\n";
|
||||||
|
|
||||||
|
cout << "\n\nCreating output files...";
|
||||||
|
|
||||||
|
try{
|
||||||
|
filename = path + datafile + "_exp_param_" + expid + ".txt";
|
||||||
|
exp_data.open(filename.c_str());
|
||||||
|
exp_data.precision(15);
|
||||||
|
exp_data.setf(ios::fixed);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if( !exp_data.is_open() )
|
||||||
|
{
|
||||||
|
throw( ExceptionManager(12) );
|
||||||
|
}
|
||||||
|
cout << " done.\n";
|
||||||
|
}
|
||||||
|
catch ( ExceptionManager e )
|
||||||
|
{
|
||||||
|
e.Report();
|
||||||
|
}
|
||||||
|
// create the moea <
|
||||||
|
save_exp_params(exp_data);
|
||||||
|
seq.save_seq_data(exp_data);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch ( ExceptionManager e )
|
|
||||||
{
|
|
||||||
e.Report();
|
|
||||||
}
|
|
||||||
// create the moea
|
|
||||||
save_exp_params(exp_data);
|
|
||||||
seq.save_seq_data(exp_data);
|
|
||||||
|
|
||||||
moeoAverageObjVecStat <PhyloMOEO> bestfit;
|
|
||||||
moeoBestObjVecStat <PhyloMOEO> avgfit;
|
|
||||||
eoPopStat<PhyloMOEO> popstats;
|
|
||||||
|
|
||||||
eoCountedFileMonitor media_scores( 2, path + datafile + "_media_scores_" + expid + ".txt", "\t", true,true );
|
|
||||||
media_scores.add( bestfit);
|
|
||||||
media_scores.add( avgfit) ;
|
|
||||||
|
|
||||||
eoCountedFileMonitor evolution_scores( 2, path + datafile + "_evolution_data_" + expid + ".txt", "\n", true,true );
|
|
||||||
evolution_scores.add( popstats);
|
|
||||||
|
|
||||||
|
|
||||||
//cout << "\n\nRunning NSGA-II ..." << endl;
|
|
||||||
|
|
||||||
eoGenContinue<PhyloMOEO> continuator(ngenerations);
|
eoGenContinue<PhyloMOEO> continuator(ngenerations);
|
||||||
eoCheckPoint<PhyloMOEO> cp(continuator);
|
eoCheckPoint<PhyloMOEO> cp(continuator);
|
||||||
eoValueParam<unsigned> generationCounter(0, "Gen.");
|
|
||||||
eoIncrementor<unsigned> increment(generationCounter.value());
|
|
||||||
cp.add(increment);
|
|
||||||
eoStdoutMonitor monitor(false);
|
|
||||||
monitor.add(generationCounter);
|
|
||||||
cp.add(monitor);
|
|
||||||
Phylomutate mutator;
|
Phylomutate mutator;
|
||||||
Phylocross crossover;
|
Phylocross crossover;
|
||||||
eoSequentialOp<PhyloMOEO> operadores;
|
eoSequentialOp<PhyloMOEO> operadores;
|
||||||
operadores.add(crossover,pcrossover);
|
operadores.add(crossover,pcrossover);
|
||||||
operadores.add(mutator,pmutation);
|
operadores.add(mutator,pmutation);
|
||||||
PhyloMOEOProbMatrixContainerUpdater probmatrixupdater(probmatrixs);
|
PhyloMOEOProbMatrixContainerUpdater probmatrixupdater(probmatrixs);
|
||||||
cp.add( bestfit);
|
|
||||||
cp.add( avgfit);
|
|
||||||
cp.add( media_scores);
|
|
||||||
cp.add( evolution_scores );
|
|
||||||
cp.add( popstats);
|
|
||||||
cp.add( probmatrixupdater );
|
cp.add( probmatrixupdater );
|
||||||
|
|
||||||
|
moeoAverageObjVecStat <PhyloMOEO> *bestfit;
|
||||||
|
moeoBestObjVecStat <PhyloMOEO> *avgfit;
|
||||||
|
eoPopStat<PhyloMOEO> *popstats;
|
||||||
|
|
||||||
|
eoCountedFileMonitor *media_scores, *evolution_scores;
|
||||||
|
eoStdoutMonitor *monitor;
|
||||||
|
eoValueParam<unsigned> *generationCounter;
|
||||||
|
eoIncrementor<unsigned> *increment;
|
||||||
|
|
||||||
|
|
||||||
|
// only the master output files
|
||||||
|
if(getNodeRank()==1){
|
||||||
|
|
||||||
|
generationCounter = new eoValueParam<unsigned> (0, "Gen.");
|
||||||
|
increment = new eoIncrementor<unsigned>(generationCounter->value());
|
||||||
|
cp.add(*increment);
|
||||||
|
|
||||||
|
monitor = new eoStdoutMonitor(false);
|
||||||
|
monitor->add(*generationCounter);
|
||||||
|
|
||||||
|
bestfit = new moeoAverageObjVecStat <PhyloMOEO>();
|
||||||
|
avgfit = new moeoBestObjVecStat <PhyloMOEO>();
|
||||||
|
popstats = new eoPopStat<PhyloMOEO> ();
|
||||||
|
|
||||||
|
media_scores = new eoCountedFileMonitor( 2, path + datafile + "_media_scores_" + expid + ".txt", "\t", true,true );
|
||||||
|
media_scores->add( *avgfit) ;
|
||||||
|
media_scores->add( *bestfit );
|
||||||
|
|
||||||
|
evolution_scores = new eoCountedFileMonitor( 2, path + datafile + "_evolution_data_" + expid + ".txt", "\n", true,true );
|
||||||
|
evolution_scores->add( *popstats);
|
||||||
|
cp.add( *media_scores);
|
||||||
|
cp.add( *evolution_scores );
|
||||||
|
cp.add( *popstats);
|
||||||
|
cp.add( *bestfit);
|
||||||
|
cp.add( *avgfit);
|
||||||
|
cp.add( *monitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// apply<PhyloMOEO> ( byobj, population );
|
|
||||||
// population.printOn(cout);
|
|
||||||
if(algotype == "ibea")
|
if(algotype == "ibea")
|
||||||
{
|
{
|
||||||
moeoAdditiveEpsilonBinaryMetric < ObjectiveVector > metric;
|
moeoAdditiveEpsilonBinaryMetric < ObjectiveVector > metric;
|
||||||
moeoIBEA < PhyloMOEO > algo (cp, byobj, operadores, metric);
|
moeoIBEA < PhyloMOEO > algo (cp, byobj, operadores, metric);
|
||||||
cout << "\n\nRunning IBEA ..." << endl;
|
if(getNodeRank()==1){
|
||||||
algo(population);
|
cout << "\n\nRunning IBEA ..." << endl; }
|
||||||
|
peoWrapper parallelEA( algo, population);
|
||||||
|
eval.setOwner(parallelEA);
|
||||||
|
peo :: run();
|
||||||
|
peo :: finalize();
|
||||||
|
//algo(population);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
moeoNSGAII < PhyloMOEO > algo (cp, byobj, operadores);
|
moeoNSGAII < PhyloMOEO > algo (cp, byobj, operadores);
|
||||||
cout << "\n\nRunning NSGA-II ..." << endl;
|
if(getNodeRank()==1){
|
||||||
algo(population);
|
cout << "\n\nRunning NSGA-II ..." << endl; }
|
||||||
|
peoWrapper parallelEA( algo, population);
|
||||||
|
eval.setOwner(parallelEA);
|
||||||
|
peo :: run();
|
||||||
|
peo :: finalize();
|
||||||
|
//algo(population);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getNodeRank()==1)
|
||||||
|
{
|
||||||
|
delete media_scores;
|
||||||
|
delete evolution_scores;
|
||||||
|
delete bestfit;
|
||||||
|
delete avgfit;
|
||||||
|
delete popstats;
|
||||||
|
delete monitor;
|
||||||
|
delete generationCounter;
|
||||||
|
delete increment;
|
||||||
|
|
||||||
cout << "\nCalculating Final Solutions...";
|
cout << "\nCalculating Final Solutions...";
|
||||||
cout << " done\n";
|
cout << " done\n";
|
||||||
|
|
||||||
PhyloMOEOFinalSolutionsArchive finalsolutions;
|
|
||||||
finalsolutions.operator()(population);
|
|
||||||
|
|
||||||
//remove_final_solutions( population );
|
|
||||||
// optimize remaining solutions
|
|
||||||
cout << "\nOptimizing tree branch lenghts...\n";
|
|
||||||
|
|
||||||
optimize_solutions( finalsolutions, lik_calc );
|
PhyloMOEOFinalSolutionsArchive finalsolutions;
|
||||||
cout << "\nReevaluating individuals \n";
|
finalsolutions.operator()(population);
|
||||||
apply<PhyloMOEO> ( byobj, finalsolutions );
|
|
||||||
|
|
||||||
finalsolutions.save_scores(path + datafile + "_final_scores_" + expid + ".txt","#Final Solutions Scores");
|
|
||||||
finalsolutions.save_trees(path + datafile + "_final_trees_" + expid + ".txt");
|
|
||||||
cout << "\ndone \n";
|
|
||||||
|
|
||||||
// print the optimized solutions
|
//remove_final_solutions( population );
|
||||||
//print_scores_pop( -2, population, evolution_data);
|
// optimize remaining solutions
|
||||||
|
cout << "\nOptimizing tree branch lenghts...\n";
|
||||||
//print_scores_pop( -2, population, final_scores);
|
|
||||||
|
//optimize_solutions( finalsolutions, lik_calc );
|
||||||
//save_trees(finalsolutions, final_trees);
|
cout << "\nReevaluating individuals \n";
|
||||||
cout << "\n\nCalculating Final Solutions clade support...";
|
apply<PhyloMOEO> ( byobj, finalsolutions );
|
||||||
|
|
||||||
PhyloMOEOPartitionStat splitstats;
|
finalsolutions.save_scores(path + datafile + "_final_scores_" + expid + ".txt","#Final Solutions Scores");
|
||||||
splitstats(finalsolutions);
|
finalsolutions.save_trees(path + datafile + "_final_trees_" + expid + ".txt");
|
||||||
eoFileMonitor finalsplitstatsaver(path+datafile+"_clades_final_"+expid+".txt");
|
cout << "\ndone \n";
|
||||||
finalsplitstatsaver.add(splitstats);
|
|
||||||
finalsplitstatsaver();
|
// print the optimized solutions
|
||||||
//cout << splitstats.value() << endl;
|
//print_scores_pop( -2, population, evolution_data);
|
||||||
//partition_map split_frequences;
|
|
||||||
//calculate_frequence_splits(finalsolutions,split_frequences);
|
//print_scores_pop( -2, population, final_scores);
|
||||||
cout << " done\n";
|
|
||||||
//save_partitions(splitstats.value(), clades_final);
|
//save_trees(finalsolutions, final_trees);
|
||||||
//split_frequences.clear();
|
cout << "\n\nCalculating Final Solutions clade support...";
|
||||||
// remove dominate solutions
|
|
||||||
cout << "\nCalculating Pareto-optimal Solutions...";
|
PhyloMOEOPartitionStat splitstats;
|
||||||
|
splitstats(finalsolutions);
|
||||||
PhyloMOEOParetoSolutionsArchive paretosolutions;
|
eoFileMonitor finalsplitstatsaver(path+datafile+"_clades_final_"+expid+".txt");
|
||||||
paretosolutions.operator()(finalsolutions);
|
finalsplitstatsaver.add(splitstats);
|
||||||
paretosolutions.save_scores(path + datafile + "_pareto_scores_" + expid + ".txt","#Pareto Solutions Scores");
|
finalsplitstatsaver();
|
||||||
paretosolutions.save_trees(path + datafile + "_pareto_trees_" + expid + ".txt");
|
//cout << splitstats.value() << endl;
|
||||||
cout << " done\n";
|
//partition_map split_frequences;
|
||||||
// print final pareto trees
|
//calculate_frequence_splits(finalsolutions,split_frequences);
|
||||||
//save_trees( paretosolutions, final_pareto_trees);
|
cout << " done\n";
|
||||||
cout << "\nCalculating Pareto-optimal Solutions clade support...";
|
//save_partitions(splitstats.value(), clades_final);
|
||||||
splitstats(paretosolutions);
|
//split_frequences.clear();
|
||||||
//calculate_frequence_splits(paretosolutions,split_frequences);
|
// remove dominate solutions
|
||||||
eoFileMonitor paretosplitstatsaver(path+datafile+"_clades_pareto_"+expid+".txt");
|
cout << "\nCalculating Pareto-optimal Solutions...";
|
||||||
paretosplitstatsaver.add(splitstats);
|
|
||||||
paretosplitstatsaver();
|
PhyloMOEOParetoSolutionsArchive paretosolutions;
|
||||||
|
paretosolutions.operator()(finalsolutions);
|
||||||
// save_partitions(splitstats.value(), clades_pareto);
|
paretosolutions.save_scores(path + datafile + "_pareto_scores_" + expid + ".txt","#Pareto Solutions Scores");
|
||||||
//split_frequences.clear();
|
paretosolutions.save_trees(path + datafile + "_pareto_trees_" + expid + ".txt");
|
||||||
cout << " done\n";
|
cout << " done\n";
|
||||||
exp_data.close();
|
// print final pareto trees
|
||||||
evolution_data.close();
|
//save_trees( paretosolutions, final_pareto_trees);
|
||||||
pareto_scores.close();
|
cout << "\nCalculating Pareto-optimal Solutions clade support...";
|
||||||
final_scores.close();
|
splitstats(paretosolutions);
|
||||||
best_media_scores.close();
|
//calculate_frequence_splits(paretosolutions,split_frequences);
|
||||||
final_trees.close();
|
eoFileMonitor paretosplitstatsaver(path+datafile+"_clades_pareto_"+expid+".txt");
|
||||||
final_pareto_trees.close();
|
paretosplitstatsaver.add(splitstats);
|
||||||
clades_pareto.close();
|
paretosplitstatsaver();
|
||||||
clades_final.close();
|
|
||||||
|
// save_partitions(splitstats.value(), clades_pareto);
|
||||||
|
//split_frequences.clear();
|
||||||
|
cout << " done\n";
|
||||||
|
exp_data.close();
|
||||||
|
evolution_data.close();
|
||||||
|
pareto_scores.close();
|
||||||
|
final_scores.close();
|
||||||
|
best_media_scores.close();
|
||||||
|
final_trees.close();
|
||||||
|
final_pareto_trees.close();
|
||||||
|
clades_pareto.close();
|
||||||
|
clades_final.close();
|
||||||
|
cout << "\nPhyloMOEA execution finishes !\n";
|
||||||
|
}
|
||||||
gsl_rng_free(rn2);
|
gsl_rng_free(rn2);
|
||||||
// delete probmatrixs;
|
// delete probmatrixs;
|
||||||
delete rn;
|
delete rn;
|
||||||
cout << "\nPhyloMOEA execution finishes !\n";
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue