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 <string> // string
|
||||||
#include <utils/eoParser.h> // eoParser
|
#include <utils/eoParser.h> // eoParser
|
||||||
#include <eoPop.h> // eoPop
|
#include <eoPop.h> // eoPop
|
||||||
#include <eoGenContinue.h> // eoGenContinue
|
#include <eoEvalFuncPtr.h> // eoEvalFunc
|
||||||
#include <eoStochTournament.h> // eoStochTournament
|
#include <eoStochTournament.h> // eoStochTournament
|
||||||
#include <eoSGA.h> // eoSGA
|
|
||||||
#include <eoGenContinue.h> // eoGenContinue
|
#include <eoGenContinue.h> // eoGenContinue
|
||||||
|
#include <eoFitContinue.h> // eoFitContinue
|
||||||
|
#include <eoCombinedContinue.h> // eoCombinedContinue
|
||||||
#include <utils/eoCheckPoint.h> // eoCheckPoint
|
#include <utils/eoCheckPoint.h> // eoCheckPoint
|
||||||
#include <utils/eoStat.h> // eoSecondMomentStats
|
#include <utils/eoStat.h> // eoBestFitnessStat
|
||||||
#include <utils/eoStdoutMonitor.h> // eoStdoutMonitor
|
#include <utils/eoStdoutMonitor.h> // eoStdoutMonitor
|
||||||
|
#include <eoSGA.h> // eoSGA
|
||||||
#include "gprop.h" // Chrom eoChromInit eoChromMutation eoChromXover eoChromEvaluator
|
#include "gprop.h" // Chrom eoChromInit eoChromMutation eoChromXover eoChromEvaluator
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -132,15 +134,17 @@ void ga()
|
||||||
apply<Chrom>(evaluator, pop);
|
apply<Chrom>(evaluator, pop);
|
||||||
|
|
||||||
// selector
|
// selector
|
||||||
// eoProportional<Chrom> select(pop);
|
|
||||||
eoStochTournament<Chrom> select;
|
eoStochTournament<Chrom> select;
|
||||||
|
|
||||||
// genetic operators
|
// genetic operators
|
||||||
eoChromMutation mutation(generations);
|
eoChromMutation mutation;
|
||||||
eoChromXover xover;
|
eoChromXover xover;
|
||||||
|
|
||||||
// stop condition
|
// 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
|
// checkpoint
|
||||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||||
|
|
@ -150,7 +154,7 @@ void ga()
|
||||||
checkpoint.add(monitor);
|
checkpoint.add(monitor);
|
||||||
|
|
||||||
// statistics
|
// statistics
|
||||||
eoSecondMomentStats<Chrom> stats;
|
eoBestFitnessStat<Chrom> stats;
|
||||||
checkpoint.add(stats);
|
checkpoint.add(stats);
|
||||||
monitor.add(stats);
|
monitor.add(stats);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
#include <EO.h> // EO
|
#include <EO.h> // EO
|
||||||
#include <eoOp.h> // eoMonOp eoQuadraticOp
|
#include <eoOp.h> // eoMonOp eoQuadraticOp
|
||||||
#include <eoEvalFuncPtr.h> // eoEvalFunc
|
|
||||||
#include <eoInit.h> // eoInit
|
#include <eoInit.h> // eoInit
|
||||||
#include <utils/rnd_generators.h> // normal_generator
|
#include <utils/rnd_generators.h> // normal_generator
|
||||||
#include "mlp.h" // mlp::net mlp::set
|
#include "mlp.h" // mlp::net mlp::set
|
||||||
|
|
@ -110,18 +109,12 @@ mlp::set trn_set, val_set, tst_set;
|
||||||
class eoChromMutation: public eoMonOp<Chrom>
|
class eoChromMutation: public eoMonOp<Chrom>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
eoChromMutation(eoValueParam<unsigned>& _generation):
|
|
||||||
generation(_generation) {}
|
|
||||||
|
|
||||||
void operator()(Chrom& chrom)
|
void operator()(Chrom& chrom)
|
||||||
{
|
{
|
||||||
mse::net tmp(chrom);
|
mse::net tmp(chrom);
|
||||||
tmp.train(trn_set, 10, 0, 0.001);
|
tmp.train(trn_set, 10, 0, 0.001);
|
||||||
chrom.invalidate();
|
chrom.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
eoValueParam<unsigned>& generation;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ public:
|
||||||
// cout << " [" << thisGeneration << "] ";
|
// cout << " [" << thisGeneration << "] ";
|
||||||
if (thisGeneration >= repTotalGenerations)
|
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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Reference in a new issue