Adding the statistics in createSimple (create.sh is becoming obsolete)
This commit is contained in:
parent
b0969cf3d4
commit
13c7062858
5 changed files with 184 additions and 11 deletions
|
|
@ -5,9 +5,9 @@ DIR_EO = ../../src
|
|||
# END eventually modify the name of EO dir
|
||||
LIB_EO = $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
|
||||
|
||||
.cpp: ; c++ -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -o $@ $*.cpp $(LIB_EO)
|
||||
.cpp: ; c++ -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -Wno-deprecated -g -o $@ $*.cpp $(LIB_EO)
|
||||
|
||||
.cpp.o: ; c++ -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -c $*.cpp
|
||||
.cpp.o: ; c++ -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -Wno-deprecated -g -c $*.cpp
|
||||
|
||||
# local sources
|
||||
SOURCES = MyStructEA.cpp \
|
||||
|
|
@ -18,7 +18,7 @@ SOURCES = MyStructEA.cpp \
|
|||
eoMyStructQuadCrossover.h
|
||||
|
||||
MyStructEA : MyStructEA.cpp
|
||||
c++ -I. -I$(DIR_EO) -g -o $@ MyStructEA.cpp $(LIB_EO) -lm
|
||||
c++ -I. -I$(DIR_EO) -Wno-deprecated -g -o $@ MyStructEA.cpp $(LIB_EO) -lm
|
||||
|
||||
tar : ; tar czvf MyStruct.tgz *.h *.cpp Makefile
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ using namespace std;
|
|||
#include "eoMyStructQuadCrossover.h"
|
||||
#include "eoMyStructMutation.h"
|
||||
|
||||
/* and (possibly) your personal statistics */
|
||||
#include "eoMyStructStat.h"
|
||||
|
||||
// GENOTYPE eoMyStruct ***MUST*** be templatized over the fitness
|
||||
|
||||
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
|
|
@ -92,9 +95,9 @@ eoCheckPoint<Indi>& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFu
|
|||
|
||||
// evolution engine (selection and replacement)
|
||||
#include <do/make_algo_scalar.h>
|
||||
eoAlgo<Indi>& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>& _continue, eoGenOp<Indi>& _op)
|
||||
eoAlgo<Indi>& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>& _continue, eoGenOp<Indi>& _op, eoDistance<Indi> *_dist = NULL)
|
||||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist);
|
||||
}
|
||||
|
||||
// simple call to the algo. stays there for consistency reasons
|
||||
|
|
@ -133,6 +136,15 @@ try
|
|||
// - call it from here:
|
||||
// eoMyStructInit<Indi> init(parser);
|
||||
|
||||
// if you want to do sharing, you'll need a distance.
|
||||
// see file utils/eoDistance.h
|
||||
//
|
||||
// IF you representation has an operator[]() double-castable,
|
||||
// then you can use for instance the quadratic distance (L2 norm)
|
||||
// eoQuadDistance<Indi> dist;
|
||||
// or the Hamming distance (L1 norm)
|
||||
// eoHammingDistance<Indi> dist;
|
||||
|
||||
|
||||
// Build the variation operator (any seq/prop construct)
|
||||
// here, a simple example with only 1 crossover (2->2, a QuadOp) and
|
||||
|
|
@ -165,7 +177,7 @@ try
|
|||
/////////////// Same thing for MUTATION
|
||||
|
||||
// a (first) mutation (possibly use the parser in its Ctor)
|
||||
eoMyStructMutation<Indi> mut /* (eoParser parser) */;
|
||||
eoMyStructMutation<Indi> mut /* (parser) */;
|
||||
|
||||
// IF MORE THAN ONE:
|
||||
|
||||
|
|
@ -205,10 +217,12 @@ try
|
|||
eoSGAGenOp<Indi> op(cross, pCross, mut, pMut);
|
||||
|
||||
|
||||
//// Now the representation-independent things
|
||||
//// Now some representation-independent things
|
||||
//
|
||||
// YOU SHOULD NOT NEED TO MODIFY ANYTHING BEYOND THIS POINT
|
||||
// You do not need to modify anything beyond this point
|
||||
// unless you want to add specific statistics to the checkpoint
|
||||
// in which case you should uncomment the corresponding block
|
||||
// and possibly modify the parameters in the stat object creation
|
||||
//////////////////////////////////////////////
|
||||
|
||||
// initialize the population
|
||||
|
|
@ -219,8 +233,90 @@ try
|
|||
eoContinue<Indi> & term = make_continue(parser, state, eval);
|
||||
// output
|
||||
eoCheckPoint<Indi> & checkpoint = make_checkpoint(parser, state, eval, term);
|
||||
|
||||
|
||||
// UNCOMMENT the following commented block if you want to add you stats
|
||||
|
||||
// if uncommented, it is assumed that you will want to print some stat.
|
||||
// if not, then the following objects will be created uselessly - but what the heck!
|
||||
|
||||
eoMyStructStat<Indi> myStat; // or maybe myStat(parser);
|
||||
checkpoint.add(myStat);
|
||||
// This one is probably redundant with the one in make_checkpoint, but w.t.h.
|
||||
eoIncrementorParam<unsigned> generationCounter("Gen.");
|
||||
checkpoint.add(generationCounter);
|
||||
// need to get the name of the redDir param (if any)
|
||||
std::string dirName = parser.getORcreateParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output - Disk").value() + "/";
|
||||
|
||||
|
||||
// those need to be pointers because of the if's
|
||||
eoStdoutMonitor *myStdOutMonitor;
|
||||
eoFileMonitor *myFileMonitor;
|
||||
#if !defined(NO_GNUPLOT)
|
||||
eoGnuplot1DMonitor *myGnuMonitor;
|
||||
#endif
|
||||
|
||||
// now check how you want to output the stat:
|
||||
bool printMyStructStat = parser.createParam(true, "coutMyStructStat", "Affiche ma stat à l'écran", '\0', "Mon Probleme").value();
|
||||
bool fileMyStructStat = parser.createParam(false, "fileMyStructStat", "Stocke ma stat Dans un fichier", '\0', "Mon Probleme").value();
|
||||
bool plotMyStructStat = parser.createParam(false, "plotMyStructStat", "Affiche graphiquement ma stat pendant l'évolution", '\0', "Mon Probleme").value();
|
||||
|
||||
// should we write it on StdOut ?
|
||||
if (printMyStructStat)
|
||||
{
|
||||
myStdOutMonitor = new eoStdoutMonitor(false);
|
||||
// don't forget to store the memory in the state
|
||||
state.storeFunctor(myStdOutMonitor);
|
||||
// and of course to add the monitor to the checkpoint
|
||||
checkpoint.add(*myStdOutMonitor);
|
||||
// and the different fields to the monitor
|
||||
myStdOutMonitor->add(generationCounter);
|
||||
myStdOutMonitor->add(eval);
|
||||
myStdOutMonitor->add(myStat);
|
||||
}
|
||||
|
||||
// first check the directory (and creates it if not exists already):
|
||||
if (fileMyStructStat || plotMyStructStat)
|
||||
if (! testDirRes(dirName, true) )
|
||||
throw runtime_error("Problem with resDir");
|
||||
|
||||
// should we write it to a file ?
|
||||
if (fileMyStructStat)
|
||||
{
|
||||
myFileMonitor = new eoFileMonitor(dirName + "myStat.xg");
|
||||
// don't forget to store the memory in the state
|
||||
state.storeFunctor(myFileMonitor);
|
||||
// and of course to add the monitor to the checkpoint
|
||||
checkpoint.add(*myFileMonitor);
|
||||
// and the different fields to the monitor
|
||||
myFileMonitor->add(generationCounter);
|
||||
myFileMonitor->add(eval);
|
||||
myFileMonitor->add(myStat);
|
||||
}
|
||||
|
||||
#if !defined(NO_GNUPLOT)
|
||||
// should we PLOT it on StdOut ? (one dot per generation, incremental plot)
|
||||
if (plotMyStructStat)
|
||||
{
|
||||
myGnuMonitor = new eoGnuplot1DMonitor(dirName+"plot_myStat.xg",minimizing_fitness<Indi>());
|
||||
// NOTE: you cand send commands to gnuplot at any time with the method
|
||||
// myGnuMonitor->gnuplotCommand(string)
|
||||
// par exemple, gnuplotCommand("set logscale y")
|
||||
|
||||
// don't forget to store the memory in the state
|
||||
state.storeFunctor(myGnuMonitor);
|
||||
// and of course to add the monitor to the checkpoint
|
||||
checkpoint.add(*myGnuMonitor);
|
||||
// and the different fields to the monitor (X = eval, Y = myStat)
|
||||
myGnuMonitor->add(eval);
|
||||
myGnuMonitor->add(myStat);
|
||||
}
|
||||
#endif
|
||||
|
||||
// algorithm (need the operator!)
|
||||
eoAlgo<Indi>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);
|
||||
// and the distance if you want to do sharing
|
||||
// eoAlgo<Indi>& ga = make_algo_scalar(parser, state, eval, checkpoint, op, &dist);
|
||||
|
||||
///// End of construction of the algorithm
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,15 @@
|
|||
Quick NOTE: This version of README is obsolete (May 25, 2004)
|
||||
In particular, a simpler version of the algorithm can be generated
|
||||
using the script
|
||||
createSimple
|
||||
|
||||
with the same syntax. It is also more powerful, allowing for instance
|
||||
to create you own statistics on the population, saving it in a file
|
||||
and/or plotting on on-line during the run (see eoStat.tmpl).
|
||||
More details some day, when I have some time ...
|
||||
|
||||
============= Old README (most is still accurate, though) ==========
|
||||
|
||||
This directory contains sample files that should make it easy to
|
||||
create an EO algorithm to evolve any type of structure
|
||||
(EO comes with two examples, bitstrings and vector of real variables,
|
||||
|
|
@ -9,7 +21,7 @@ objective fitness - or be patient :-)
|
|||
|
||||
This file will help you to build the same algorithm than the ones
|
||||
in the Lesson4 of the tutorial, but with YOUR genotype instead of
|
||||
bitstrings or vector<double>
|
||||
bitstrings or vector<double>. More details in Lesson5 of the tutorial.
|
||||
|
||||
It is assumed in the following that you have read the first part of
|
||||
the tutorial (Lessons 1 to 4).
|
||||
|
|
@ -89,7 +101,7 @@ want to become active), and run
|
|||
|
||||
% eoAppliEA @eoAppliEA.param
|
||||
|
||||
(see the Lesson 4 of the tutorial for more details now).
|
||||
(see the Lesson 5 of the tutorial for more details now).
|
||||
|
||||
HINTS
|
||||
-----
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ endif
|
|||
|
||||
if (-f $TargetDir/Makefile) then
|
||||
echo A Makefile already exists there.
|
||||
echo I'm creating Makefile.$1. You'll have to merge them both,
|
||||
echo "I'm creating Makefile.$1. You'll have to merge them both,"
|
||||
echo OR to call make -f Makefile.$1
|
||||
set MakeName = Makefile.$1
|
||||
else
|
||||
|
|
@ -48,6 +48,7 @@ echo Creating source files for application $1 in $TargetDir/
|
|||
|
||||
sed s/MyStruct/$1/g eoMyStruct.tmpl > $TargetDir/eo$1.h
|
||||
sed s/MyStruct/$1/g init.tmpl > $TargetDir/eo$1Init.h
|
||||
sed s/MyStruct/$1/g stat.tmpl > $TargetDir/eo$1Stat.h
|
||||
sed s/MyStruct/$1/g evalFunc.tmpl > $TargetDir/eo$1EvalFunc.h
|
||||
sed s/MyStruct/$1/g mutation.tmpl > $TargetDir/eo$1Mutation.h
|
||||
sed s/MyStruct/$1/g quadCrossover.tmpl > $TargetDir/eo$1QuadCrossover.h
|
||||
|
|
|
|||
64
eo/tutorial/Templates/stat.tmpl
Normal file
64
eo/tutorial/Templates/stat.tmpl
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
The above line is usefulin Emacs-like editors
|
||||
*/
|
||||
|
||||
/*
|
||||
Template for computing statistics on eoPop
|
||||
============================================
|
||||
*/
|
||||
|
||||
#ifndef _eoMyStructStat_h
|
||||
#define _eoMyStructStat_h
|
||||
|
||||
// include the base definition of eoInit
|
||||
#include <utils/eoStat.h>
|
||||
|
||||
/**
|
||||
* Always write a comment in this format before class definition
|
||||
* if you want the class to be documented by Doxygen
|
||||
*
|
||||
* ASSUMPTION on the class GenoypeT:
|
||||
* it needs to derive from EO (i.e. has a Fitness).
|
||||
*
|
||||
* It is assumed that you want to compute a double.
|
||||
* In case you want something else, then your stat should derive from
|
||||
* eoStat<GenotypeT, T>
|
||||
* where class T is the class of the computed statistics
|
||||
*/
|
||||
template <class EOT>
|
||||
class eoMyStructStat : public eoStat<EOT, double>
|
||||
{
|
||||
public :
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
|
||||
// START eventually add or modify the anyVariable argument
|
||||
/** Ctor - you change the default name of course.
|
||||
* @param
|
||||
* _description : inherited from eoValueParam (eoStat is an from eoVapueParam)
|
||||
*/
|
||||
eoMyStructStat(std::string _description = "eoMyStructStat ") :
|
||||
eoStat<EOT, double>(0.0, _description)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoMonReelStat object
|
||||
// END Code of Ctor of an eoMonReelStat object
|
||||
}
|
||||
|
||||
void operator()(const eoPop<EOT>& _pop){
|
||||
double tmpStat;
|
||||
// START Code for computing the statistics - in tmpStat
|
||||
// tmpStat = blablabla
|
||||
// END Code for computing the statistics
|
||||
value() = tmpStat; // store the stat in the eoParam value() field
|
||||
}
|
||||
|
||||
virtual std::string className(void) const { return "eoMyStructStat"; }
|
||||
private :
|
||||
// START Private data of an eoMyStructStat object
|
||||
// varType anyVariable; // for example ...
|
||||
// END Private data of an eoMyStructStat object
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue