Initial version of the tutorial.
Warning: all Makefile's are hand-made, and will only work in Linux
This commit is contained in:
parent
a27dc53ef0
commit
b8d4e7faef
48 changed files with 9174 additions and 0 deletions
531
eo/tutorial/html/eoLesson3.html
Normal file
531
eo/tutorial/html/eoLesson3.html
Normal file
|
|
@ -0,0 +1,531 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdksmp i686) [Netscape]">
|
||||
<title>Tutorial: Lesson 3</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoLesson2.html">Lesson 2</a> -
|
||||
<a href="eoLesson4.html">Lesson
|
||||
4</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Top-Down</a>
|
||||
- <a href="eoBottomUp.html">Bottom-up</a> - <a href="eoProgramming.html">Hints</a>
|
||||
- <b><font face="Arial,Helvetica"><a href="doc/html/index.html">EO documentation</a></font></b>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Tutorial Lesson 3: input/output</font></h1></center>
|
||||
In this lesson, you will still use the same Evolutionary Algorithm, BUT
|
||||
in a much more <b><font color="#FF6600">user-friendly</font></b> way. You
|
||||
will discover how to
|
||||
<ul>
|
||||
<li>
|
||||
<a href="#parser">input parameters</a> on the command-line or from a text
|
||||
file</li>
|
||||
|
||||
<li>
|
||||
<a href="#state">save</a> the population to disk, together with every part
|
||||
of the algrithm you could think of - so you can decide to <font color="#FF6600">reload</font>
|
||||
everything later to continue the same run, eventually with different parameters.</li>
|
||||
|
||||
<li>
|
||||
<a href="#stats">generate statistics</a> on the populations, and <a href="#monitor">output
|
||||
them</a> to the screen, text or graphic, or to a file (or to any other
|
||||
device you might want to use).</li>
|
||||
</ul>
|
||||
First, but you should now have done it without being told, go into the
|
||||
<font color="#FF6600">Lesson3
|
||||
sub-dir</font> of the tutorial dir and type
|
||||
<b><tt><font color="#990000"><font size=+1>make</font></font></tt></b>.
|
||||
This will compile the <b><tt><font color="#660000"><font size=+1>SecondBitEA</font></font></tt></b>
|
||||
program (and, some day, SecondRealEA).
|
||||
<p>You can then either
|
||||
<ul>
|
||||
<li>
|
||||
browse the corresponding code (only <a href="SecondBitEA.html">SecondBitEA</a>
|
||||
available right now, but you can figure out how SecondRealEA will look
|
||||
like),</li>
|
||||
|
||||
<li>
|
||||
look at the <a href="#changes">summary of changes</a>,</li>
|
||||
|
||||
<li>
|
||||
or find out directly explanations about the new features: the <a href="#parser">eoParser</a>,
|
||||
<a href="#state">eoState</a>
|
||||
and <a href="#checkpoint">eoCheckpoint</a> classes.</li>
|
||||
</ul>
|
||||
|
||||
<p><br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="changes"></a><b><font color="#000099"><font size=+2>Changes</font></font></b>
|
||||
<br><font color="#000000">As already said, the behavior of the algorithm
|
||||
will be exactly the same as the previous one as far as optimization is
|
||||
concerned. Only the input (of algorithm parameters) and output (of program
|
||||
results) will be very different.</font>
|
||||
<br><font color="#000000">Hence, the sections corresponding to the <a href="SecondBitEA.html#eval">fitness
|
||||
function</a>, the <a href="SecondBitEA.html#init">initialization</a>, the
|
||||
<a href="SecondBitEA.html#operators">variation
|
||||
operators</a>, the <a href="SecondBitEA.html#engine">evolution engine</a>
|
||||
and the <a href="SecondBitEA.html#generation">algorithm</a> itself are
|
||||
almost identical (apart from variable name changes).</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000"><a href="SecondBitEA.html#eval">Fitness function</a>:
|
||||
there is an </font><font color="#FF6600">additional line</font><font color="#000000">
|
||||
after the encapsulation of our </font><font color="#CC0000">binary_function</font><font color="#000000">
|
||||
into an </font><b><tt><font color="#CC0000"><font size=+1>eoEvalFunc</font></font></tt></b><font color="#000000">
|
||||
object, which again encapsulate the </font><b><tt><font color="#CC0000"><font size=+1>eoEvalFunc</font></font></tt></b><font color="#000000">
|
||||
into an </font><b><tt><font color="#CC0000"><font size=+1>eoEvalFuncCounter</font></font></tt></b><font color="#000000">.
|
||||
As its name says, thisobject will, in addition to computing the fitness,
|
||||
count the </font><b><font color="#FF6600">actual</font></b><font color="#000000">
|
||||
number of evaluations: the fitness of non-modified individuals is of course
|
||||
not recomputed - and this is taken care of by this object. Moreover, it
|
||||
can be later </font><font color="#FF6600">used for displays</font><font color="#000000">
|
||||
in <a href="#monitor">eoMonitor</a> objects, as done in the <a href="SecondBitEA.html#eval_monitor">checkpoint
|
||||
section</a>.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The <a href="SecondBitEA.html#init">initialization</a>
|
||||
section has been extended to account for the possibility to </font><font color="#CC33CC">re-load
|
||||
a previously saved population</font><font color="#000000">. This is achieved
|
||||
through an <a href="#state">eoState</a> object, if the corresponding program
|
||||
parameter is set.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The
|
||||
<a href="SecondBitEA.html#operators">variation
|
||||
operators</a> and the <a href="SecondBitEA.html#engine">evolution engine</a>
|
||||
sections are similar to the ones in Lesson2</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The </font><b><font color="#3366FF">parameter section</font></b><font color="#000000">
|
||||
is completely different from the previous one. All variables corresponding
|
||||
to </font><font color="#3366FF">program parameters</font><font color="#000000">
|
||||
are now </font><a href="SecondBitEA.html#seed_declare">declared</a><font color="#000000">
|
||||
in the </font><b><tt><font color="#990000"><font size=+1>main_function</font></font></tt></b><font color="#000000">
|
||||
(as before), but their values are set in a <a href="SecondBitEA.html#parametres">new
|
||||
function</a>, called </font><b><tt><font color="#660000">read_param.</font></tt></b><font color="#000000">
|
||||
See the <a href="#parser">eoParser</a> description for more details.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The <a href="SecondBitEA.html#stop">stopping criterion
|
||||
section</a>, has in fact now become the checkpoint section, as it involves
|
||||
much more than just stopping criteria. See all details in the <a href="#checkpoint">eoCheckpoint
|
||||
paragraph below</a>.</font></li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="parser"></a><b><font color="#000099"><font size=+2>eoParser:
|
||||
parameter input</font></font></b>
|
||||
<br><font color="#000000">The first two examples of Lessons 1 and 2 had
|
||||
a very crude way to set parameter values: they were hard-coded, and you
|
||||
had to recompile the whole program to change a single value. We shall now
|
||||
see now to set parameter values in a flexible way (though we're still looking
|
||||
for volunteers to create a Graphical User Interface :-)</font>
|
||||
<br><font color="#000000">Two base classes are used for that purpose:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">The </font><b><tt><font color="#3366FF">eoValueParam</font></tt></b><font color="#000000">
|
||||
class, </font><font color="#FF6600">templatized by the type of the variable</font><font color="#000000">
|
||||
you want to handle (i.e. i</font><b><tt><font color="#660000">nteger, double,
|
||||
yourPrivateClass</font></tt></b><font color="#000000">, ...). In this lesson,
|
||||
we will not go into details: e.g. we will not tell you that the
|
||||
<b><font face="Arial,Helvetica"><font size=+1><a href="doc/html/class_eovalueparam.html">eoValueParam</a></font></font></b>
|
||||
is actually a templatized sub-class of abstract class eoParam (oups, I
|
||||
said it!), nor will we deal with parameters outside their use from an eoParser.
|
||||
See the parameter section of the Bottom-up tutorial, or wait until <a href="eoLesson4.html">lesson
|
||||
4</a>).</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The </font><b><tt><font color="#3366FF">eoParser</font></tt></b><font color="#000000">
|
||||
class, whose only purpose is the input of parameters.</font></li>
|
||||
</ul>
|
||||
<b><font color="#FF0000">Modifying parameter values at run-time:</font></b>
|
||||
<br><font color="#000000">Using an eoParser object, the parameter values
|
||||
are read, by order of priority</font>
|
||||
<ol>
|
||||
<li>
|
||||
<font color="#000000">from the command-line</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">from a text file</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">from the environement</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">from default values</font></li>
|
||||
</ol>
|
||||
The syntax of parameter reading is a <b><font color="#FF6600">keyword</font></b>-based
|
||||
syntax, now traditional in the Unix world:
|
||||
<ul>
|
||||
<li>
|
||||
in EO, each parameter is designated by <font color="#FF6600">a (long) keyword</font>,
|
||||
and optionally by a <font color="#FF6600">short (1 character) keyword</font>.</li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
the general syntax to modify parameter value at run-time is (either from
|
||||
the command-line or in a text file)</li>
|
||||
|
||||
<br>
|
||||
<b><tt><font color="#660000">--longKeyword=value</font></tt></b>
|
||||
or <b><tt><font color="#660000">-c=value</font></tt></b>
|
||||
if 'c' is the short keyword
|
||||
<br>
|
||||
<li>
|
||||
so, after compiling the executable for Lesson 3 (<b><tt><font color="#FF6666">make
|
||||
lesson3</font></tt></b> at system prompt in Unix), you can try to type
|
||||
in</li>
|
||||
|
||||
<br>
|
||||
<b><tt><font color="#FF6666">SecondBitEA</font></tt></b>
|
||||
<br>and see the algorithm run as before (OneMax optimized on 8-bits bitstrings).
|
||||
But you can now type in
|
||||
<br>
|
||||
<b><tt><font color="#FF6666">SecondBitEA --vecSize=100</font></tt></b>
|
||||
<br>and see the output of the optimization of OneMax on 100-bit bitstings.
|
||||
<br>
|
||||
<li>
|
||||
Take a look at all available parameters by typing in</li>
|
||||
|
||||
<br>
|
||||
<b><tt><font color="#FF6666">SecondBitEA --help</font></tt></b>
|
||||
<br>or by going into the code: all parameter inputs have been grouped in
|
||||
the
|
||||
<a href="SecondBitEA.html#parametres">read_param</a> function.
|
||||
<br>
|
||||
<li>
|
||||
After running the algorithm, a new file has been created, named <b><tt><font color="#990000">SecondBitEA.status</font></tt></b>:
|
||||
it contains the list of all actual parameters used, and can directly be
|
||||
used as parameter input file: change the file name (e.g. to <b><tt><font color="#660000">SecondBitEA.param</font></tt></b>),
|
||||
edit it, change whichever parameter you want, and type in</li>
|
||||
|
||||
<br>
|
||||
|
||||
<b><tt><font color="#FF6666">SecondBitEA @SecondBitEA.param</font></tt></b>
|
||||
<br>and you will see all values that you defined into the file taken into
|
||||
account.
|
||||
<br>
|
||||
<li>
|
||||
The <font color="#FF6600">priority</font> remains to the <font color="#FF6600">command-line</font>,
|
||||
so you can still override the values in the parameter file by giving a
|
||||
new value directly on the command-line.</li>
|
||||
</ul>
|
||||
<b><font color="#FF0000">Programming parameter input:</font></b>
|
||||
<br>the code of SeconBitEA provides examples of parameters reading. Lets
|
||||
take the example of the random number generator <b><tt><font color="#660000">seed</font></tt></b>.
|
||||
<ul>
|
||||
<li>
|
||||
You first need to <a href="SecondBitEA.html#seed_declare">declare</a> it
|
||||
in the <b><tt><font color="#660000">main_function</font></tt></b>. As parameter
|
||||
reading will be done in the <b><tt><font color="#660000">read_param</font></tt></b>
|
||||
function, you need to pass it the variable seed. Note that read_param receives
|
||||
it <a href="SecondBitEA.html#seed_passing">by reference</a>, as it is going
|
||||
to modify its value!</li>
|
||||
|
||||
<li>
|
||||
In read_param, you need first to <a href="SecondBitEA.html#parser_declare">declare
|
||||
an eoParser object</a> (it needs the standard argc and argv in its constructor).</li>
|
||||
|
||||
<br>Then, <a href="SecondBitEA.html#_seed_declare">declare a parameter</a>
|
||||
of type <b><tt><font color="#660000">uint32</font></tt></b> (32-bits integer),
|
||||
and read it directly from the parser, using method <b><tt><font color="#660000">create_param</font></tt></b>.
|
||||
The arguments are obvious: default value, long keyword, comment (that will
|
||||
appear in the help message and in the output "status" file if any).
|
||||
<li>
|
||||
Finally, you need to <a href="SecondBitEA.html#seed_assign">assign the
|
||||
value</a> to the variable _seed (hence modifying the original seed variable).</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="state"></a><b><font color="#000099"><font size=+2>eoState:
|
||||
saving and loading</font></font></b>
|
||||
<br><font color="#000000">You might have noticed in the </font><b><tt><font color="#660000">read_param</font></tt></b><font color="#000000">
|
||||
described above a </font><font color="#FF6600">new parameter</font><font color="#000000">
|
||||
named </font><b><tt><font color="#660000"><a href="SecondBitEA.html#_load_name">load_name.</a></font></tt></b><font color="#000000">
|
||||
Now if you go to the <a href="SecondBitEA.html#init">init section</a> of
|
||||
the code, you will see an alternative way of </font><font color="#CC33CC">initializing
|
||||
the population</font><font color="#000000">: if load_name is an empty string,
|
||||
then we do as in the preceding example and use an eoInitFixedLength object.
|
||||
However, if a load_name name was entered, the population is read through
|
||||
the </font><b><tt><font color="#660000"><a href="SecondBitEA.html#instate.load">inState.load(load_name)</a></font></tt></b><font color="#000000">
|
||||
instruction. Moreover, the comment says "Loading pop </font><font color="#FF6600">and
|
||||
rng</font><font color="#000000">".</font>
|
||||
<p><font color="#000000">This is made possible using the </font><b><tt><font color="#3366FF">eoState</font></tt></b><font color="#000000">
|
||||
class. </font><b><tt><font color="#3366FF">eoState</font></tt></b><font color="#000000">
|
||||
objects maintain references to </font><b><tt><font color="#660000">eoObjects</font></tt></b><font color="#000000">
|
||||
that have both an input method (</font><b><tt><font color="#3366FF">readFrom</font></tt></b><font color="#000000">)
|
||||
and an output method (</font><b><tt><font color="#3366FF">printOn</font></tt></b><font color="#000000">),
|
||||
i.e. that derive from the base class </font><b><font face="Arial,Helvetica"><font color="#660000"><font size=+1><a href="doc/html/class_eopersistent.html">eoPersistent</a></font></font></font></b><font color="#000000">.
|
||||
You must first </font><b><tt><font color="#3366FF"><a href="SecondBitEA.html#register">register</a></font></tt></b><font color="#000000">
|
||||
object into a state, and can then save them to a (text) file, and later
|
||||
read them from that file using the </font><b><tt><font color="#3366FF">load</font></tt></b><font color="#000000">
|
||||
method, as done <a href="SecondBitEA.html#loadstate">here</a>.</font>
|
||||
<br><font color="#000000">Of course, you can call the </font><b><tt><font color="#3366FF">save</font></tt></b><font color="#000000">
|
||||
method for an </font><b><tt><font color="#3366FF">eoState</font></tt></b><font color="#000000">
|
||||
object anywhere in the code. But the <a href="#statesaver">checkpointing</a>
|
||||
mechanism offers you better ways to do that - and it's so easy ....</font>
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="checkpoint"></a><b><font color="#000099"><font size=+2>eoCheckpoint:
|
||||
every generation I'd like to ...</font></font></b>
|
||||
<br><font color="#000000">The checkpointing mechanism is a very powerfull
|
||||
construct to perform some </font><b><font color="#FF6600">systematic actions</font></b><font color="#000000">
|
||||
every generation - like </font><font color="#FF6600">saving things</font><font color="#000000">
|
||||
(using eoState objects described above), computing </font><font color="#FF6600">statistics</font><font color="#000000">
|
||||
on the population, </font><font color="#FF6600">updating</font><font color="#000000">
|
||||
dynamical parameters or </font><font color="#FF6600">displaying</font><font color="#000000">
|
||||
information.</font>
|
||||
<p><b><tt><font color="#3366FF">eoCheckpoint</font></tt></b><font color="#000000">
|
||||
objects are </font><b><tt><font color="#3366FF">eoContinue</font></tt></b><font color="#000000">
|
||||
objects that contain </font><font color="#FF6600">pointers to different
|
||||
types</font><font color="#000000"> of objects. When their </font><b><tt><font color="#660000">operator()</font></tt></b><font color="#000000">
|
||||
method is called (i.e. every generation in the examples up to now), they
|
||||
first call the </font><b><tt><font color="#660000">operator()</font></tt></b><font color="#000000">
|
||||
methods of all object they contain, and then return their result as an
|
||||
</font><b><tt><font color="#3366FF">eoContinue</font></tt></b><font color="#000000">
|
||||
object (i.e. should we continue or stop).</font>
|
||||
<br><b><font color="#FF0000">Programming: </font></b><font color="#000000">To
|
||||
do something every generation, you simply need to </font><b><tt><font color="#3366FF">add</font></tt></b><font color="#000000">
|
||||
an object whose </font><b><tt><font color="#660000">operator()</font></tt></b><font color="#000000">
|
||||
does what you want to the eoState that you will use as continuator in the
|
||||
algorithm.</font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="stop"></a><b><font color="#000099">eoCheckpoint:
|
||||
Stopping</font></b>
|
||||
<br><font color="#000000">The </font><b><tt><font color="#3366FF">eoContinue</font></tt></b><font color="#000000">
|
||||
part of an </font><b><tt><font color="#3366FF">eoCheckpoint</font></tt></b><font color="#000000">
|
||||
is a single object, <a href="SecondBitEA.html#checkpoint">passed to the
|
||||
constructor</a>. If you want more that one stopping criterion, use an <a href="SecondBitEA.html#stop">eoCombinedContinue</a>
|
||||
object as described in <a href="eoLesson2.html#combinedContinue">Lesson2</a>.</font>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="stats"></a><b><font color="#000099">eoCheckpoint: Computing
|
||||
statistics</font></b>
|
||||
<br><font color="#000000">Statistics are computed using </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
objects, i.e. functor objects whose </font><b><tt><font color="#660000">operator()</font></tt></b><font color="#000000">
|
||||
receives as argument a reference to a population as argument, and can hence
|
||||
compute whatever is needed over that population. </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
objects are </font><font color="#FF6600">templatized</font><font color="#000000">
|
||||
over the type of what they compute (e.g. </font><b><tt><font color="#660000">double</font></tt></b><font color="#000000">,
|
||||
or </font><b><tt><font color="#660000">pair<double></font></tt></b><font color="#000000">,
|
||||
or ...). But looking at the <a href="doc/html/class_eostat.html">inheritance
|
||||
diagram</a> of the </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
class, you find that </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
objects are also </font><b><tt><font color="#3366FF">eoValueParam</font></tt></b><font color="#000000">
|
||||
objects. And this allows </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
to be used within </font><b><tt><font color="#3366FF">eoMonitor</font></tt></b><font color="#000000">
|
||||
object, and hence </font><b><font color="#FF6600">displayed</font></b><font color="#000000">
|
||||
to the user!</font>
|
||||
<p><b><font color="#FF0000">Available statistics</font></b>: Some widely
|
||||
used statistics are already available (and of course you can build you
|
||||
own!).
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoBestFitnessStat</font></tt></b> returns
|
||||
the fitness value of the best individual in the population (of type <b><tt><font color="#660000">FitnessType</font></tt></b>,
|
||||
whatever this is).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoAverageStat</font></tt></b> and <b><tt><font color="#3366FF">eoSecondMomentStat</font></tt></b>
|
||||
respectiveley return the average (type double, assumes that <b><tt><font color="#660000">FitnessType</font></tt></b>
|
||||
is castable to a double) and a pair made of the average and the standard
|
||||
deviation (type <b><tt><font color="#660000">pair<double></font></tt></b>)
|
||||
of the fitnesses in the populations.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoDiversityStat</font></tt></b> returns the
|
||||
diversity in the population: asssuming that there is a distance function
|
||||
defined among individuals, it returns the average inter-individuals distance.
|
||||
See also Exercise 2.</li>
|
||||
</ul>
|
||||
<b><font color="#FF0000">Programming</font></b>: To compute some statistics
|
||||
within your algorithm, simply <a href="SecondBitEA.html#stat_declare">declare</a>
|
||||
the corresponding eoStat objects, and <a href="SecondBitEA.html#stat_pass">add</a>
|
||||
them to the <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b> you
|
||||
use in the algorithm.
|
||||
<p><b><font color="#FF0000">Note</font></b>: actually, there are 2 disctinct
|
||||
classes that compute and gove access to statistics: <b><tt><font color="#3366FF">eoStat</font></tt></b>
|
||||
and <b><tt><font color="#3366FF">eoSortedStat</font></tt></b>. As its name
|
||||
indicate, the latter is used whenever computing the statistics require
|
||||
a sorted population: not only this avoids to sort the population many times,
|
||||
but also it avoids changing the order of the population at all as eoSortedStat
|
||||
work on a temporary vector of fitnesses . But <font color="#FF6600">as
|
||||
far as their usage is concerned, its makes no difference</font>.
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="monitor"></a><b><font color="#000099">eoCheckpoint: Displaying
|
||||
eoParameters</font></b>
|
||||
<br><font color="#000000">The </font><b><tt><font color="#3366FF">eoMonitor</font></tt></b><font color="#000000">
|
||||
objects are used to display a set of </font><b><tt><font color="#3366FF">eoValueParam</font></tt></b><font color="#000000">
|
||||
objects.</font>
|
||||
<p><b><font color="#FF0000">Available monitors</font></b>: A few monitors
|
||||
are available in th eEO distribution:
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoStdoutMonitor</font></tt></b> displays its
|
||||
parameters in <font color="#FF6600">text format on the screen</font>. The
|
||||
(optional) boolean value in the constructor modifies the output: when true
|
||||
(the default), vebose output is used, with one line per parameter. When
|
||||
false, parcimonious output displays one line for all parameters.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoStdoutMonitor</font></tt></b> writes its
|
||||
parameters in <font color="#FF6600">text format in a file</font>. A file
|
||||
name is required in the constructor, and an optional separator character
|
||||
can be added (default is ','). Note that the file is overwritten by next
|
||||
call to the same program.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoGnuplot1DMonitor</font></tt></b> displays
|
||||
its parameters in <font color="#FF6600">graphical format on the screen</font>
|
||||
by calling the <b><tt><font color="#660000">gnuplot</font></tt></b> program,
|
||||
and as of today, only works in the Unix version of EO (as always, volunteers
|
||||
are welcome to port that to MS Windows). It takes an optional filename
|
||||
as input, as communication of data with <b><tt><font color="#660000">gnuplot</font></tt></b>
|
||||
is done through a file. If no filename is provided, the file will be erased
|
||||
at the end of the run, while it is otherwise kept (though it will be overwritten
|
||||
by next call to the same program).</li>
|
||||
</ul>
|
||||
|
||||
<p><br><b><font color="#FF0000">Programming:</font></b> To display something
|
||||
while the algorithm is running, you need to <a href="SecondBitEA.html#monitor_declare">declare</a>
|
||||
an <b><tt><font color="#3366FF">eoMonitor</font></tt></b> object, <a href="SecondBitEA.html#monitor_add">add</a>
|
||||
some objects (that must be <b><tt><font color="#3366FF">eoValueParam</font></tt></b>
|
||||
objects) to that monitor, and of course <a href="SecondBitEA.html#monitor_pass">add</a>
|
||||
the monitor to the <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b>
|
||||
you use in the algorithm.
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="update"></a><b><font color="#000099">eoCheckpoint: Updating
|
||||
things</font></b>
|
||||
<br><font color="#000000">The last type of objects that </font><b><tt><font color="#3366FF">eoCheckpoint</font></tt></b><font color="#000000">
|
||||
can handle are </font><b><tt><font color="#3366FF">eoUpdater</font></tt></b><font color="#000000">
|
||||
objects. You should simply encapsulate in an </font><b><tt><font color="#3366FF">eoUpdater</font></tt></b><font color="#000000">
|
||||
anything you wish to do which does not fit into one of the above category.
|
||||
Note that their </font><b><tt><font color="#660000">operator() method</font></tt></b><font color="#000000">
|
||||
does not receive any argument.</font>
|
||||
<p><b><font color="#FF0000">Available monitors</font></b>: A few updaters
|
||||
are available in the EO distribution:
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoIncrementor</font></tt></b> A simple updater
|
||||
which maintains a <font color="#FF6600">counter</font> (an <b><tt><font color="#3366FF">eoValueParam</font></tt></b>
|
||||
that needs to be created beforehand, and passed in the constructor). It
|
||||
is incremented everytime the <b><tt><font color="#660000">operator()</font></tt></b>
|
||||
method is called (every generation at the moment). You can of course also
|
||||
give an increment in the constructor (1 by default).</li>
|
||||
|
||||
<li>
|
||||
<a NAME="statesaver"></a><b><tt><font color="#3366FF">eoCountedStateSaver</font></tt></b>
|
||||
and <b><tt><font color="#3366FF">eoTimedStateSaver</font></tt></b> can
|
||||
be used to <font color="#FF6600">save</font> some existing <b><tt><font color="#3366FF">eoState</font></tt></b>
|
||||
(see <a href="#state">above</a>) to a file regularly, either based on the
|
||||
generation count (e.g. every 4 generations) or based on the clock (e.g.
|
||||
every 5 seconds).</li>
|
||||
</ul>
|
||||
<b><font color="#FF0000">Programming:</font></b>
|
||||
<br>A very simple example of using an <b><tt><font color="#3366FF">eoUpdater</font></tt></b>
|
||||
is given in the code for SecondBitEA: First <a href="SecondBitEA.html#param_declare">declare</a>
|
||||
an <b><tt><font color="#3366FF">eoValueParam</font></tt></b> object, then
|
||||
<a href="SecondBitEA.html#param_pass">use
|
||||
it to construct</a> an <b><tt><font color="#3366FF">eoIncrementor</font></tt></b>
|
||||
that you must <a href="SecondBitEA.html#updater_pass">add</a> to the <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b>
|
||||
in order to activate its update. You can then use the parameter for your
|
||||
purpose, for instance as a first coordinate for a monitor.
|
||||
<br>Note also how to use the statesavers: first <a href="SecondBitEA.html#outstate_declare">declare</a>
|
||||
a state, then <a href="SecondBitEA.html#outstate_register">register</a>
|
||||
whatever you think necessary to that state, then <a href="SecondBitEA.html#statesaver_declare">pass</a>
|
||||
the state to some state-saver - and don't forget to <a href="SecondBitEA.html#statesaver_pass">add</a>
|
||||
the statesavers to the current <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b>.
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>Exercice 1:</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">The code of </font><b><tt><font color="#660000"><font size=+1>SecondBitEA</font></font></tt></b><font color="#000000">
|
||||
display things in the current window in text format. Replace the </font><b><tt><font color="#3366FF">eoFileMonitor</font></tt></b><font color="#000000">
|
||||
by an </font><b><tt><font color="#3366FF">eoGnuplot1DMonitor</font></tt></b><font color="#000000">
|
||||
and watch the </font><b><font color="#FF6600">graphical output </font></b><font color="#000000">(</font><font color="#FF6600">Unix</font><font color="#000000">
|
||||
systems with </font><font color="#FF6600">gnuplot</font><font color="#000000">
|
||||
installed only, sorry).</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">Note that you must also replace the </font><b><tt><font color="#3366FF">eoSecondMomentStat</font></tt></b><font color="#000000">
|
||||
by an </font><b><tt><font color="#3366FF">eoAverageStat</font></tt></b><font color="#000000">,
|
||||
otherwise the standard deviations won't make any sense here.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">Please try to understand why the average is always
|
||||
0 before taking alook at the solution (file <a href="NoWay.html">exercise1.cpp</a>).</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">Then run</font></li>
|
||||
|
||||
<br><b><tt><font color="#660000"><font size=+1>
|
||||
exercise1 --vecSize=1000 --maxGen=1000</font></font></tt></b>
|
||||
<br><font color="#000000">to get a chance to see something hapenning before
|
||||
the program ends!</font></ul>
|
||||
|
||||
<hr WIDTH="100%"><b><font color="#000099"><font size=+2>Exercice 2:</font></font></b>
|
||||
<br><font color="#000000">Write the </font><b><tt><font color="#3366FF">eoDiversityStat</font></tt></b><font color="#000000">
|
||||
stat computation and test it. Thanks to send us the code!</font>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>Exercice 3:</font></font></b>
|
||||
<br><font color="#000000">Write the code for an </font><b><tt><font color="#3366FF"><font size=+1>eoGnuplot1DwithErrorbarsMonitor</font></font></tt></b><font color="#000000">
|
||||
that would take into account the standard deviations and display them as
|
||||
errorbars.</font>
|
||||
<br><font color="#000000">Again, send us the code afterwards, thanks :-)</font>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>Lessons learned:</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
Value of program parameters can be set <b><font color="#FF6600">at run-time</font></b>
|
||||
using the <b><tt><font color="#3366FF"><font size=+1>eoParser</font></font></tt></b>
|
||||
class.</li>
|
||||
|
||||
<li>
|
||||
<b><font color="#FF6600">Snapshots</font></b> of the algorithms can easily
|
||||
be <font color="#FF6600">saved</font> (and <font color="#FF6600">restored</font>)
|
||||
thanks to the <b><tt><font color="#3366FF"><font size=+1>eoState</font></font></tt></b>
|
||||
class.</li>
|
||||
|
||||
<li>
|
||||
The <b><tt><font color="#3366FF"><font size=+1>eoCheckpoint</font></font></tt></b>
|
||||
mechanism let you <b><font color="#FF6600">do things every generation</font></b>
|
||||
without modifying existing algorithms, by simply writing the necessary
|
||||
code and encapsulating it into an object that <b><tt><font color="#3366FF"><font size=+1>eoCheckpoint</font></font></tt></b>
|
||||
is aware of, that are at the moment the following:</li>
|
||||
|
||||
<li>
|
||||
computing <b><font color="#FF6600">statistics</font></b>, <b><font color="#FF6600">displaying
|
||||
</font></b>parameters
|
||||
(e.g. statistics), <b><font color="#FF6600">saving</font></b> the
|
||||
<b><tt><font color="#3366FF"><font size=+1>(eo)State</font></font></tt></b>
|
||||
of the program.</li>
|
||||
</ul>
|
||||
In next lesson you will find out that many <a href="intro.html#adaptive">adaptive
|
||||
techniques</a> (the state-of-the-art in Evolutionary Computation) can easily
|
||||
be programmed through the <b><tt><font color="#3366FF"><font size=+1>eoUpdater</font></font></tt></b>
|
||||
construct.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a href="eoLesson2.html">Lesson 2</a> -
|
||||
<a href="eoLesson4.html">Lesson
|
||||
4</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Top-Down</a>
|
||||
- <a href="eoBottomUp.html">Bottom-up</a> - <a href="eoProgramming.html">Hints</a>
|
||||
-<b> <font face="Arial,Helvetica"><a href="doc/html/index.html">EO documentation</a></font></b>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@polytechnique.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Fri Nov 3 18:49:12 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Mon Nov 27 8:49:12 CET 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
Reference in a new issue