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 <moeo>
|
||||
#include <peo>
|
||||
#include <PhyloMOEO.h>
|
||||
#include <PhyloMOEO_operators.h>
|
||||
#include <PhyloMOEO_init.h>
|
||||
#include <PhyloMOEO_eval.h>
|
||||
#include <PhyloMOEO_archive.h>
|
||||
#include <PhyloMOEOProbMatrixContainerUpdater.h>
|
||||
#include <PhyloMOEO_packunpack.h>
|
||||
#include <moeoNSGAII2.h>
|
||||
#include <utils/moeoBestObjVecStat.h>
|
||||
#include <utils/moeoAverageObjVecStat.h>
|
||||
|
|
@ -13,6 +15,7 @@
|
|||
#include <eoCountedFileMonitor.h>
|
||||
#include <eoSingleFileCountedStateSaver.h>
|
||||
#include <vectorSortIndex.h>
|
||||
|
||||
#include <utils.h>
|
||||
#include <ctime>
|
||||
#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;
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
welcome_message();
|
||||
|
||||
peo :: init( argc, argv );
|
||||
|
||||
|
||||
|
||||
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
|
||||
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();
|
||||
|
|
@ -52,18 +59,22 @@ int main(int argc, char *argv[])
|
|||
convert << seed;
|
||||
expid = parser.createParam(convert.str(), "expid", "Experiment ID", 'e',"Param").value();
|
||||
|
||||
|
||||
if(getNodeRank()==1) welcome_message();
|
||||
if( datafile.size()==0 )
|
||||
{
|
||||
parser.printHelp( cout );
|
||||
|
||||
if(getNodeRank()==1) parser.printHelp( cout );
|
||||
return(-1);
|
||||
}
|
||||
|
||||
|
||||
// all nodes read datafile and prepares likelihood and parsimony calculation
|
||||
string filename = path + datafile;
|
||||
cout << "\n\nReading Sequence Datafile...";
|
||||
Sequences seq(filename.c_str());
|
||||
cout << " done.\n";
|
||||
// calculate datafile
|
||||
cout << "calculating pattersn..." << getNodeRank() << endl;
|
||||
seq.calculate_patterns();
|
||||
seq.calculate_frequences();
|
||||
|
||||
|
|
@ -73,177 +84,208 @@ int main(int argc, char *argv[])
|
|||
ParsimonyCalculator parsi_calc(templatetree);
|
||||
SubstModel modelHKY( seq, SubstModel::HKY85);
|
||||
modelHKY.init();
|
||||
modelHKY.set_kappa(kappa); // banco_grande
|
||||
modelHKY.set_kappa(kappa);
|
||||
ProbMatrixContainer probmatrixs(modelHKY);
|
||||
LikelihoodCalculator lik_calc(templatetree, modelHKY, probmatrixs,ncats);
|
||||
lik_calc.set_alpha(alpha);
|
||||
modelHKY.init();
|
||||
PhyloEval byobj( parsi_calc, lik_calc );
|
||||
|
||||
Phyloraninit initializer(templatetree);
|
||||
|
||||
eoState state;
|
||||
|
||||
//eoPop <PhyloMOEO> &population = state.takeOwnership(eoPop<PhyloMOEO>(popsize, initializer));
|
||||
|
||||
eoPop<PhyloMOEO> population(popsize, initializer);
|
||||
//state.registerObject( population );
|
||||
peoMoeoPopEval <PhyloMOEO> eval(byobj);
|
||||
|
||||
cout << "\n\nReading Initial Trees...";
|
||||
if( usertree.size() >0)
|
||||
// Only the master node read the initial trees and writes ouput files
|
||||
if(getNodeRank()==1)
|
||||
{
|
||||
filename = path + usertree;
|
||||
readtrees(filename.c_str(), population);
|
||||
}
|
||||
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() )
|
||||
cout << "\n\nReading Initial Trees...";
|
||||
if( usertree.size() >0)
|
||||
{
|
||||
throw( ExceptionManager(12) );
|
||||
filename = path + usertree;
|
||||
readtrees(filename.c_str(), population);
|
||||
}
|
||||
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);
|
||||
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;
|
||||
Phylocross crossover;
|
||||
eoSequentialOp<PhyloMOEO> operadores;
|
||||
operadores.add(crossover,pcrossover);
|
||||
operadores.add(mutator,pmutation);
|
||||
PhyloMOEOProbMatrixContainerUpdater probmatrixupdater(probmatrixs);
|
||||
cp.add( bestfit);
|
||||
cp.add( avgfit);
|
||||
cp.add( media_scores);
|
||||
cp.add( evolution_scores );
|
||||
cp.add( popstats);
|
||||
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")
|
||||
{
|
||||
moeoAdditiveEpsilonBinaryMetric < ObjectiveVector > metric;
|
||||
moeoIBEA < PhyloMOEO > algo (cp, byobj, operadores, metric);
|
||||
cout << "\n\nRunning IBEA ..." << endl;
|
||||
algo(population);
|
||||
if(getNodeRank()==1){
|
||||
cout << "\n\nRunning IBEA ..." << endl; }
|
||||
peoWrapper parallelEA( algo, population);
|
||||
eval.setOwner(parallelEA);
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
//algo(population);
|
||||
}
|
||||
else
|
||||
{
|
||||
moeoNSGAII < PhyloMOEO > algo (cp, byobj, operadores);
|
||||
cout << "\n\nRunning NSGA-II ..." << endl;
|
||||
algo(population);
|
||||
|
||||
if(getNodeRank()==1){
|
||||
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 << " done\n";
|
||||
|
||||
PhyloMOEOFinalSolutionsArchive finalsolutions;
|
||||
finalsolutions.operator()(population);
|
||||
|
||||
//remove_final_solutions( population );
|
||||
// optimize remaining solutions
|
||||
cout << "\nOptimizing tree branch lenghts...\n";
|
||||
cout << "\nCalculating Final Solutions...";
|
||||
cout << " done\n";
|
||||
|
||||
optimize_solutions( finalsolutions, lik_calc );
|
||||
cout << "\nReevaluating individuals \n";
|
||||
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";
|
||||
PhyloMOEOFinalSolutionsArchive finalsolutions;
|
||||
finalsolutions.operator()(population);
|
||||
|
||||
// print the optimized solutions
|
||||
//print_scores_pop( -2, population, evolution_data);
|
||||
|
||||
//print_scores_pop( -2, population, final_scores);
|
||||
|
||||
//save_trees(finalsolutions, final_trees);
|
||||
cout << "\n\nCalculating Final Solutions clade support...";
|
||||
//remove_final_solutions( population );
|
||||
// optimize remaining solutions
|
||||
cout << "\nOptimizing tree branch lenghts...\n";
|
||||
|
||||
//optimize_solutions( finalsolutions, lik_calc );
|
||||
cout << "\nReevaluating individuals \n";
|
||||
apply<PhyloMOEO> ( byobj, finalsolutions );
|
||||
|
||||
PhyloMOEOPartitionStat splitstats;
|
||||
splitstats(finalsolutions);
|
||||
eoFileMonitor finalsplitstatsaver(path+datafile+"_clades_final_"+expid+".txt");
|
||||
finalsplitstatsaver.add(splitstats);
|
||||
finalsplitstatsaver();
|
||||
//cout << splitstats.value() << endl;
|
||||
//partition_map split_frequences;
|
||||
//calculate_frequence_splits(finalsolutions,split_frequences);
|
||||
cout << " done\n";
|
||||
//save_partitions(splitstats.value(), clades_final);
|
||||
//split_frequences.clear();
|
||||
// remove dominate solutions
|
||||
cout << "\nCalculating Pareto-optimal Solutions...";
|
||||
|
||||
PhyloMOEOParetoSolutionsArchive paretosolutions;
|
||||
paretosolutions.operator()(finalsolutions);
|
||||
paretosolutions.save_scores(path + datafile + "_pareto_scores_" + expid + ".txt","#Pareto Solutions Scores");
|
||||
paretosolutions.save_trees(path + datafile + "_pareto_trees_" + expid + ".txt");
|
||||
cout << " done\n";
|
||||
// print final pareto trees
|
||||
//save_trees( paretosolutions, final_pareto_trees);
|
||||
cout << "\nCalculating Pareto-optimal Solutions clade support...";
|
||||
splitstats(paretosolutions);
|
||||
//calculate_frequence_splits(paretosolutions,split_frequences);
|
||||
eoFileMonitor paretosplitstatsaver(path+datafile+"_clades_pareto_"+expid+".txt");
|
||||
paretosplitstatsaver.add(splitstats);
|
||||
paretosplitstatsaver();
|
||||
|
||||
// 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();
|
||||
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
|
||||
//print_scores_pop( -2, population, evolution_data);
|
||||
|
||||
//print_scores_pop( -2, population, final_scores);
|
||||
|
||||
//save_trees(finalsolutions, final_trees);
|
||||
cout << "\n\nCalculating Final Solutions clade support...";
|
||||
|
||||
PhyloMOEOPartitionStat splitstats;
|
||||
splitstats(finalsolutions);
|
||||
eoFileMonitor finalsplitstatsaver(path+datafile+"_clades_final_"+expid+".txt");
|
||||
finalsplitstatsaver.add(splitstats);
|
||||
finalsplitstatsaver();
|
||||
//cout << splitstats.value() << endl;
|
||||
//partition_map split_frequences;
|
||||
//calculate_frequence_splits(finalsolutions,split_frequences);
|
||||
cout << " done\n";
|
||||
//save_partitions(splitstats.value(), clades_final);
|
||||
//split_frequences.clear();
|
||||
// remove dominate solutions
|
||||
cout << "\nCalculating Pareto-optimal Solutions...";
|
||||
|
||||
PhyloMOEOParetoSolutionsArchive paretosolutions;
|
||||
paretosolutions.operator()(finalsolutions);
|
||||
paretosolutions.save_scores(path + datafile + "_pareto_scores_" + expid + ".txt","#Pareto Solutions Scores");
|
||||
paretosolutions.save_trees(path + datafile + "_pareto_trees_" + expid + ".txt");
|
||||
cout << " done\n";
|
||||
// print final pareto trees
|
||||
//save_trees( paretosolutions, final_pareto_trees);
|
||||
cout << "\nCalculating Pareto-optimal Solutions clade support...";
|
||||
splitstats(paretosolutions);
|
||||
//calculate_frequence_splits(paretosolutions,split_frequences);
|
||||
eoFileMonitor paretosplitstatsaver(path+datafile+"_clades_pareto_"+expid+".txt");
|
||||
paretosplitstatsaver.add(splitstats);
|
||||
paretosplitstatsaver();
|
||||
|
||||
// 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);
|
||||
// delete probmatrixs;
|
||||
// delete probmatrixs;
|
||||
delete rn;
|
||||
cout << "\nPhyloMOEA execution finishes !\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue