adding a new terminator and a monitor
This commit is contained in:
parent
41a85aaa7d
commit
2abab21960
3 changed files with 16 additions and 19 deletions
|
|
@ -9,13 +9,15 @@
|
|||
#include <string> // string
|
||||
#include <utils/eoParser.h> // eoParser
|
||||
#include <eoPop.h> // eoPop
|
||||
#include <eoEvalFuncPtr.h> // eoEvalFunc
|
||||
#include <eoStochTournament.h> // eoStochTournament
|
||||
#include <eoGenContinue.h> // eoGenContinue
|
||||
#include <eoStochTournament.h> // eoStochTournament
|
||||
#include <eoSGA.h> // eoSGA
|
||||
#include <eoGenContinue.h> // eoGenContinue
|
||||
#include <eoFitContinue.h> // eoFitContinue
|
||||
#include <eoCombinedContinue.h> // eoCombinedContinue
|
||||
#include <utils/eoCheckPoint.h> // eoCheckPoint
|
||||
#include <utils/eoStat.h> // eoSecondMomentStats
|
||||
#include <utils/eoStat.h> // eoBestFitnessStat
|
||||
#include <utils/eoStdoutMonitor.h> // eoStdoutMonitor
|
||||
#include <eoSGA.h> // eoSGA
|
||||
#include "gprop.h" // Chrom eoChromInit eoChromMutation eoChromXover eoChromEvaluator
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -126,21 +128,23 @@ void ga()
|
|||
// create population
|
||||
eoInitChrom init;
|
||||
eoPop<Chrom> pop(pop_size.value(), init);
|
||||
|
||||
|
||||
// evaluate population
|
||||
eoEvalFuncPtr<Chrom> evaluator(eoChromEvaluator);
|
||||
apply<Chrom>(evaluator, pop);
|
||||
|
||||
|
||||
// selector
|
||||
// eoProportional<Chrom> select(pop);
|
||||
eoStochTournament<Chrom> select;
|
||||
|
||||
// genetic operators
|
||||
eoChromMutation mutation(generations);
|
||||
eoChromMutation mutation;
|
||||
eoChromXover xover;
|
||||
|
||||
|
||||
// stop condition
|
||||
eoGenContinue<Chrom> continuator(generations.value());
|
||||
eoGenContinue<Chrom> continuator1(generations.value());
|
||||
phenotype p; p.val_ok = val_set.size() - 1; p.mse_error = 0;
|
||||
eoFitContinue<Chrom> continuator2(p);
|
||||
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
|
||||
|
||||
// checkpoint
|
||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||
|
|
@ -150,7 +154,7 @@ void ga()
|
|||
checkpoint.add(monitor);
|
||||
|
||||
// statistics
|
||||
eoSecondMomentStats<Chrom> stats;
|
||||
eoBestFitnessStat<Chrom> stats;
|
||||
checkpoint.add(stats);
|
||||
monitor.add(stats);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
#include <string> // string
|
||||
#include <EO.h> // EO
|
||||
#include <eoOp.h> // eoMonOp eoQuadraticOp
|
||||
#include <eoEvalFuncPtr.h> // eoEvalFunc
|
||||
#include <eoInit.h> // eoInit
|
||||
#include <utils/rnd_generators.h> // normal_generator
|
||||
#include "mlp.h" // mlp::net mlp::set
|
||||
|
|
@ -110,18 +109,12 @@ mlp::set trn_set, val_set, tst_set;
|
|||
class eoChromMutation: public eoMonOp<Chrom>
|
||||
{
|
||||
public:
|
||||
eoChromMutation(eoValueParam<unsigned>& _generation):
|
||||
generation(_generation) {}
|
||||
|
||||
void operator()(Chrom& chrom)
|
||||
{
|
||||
mse::net tmp(chrom);
|
||||
tmp.train(trn_set, 10, 0, 0.001);
|
||||
chrom.invalidate();
|
||||
}
|
||||
|
||||
private:
|
||||
eoValueParam<unsigned>& generation;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public:
|
|||
// cout << " [" << thisGeneration << "] ";
|
||||
if (thisGeneration >= repTotalGenerations)
|
||||
{
|
||||
cout << "STOP in eoGenContinue: Reached maximum number of generations\n";
|
||||
cout << "STOP in eoGenContinue: Reached maximum number of generations [" << thisGeneration << "/" << repTotalGenerations << "]\n";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
Reference in a new issue