Simplify configuration.
Remove support for (outdated) <strstream>, require <sstream>. Require uint32_t for now, defined in stdint.h according to C99. Some general cleanup and more documentation.
This commit is contained in:
parent
abe55a641a
commit
cf2a57dd88
46 changed files with 482 additions and 886 deletions
|
|
@ -245,6 +245,9 @@ namespace mlp {
|
||||||
load(is);
|
load(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Virtual destructor */
|
||||||
|
virtual ~net() {};
|
||||||
|
|
||||||
void load(istream &is) {
|
void load(istream &is) {
|
||||||
unsigned num_inputs;
|
unsigned num_inputs;
|
||||||
unsigned num_outputs;
|
unsigned num_outputs;
|
||||||
|
|
@ -253,7 +256,7 @@ namespace mlp {
|
||||||
is >> num_inputs >> num_outputs >> num_hidden_layers;
|
is >> num_inputs >> num_outputs >> num_hidden_layers;
|
||||||
|
|
||||||
std::vector<unsigned> layer_sizes;
|
std::vector<unsigned> layer_sizes;
|
||||||
for (int i=0; i<num_hidden_layers;i++) {
|
for (unsigned i=0; i<num_hidden_layers;i++) {
|
||||||
unsigned layer_size;
|
unsigned layer_size;
|
||||||
is >> layer_size;
|
is >> layer_size;
|
||||||
layer_sizes.push_back(layer_size);
|
layer_sizes.push_back(layer_size);
|
||||||
|
|
|
||||||
|
|
@ -28,28 +28,27 @@ AC_PROG_MAKE_SET
|
||||||
AC_PROG_RANLIB
|
AC_PROG_RANLIB
|
||||||
AC_CHECK_PROG(DOXYGEN, doxygen, doxygen, true)
|
AC_CHECK_PROG(DOXYGEN, doxygen, doxygen, true)
|
||||||
|
|
||||||
dnl Checks for header files.
|
dnl Checks for compiler characteristics.
|
||||||
AC_HEADER_STDC
|
|
||||||
AC_CHECK_HEADERS(inttypes.h)
|
|
||||||
AC_CHECK_HEADERS(limits.h)
|
|
||||||
AC_CHECK_HEADERS(values.h)
|
|
||||||
AC_CXX_HAVE_NUMERIC_LIMITS
|
|
||||||
AC_CXX_HAVE_SSTREAM
|
|
||||||
AC_CXX_NAMESPACES
|
AC_CXX_NAMESPACES
|
||||||
|
AC_TYPE_SIZE_T
|
||||||
|
|
||||||
|
dnl Checks for header files.
|
||||||
|
AC_LANG(C)
|
||||||
|
AC_HEADER_STDC
|
||||||
|
AC_CHECK_HEADERS(limits.h)
|
||||||
|
AC_LANG(C++)
|
||||||
|
AC_CHECK_HEADERS(sstream, [], AC_MSG_ERROR([Need sstream C++ include.]))
|
||||||
|
AC_CHECK_HEADERS(stdint.h, [], AC_MSG_WARN([Need C99 standard header.]))
|
||||||
|
AC_CXX_HAVE_NUMERIC_LIMITS
|
||||||
|
|
||||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||||
AC_C_CONST
|
AC_CHECK_SIZEOF(unsigned long)
|
||||||
AC_C_INLINE
|
AC_CHECK_TYPES(uint32_t, [], AC_MSG_WARN([Need uint32_t from C99 standard.]))
|
||||||
AC_CHECK_SIZEOF([unsigned long])
|
|
||||||
AC_CHECK_TYPES(uint32_t)
|
|
||||||
AC_TYPE_SIZE_T
|
|
||||||
|
|
||||||
dnl Checks for libraries.
|
dnl Checks for libraries.
|
||||||
AC_CHECK_LIB(m, cos)
|
AC_CHECK_LIB(m, cos)
|
||||||
|
|
||||||
dnl Checks for library functions.
|
dnl Checks for library functions.
|
||||||
AC_CHECK_FUNCS(select)
|
|
||||||
|
|
||||||
|
|
||||||
dnl create makefiles
|
dnl create makefiles
|
||||||
AC_OUTPUT(Makefile \
|
AC_OUTPUT(Makefile \
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,6 @@ libeo_a_SOURCES = eoFunctorStore.cpp \
|
||||||
eoScalarFitnessAssembled.cpp
|
eoScalarFitnessAssembled.cpp
|
||||||
|
|
||||||
|
|
||||||
AM_CXXFLAGS = -I$(top_srcdir)/src
|
|
||||||
|
|
||||||
pkginclude_HEADERS = eo \
|
pkginclude_HEADERS = eo \
|
||||||
EO.h \
|
EO.h \
|
||||||
apply.h \
|
apply.h \
|
||||||
|
|
@ -114,3 +112,6 @@ pkginclude_HEADERS = eo \
|
||||||
es.h \
|
es.h \
|
||||||
ga.h
|
ga.h
|
||||||
|
|
||||||
|
AM_CXXFLAGS = -I$(top_srcdir)/src
|
||||||
|
|
||||||
|
AM_LIBS = -Lutils -leoutil
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// make_checkpoint_pareto.h
|
// make_checkpoint_pareto.h
|
||||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000
|
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
|
|
@ -32,11 +32,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#else
|
|
||||||
#include <strstream>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "EO.h"
|
#include "EO.h"
|
||||||
#include "eoParetoFitness.h"
|
#include "eoParetoFitness.h"
|
||||||
|
|
@ -55,7 +51,7 @@ template <class EOT>
|
||||||
eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state, eoEvalFuncCounter<EOT>& _eval, eoContinue<EOT>& _continue)
|
eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state, eoEvalFuncCounter<EOT>& _eval, eoContinue<EOT>& _continue)
|
||||||
{
|
{
|
||||||
// first, create a checkpoint from the eoContinue - and store in _state
|
// first, create a checkpoint from the eoContinue - and store in _state
|
||||||
eoCheckPoint<EOT> & checkpoint =
|
eoCheckPoint<EOT> & checkpoint =
|
||||||
_state.storeFunctor(new eoCheckPoint<EOT>(_continue));
|
_state.storeFunctor(new eoCheckPoint<EOT>(_continue));
|
||||||
|
|
||||||
/////// get number of obectives from Fitness - not very elegant
|
/////// get number of obectives from Fitness - not very elegant
|
||||||
|
|
@ -72,9 +68,9 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
|
||||||
// Create anyway a generation-counter parameter WARNING: not stored anywhere!!!
|
// Create anyway a generation-counter parameter WARNING: not stored anywhere!!!
|
||||||
eoValueParam<unsigned> *generationCounter = new eoValueParam<unsigned>(0, "Gen.");
|
eoValueParam<unsigned> *generationCounter = new eoValueParam<unsigned>(0, "Gen.");
|
||||||
// Create an incrementor (sub-class of eoUpdater).
|
// Create an incrementor (sub-class of eoUpdater).
|
||||||
eoIncrementor<unsigned> & increment =
|
eoIncrementor<unsigned> & increment =
|
||||||
_state.storeFunctor(new eoIncrementor<unsigned>(generationCounter->value()) );
|
_state.storeFunctor(new eoIncrementor<unsigned>(generationCounter->value()) );
|
||||||
// Add it to the checkpoint,
|
// Add it to the checkpoint,
|
||||||
checkpoint.add(increment);
|
checkpoint.add(increment);
|
||||||
|
|
||||||
// dir for DISK output
|
// dir for DISK output
|
||||||
|
|
@ -109,7 +105,7 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
|
||||||
unsigned frequency = atoi(fPlot.first.c_str());
|
unsigned frequency = atoi(fPlot.first.c_str());
|
||||||
if (frequency) // something to plot
|
if (frequency) // something to plot
|
||||||
{
|
{
|
||||||
unsigned nbPlot = fPlot.second.size();
|
unsigned nbPlot = fPlot.second.size();
|
||||||
if ( nbPlot % 2 ) // odd!
|
if ( nbPlot % 2 ) // odd!
|
||||||
throw std::runtime_error("Odd number of front description in make_checkpoint_pareto");
|
throw std::runtime_error("Odd number of front description in make_checkpoint_pareto");
|
||||||
|
|
||||||
|
|
@ -124,32 +120,18 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
|
||||||
unsigned obj2 = atoi(fPlot.second[i+1].c_str());
|
unsigned obj2 = atoi(fPlot.second[i+1].c_str());
|
||||||
eoMOFitnessStat<EOT>* fStat;
|
eoMOFitnessStat<EOT>* fStat;
|
||||||
if (!bStat[obj1]) { // not already there: create it
|
if (!bStat[obj1]) { // not already there: create it
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "Obj. " << obj1 << std::ends;
|
os << "Obj. " << obj1 << std::ends;
|
||||||
fStat = new eoMOFitnessStat<EOT>(obj1, os.str().c_str());
|
fStat = new eoMOFitnessStat<EOT>(obj1, os.str().c_str());
|
||||||
#else
|
|
||||||
char s[1024];
|
|
||||||
std::ostrstream os(s, 1022);
|
|
||||||
os << "Obj. " << obj1 << std::ends;
|
|
||||||
fStat = new eoMOFitnessStat<EOT>(obj1, s);
|
|
||||||
#endif
|
|
||||||
_state.storeFunctor(fStat);
|
_state.storeFunctor(fStat);
|
||||||
bStat[obj1]=true;
|
bStat[obj1]=true;
|
||||||
theStats[obj1]=fStat;
|
theStats[obj1]=fStat;
|
||||||
checkpoint.add(*fStat);
|
checkpoint.add(*fStat);
|
||||||
}
|
}
|
||||||
if (!bStat[obj2]) { // not already there: create it
|
if (!bStat[obj2]) { // not already there: create it
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "Obj. " << obj2 << std::ends;
|
os << "Obj. " << obj2 << std::ends;
|
||||||
fStat = new eoMOFitnessStat<EOT>(obj2, os.str().c_str());
|
fStat = new eoMOFitnessStat<EOT>(obj2, os.str().c_str());
|
||||||
#else
|
|
||||||
char s[1024];
|
|
||||||
std::ostrstream os2(s, 1022);
|
|
||||||
os2 << "Obj. " << obj2 << std::ends;
|
|
||||||
fStat = new eoMOFitnessStat<EOT>(obj2, s);
|
|
||||||
#endif
|
|
||||||
_state.storeFunctor(fStat);
|
_state.storeFunctor(fStat);
|
||||||
bStat[obj2]=true;
|
bStat[obj2]=true;
|
||||||
theStats[obj2]=fStat;
|
theStats[obj2]=fStat;
|
||||||
|
|
@ -157,26 +139,18 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
|
||||||
}
|
}
|
||||||
|
|
||||||
// then the fileSnapshots
|
// then the fileSnapshots
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "Front." << obj1 << "." << obj2 << "." << std::ends;
|
os << "Front." << obj1 << "." << obj2 << "." << std::ends;
|
||||||
eoFileSnapshot& snapshot = _state.storeFunctor(
|
eoFileSnapshot& snapshot = _state.storeFunctor(
|
||||||
new eoFileSnapshot(dirName, frequency, os.str().c_str()));
|
new eoFileSnapshot(dirName, frequency, os.str().c_str()));
|
||||||
#else
|
|
||||||
char s3[1024];
|
|
||||||
std::ostrstream os3(s3, 1022);
|
|
||||||
os3 << "Front." << obj1 << "." << obj2 << "." << std::ends;
|
|
||||||
eoFileSnapshot & snapshot = _state.storeFunctor(
|
|
||||||
new eoFileSnapshot(dirName, frequency, s3 ) );
|
|
||||||
#endif
|
|
||||||
checkpoint.add(snapshot);
|
checkpoint.add(snapshot);
|
||||||
|
|
||||||
snapshot.add(*theStats[obj1]);
|
snapshot.add(*theStats[obj1]);
|
||||||
snapshot.add(*theStats[obj2]);
|
snapshot.add(*theStats[obj2]);
|
||||||
|
|
||||||
// and create the gnuplotter from the fileSnapshot
|
// and create the gnuplotter from the fileSnapshot
|
||||||
#if !defined(NO_GNUPLOT)
|
#if !defined(NO_GNUPLOT)
|
||||||
if (boolGnuplot)
|
if (boolGnuplot)
|
||||||
{
|
{
|
||||||
eoGnuplot1DSnapshot & plotSnapshot = _state.storeFunctor(new
|
eoGnuplot1DSnapshot & plotSnapshot = _state.storeFunctor(new
|
||||||
eoGnuplot1DSnapshot(snapshot));
|
eoGnuplot1DSnapshot(snapshot));
|
||||||
|
|
@ -204,8 +178,8 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
|
||||||
// do we want an eoStdoutMonitor?
|
// do we want an eoStdoutMonitor?
|
||||||
bool needStdoutMonitor = printPop ; // only this one at the moment
|
bool needStdoutMonitor = printPop ; // only this one at the moment
|
||||||
|
|
||||||
// The Stdout monitor will print parameters to the screen ...
|
// The Stdout monitor will print parameters to the screen ...
|
||||||
if ( needStdoutMonitor )
|
if ( needStdoutMonitor )
|
||||||
{
|
{
|
||||||
eoStdoutMonitor & monitor = _state.storeFunctor(new eoStdoutMonitor(false));
|
eoStdoutMonitor & monitor = _state.storeFunctor(new eoStdoutMonitor(false));
|
||||||
|
|
||||||
|
|
@ -241,12 +215,12 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
|
||||||
#else
|
#else
|
||||||
std::string stmp = dirName + "/generations";
|
std::string stmp = dirName + "/generations";
|
||||||
#endif
|
#endif
|
||||||
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
|
eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp);
|
||||||
_state.storeFunctor(stateSaver1);
|
_state.storeFunctor(stateSaver1);
|
||||||
checkpoint.add(*stateSaver1);
|
checkpoint.add(*stateSaver1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// save state every T seconds
|
// save state every T seconds
|
||||||
eoValueParam<unsigned>& saveTimeIntervalParam = _parser.createParam(unsigned(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" );
|
eoValueParam<unsigned>& saveTimeIntervalParam = _parser.createParam(unsigned(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" );
|
||||||
if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0)
|
if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0)
|
||||||
{
|
{
|
||||||
|
|
@ -259,7 +233,7 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
|
||||||
#else
|
#else
|
||||||
std::string stmp = dirName + "/time";
|
std::string stmp = dirName + "/time";
|
||||||
#endif
|
#endif
|
||||||
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
|
eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp);
|
||||||
_state.storeFunctor(stateSaver2);
|
_state.storeFunctor(stateSaver2);
|
||||||
checkpoint.add(*stateSaver2);
|
checkpoint.add(*stateSaver2);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,13 @@
|
||||||
#define eoSequential_h
|
#define eoSequential_h
|
||||||
|
|
||||||
/** Contains the following classes:
|
/** Contains the following classes:
|
||||||
* - eoSequentialSelect, returns all individuals one by one,
|
* - eoSequentialSelect, returns all individuals one by one,
|
||||||
* either sorted or shuffled
|
* either sorted or shuffled
|
||||||
* - eoEliteSequentialSelect, returns all indivisuals one by one
|
* - eoEliteSequentialSelect, returns all indivisuals one by one
|
||||||
* starting with best, continuing shuffled (see G3 engine)
|
* starting with best, continuing shuffled (see G3 engine)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <utils/eoData.h>
|
||||||
#include <utils/eoRNG.h>
|
#include <utils/eoRNG.h>
|
||||||
#include <eoSelectOne.h>
|
#include <eoSelectOne.h>
|
||||||
|
|
||||||
|
|
@ -129,7 +130,7 @@ template <class EOT> class eoEliteSequentialSelect: public eoSelectOne<EOT>
|
||||||
const EOT *ptmp = eoPters[0];
|
const EOT *ptmp = eoPters[0];
|
||||||
eoPters[0]=best;
|
eoPters[0]=best;
|
||||||
eoPters[ibest] = ptmp;
|
eoPters[ibest] = ptmp;
|
||||||
// exit after setting current
|
// exit after setting current
|
||||||
current=0;
|
current=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoVariableLengthCrossover.h
|
// eoVariableLengthCrossover.h
|
||||||
// (c) GeNeura Team, 2000 - EEAAX 1999 - Maarten Keijzer 2000
|
// (c) GeNeura Team, 2000 - EEAAX 1999 - Maarten Keijzer 2000
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
|
|
@ -55,7 +55,7 @@ public:
|
||||||
eoUniformAtomExchange(double _rate=0.5):rate(_rate){}
|
eoUniformAtomExchange(double _rate=0.5):rate(_rate){}
|
||||||
|
|
||||||
/** randomize: fill the mask: the exchange will be simulated first
|
/** randomize: fill the mask: the exchange will be simulated first
|
||||||
* to see if sizes are OK, so it must be repeatable :
|
* to see if sizes are OK, so it must be repeatable :
|
||||||
* the mask has to be a private data, cannot be computed on the fly
|
* the mask has to be a private data, cannot be computed on the fly
|
||||||
*/
|
*/
|
||||||
void randomize(unsigned _size1, unsigned _size2)
|
void randomize(unsigned _size1, unsigned _size2)
|
||||||
|
|
@ -154,17 +154,10 @@ public :
|
||||||
|
|
||||||
/** the inherited className */
|
/** the inherited className */
|
||||||
virtual std::string className() const
|
virtual std::string className() const
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "eoVlAtomExchangeQuadOp(" << atomExchange.className() << ")";
|
os << "eoVlAtomExchangeQuadOp(" << atomExchange.className() << ")";
|
||||||
return os.str()
|
return os.str()
|
||||||
#else
|
|
||||||
char s[1024];
|
|
||||||
std::ostrstream os(s, 1022);
|
|
||||||
os << "eoVlAtomExchangeQuadOp(" << atomExchange.className() << ")" << std::ends;
|
|
||||||
return std::string(s);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -172,7 +165,7 @@ private:
|
||||||
eoAtomExchange<AtomType> & atomExchange;
|
eoAtomExchange<AtomType> & atomExchange;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Crossover using an AtomCrossover. Probably irrelevant in Variable Length -
|
/** Crossover using an AtomCrossover. Probably irrelevant in Variable Length -
|
||||||
see eoFlOrBinOp.h and eoFlOrQuadOp.h for the similar Fixed Length operators
|
see eoFlOrBinOp.h and eoFlOrQuadOp.h for the similar Fixed Length operators
|
||||||
*/
|
*/
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
|
|
@ -201,7 +194,7 @@ public :
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string className() const
|
virtual std::string className() const
|
||||||
{
|
{
|
||||||
return "eoInnerExchangeQuadOp(" + op.className() + ")";
|
return "eoInnerExchangeQuadOp(" + op.className() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,16 +142,9 @@ public :
|
||||||
|
|
||||||
virtual std::string className() const
|
virtual std::string className() const
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "eoVlDelMutation("<<chooser.className() << ")";
|
os << "eoVlDelMutation("<<chooser.className() << ")";
|
||||||
return os.str();
|
return os.str();
|
||||||
#else
|
|
||||||
char s[1024];
|
|
||||||
std::ostrstream os(s, 1022);
|
|
||||||
os << "eoVlDelMutation(" << chooser.className() << ")" << std::ends;
|
|
||||||
return std::string(s);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; fill-column: 80 -*-
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoEsMutationInit.h
|
// eoEsMutationInit.h
|
||||||
|
|
@ -24,37 +24,48 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _eoEsInit_h
|
#ifndef _eoEsMutationInit_h
|
||||||
#define _eoEsInit_h
|
#define _eoEsMutationInit_h
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <utils/eoParser.h>
|
#include <utils/eoParser.h>
|
||||||
|
|
||||||
/**
|
/** Initialize Mutation operator
|
||||||
\ingroup EvolutionStrategies
|
|
||||||
|
|
||||||
eoESMutationInit. Proxy class that is used for initializing the mutation
|
@ingroup EvolutionStrategies
|
||||||
operator. It provides an interface between eoEsMutate and the abstract
|
|
||||||
parameterLoader. It also provides the names for the parameters in this
|
|
||||||
class as virtual protected member functions.
|
|
||||||
|
|
||||||
If you have more than a single ES in a project that need different
|
Proxy class that is used for initializing the mutation operator. It provides an
|
||||||
names in the configuration files, you might consider overriding this class
|
interface between eoEsMutate and the abstract parameterLoader. It also provides
|
||||||
to change the names.
|
the names for the parameters in this class as virtual protected member
|
||||||
|
functions.
|
||||||
|
|
||||||
@see eoEsMutate
|
If you have more than a single ES in a project that need different names in the
|
||||||
|
configuration files, you might consider overriding this class to change the
|
||||||
|
names.
|
||||||
|
|
||||||
|
@see eoEsMutate
|
||||||
*/
|
*/
|
||||||
class eoEsMutationInit
|
class eoEsMutationInit
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
|
/** Constructor
|
||||||
|
|
||||||
|
@param _parser Parser to read parameters from.
|
||||||
|
@param _section Parser section for \tau-parameters.
|
||||||
|
*/
|
||||||
eoEsMutationInit(eoParser& _parser,
|
eoEsMutationInit(eoParser& _parser,
|
||||||
std::string _section="ES mutation parameters" ) :
|
std::string _section="ES mutation parameters" ) :
|
||||||
parser(_parser), repSection(_section),
|
parser(_parser), repSection(_section),
|
||||||
TauLclParam(0), TauGlbParam(0), TauBetaParam(0) {}
|
TauLclParam(0), TauGlbParam(0), TauBetaParam(0) {}
|
||||||
|
|
||||||
// because we have virtual function - size
|
/** Virtual destructor */
|
||||||
virtual ~eoEsMutationInit(){}
|
virtual ~eoEsMutationInit() {}
|
||||||
|
|
||||||
|
/** local \tau */
|
||||||
double TauLcl(void)
|
double TauLcl(void)
|
||||||
{
|
{
|
||||||
if (TauLclParam == 0)
|
if (TauLclParam == 0)
|
||||||
|
|
@ -63,10 +74,10 @@ class eoEsMutationInit
|
||||||
"Local Tau (before normalization)",
|
"Local Tau (before normalization)",
|
||||||
TauLclShort(), section());
|
TauLclShort(), section());
|
||||||
}
|
}
|
||||||
|
|
||||||
return TauLclParam->value();
|
return TauLclParam->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** global tau */
|
||||||
double TauGlb(void)
|
double TauGlb(void)
|
||||||
{
|
{
|
||||||
if (TauGlbParam == 0)
|
if (TauGlbParam == 0)
|
||||||
|
|
@ -75,10 +86,10 @@ class eoEsMutationInit
|
||||||
"Global Tau (before normalization)",
|
"Global Tau (before normalization)",
|
||||||
TauGlbShort(), section());
|
TauGlbShort(), section());
|
||||||
}
|
}
|
||||||
|
|
||||||
return TauGlbParam->value();
|
return TauGlbParam->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** correlation's tau */
|
||||||
double TauBeta(void)
|
double TauBeta(void)
|
||||||
{
|
{
|
||||||
if (TauBetaParam == 0)
|
if (TauBetaParam == 0)
|
||||||
|
|
@ -86,14 +97,12 @@ class eoEsMutationInit
|
||||||
TauBetaParam = &parser.getORcreateParam(0.0873, TauBetaName(),
|
TauBetaParam = &parser.getORcreateParam(0.0873, TauBetaName(),
|
||||||
"Beta", TauBetaShort(), section());
|
"Beta", TauBetaShort(), section());
|
||||||
}
|
}
|
||||||
|
|
||||||
return TauBetaParam->value();
|
return TauBetaParam->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
virtual std::string section(void)
|
virtual std::string section(void) { return repSection; }
|
||||||
{ return repSection; }
|
|
||||||
|
|
||||||
virtual std::string TauLclName(void) const { return "TauLoc"; }
|
virtual std::string TauLclName(void) const { return "TauLoc"; }
|
||||||
virtual char TauLclShort(void) const { return 'l'; }
|
virtual char TauLclShort(void) const { return 'l'; }
|
||||||
|
|
@ -104,13 +113,13 @@ class eoEsMutationInit
|
||||||
virtual std::string TauBetaName(void) const { return "Beta"; }
|
virtual std::string TauBetaName(void) const { return "Beta"; }
|
||||||
virtual char TauBetaShort(void) const { return 'b'; }
|
virtual char TauBetaShort(void) const { return 'b'; }
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
eoParser& parser;
|
eoParser& parser;
|
||||||
std::string repSection;
|
std::string repSection;
|
||||||
eoValueParam<double>* TauLclParam;
|
eoValueParam<double>* TauLclParam;
|
||||||
eoValueParam<double>* TauGlbParam;
|
eoValueParam<double>* TauGlbParam;
|
||||||
eoValueParam<double>* TauBetaParam;
|
eoValueParam<double>* TauBetaParam;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -27,23 +27,13 @@
|
||||||
#ifndef _make_genotype_h
|
#ifndef _make_genotype_h
|
||||||
#define _make_genotype_h
|
#define _make_genotype_h
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
#include <sstream>
|
|
||||||
#else
|
|
||||||
#include <strstream>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "es/eoReal.h"
|
#include "es/eoReal.h"
|
||||||
#include "es/eoEsChromInit.h"
|
#include "es/eoEsChromInit.h"
|
||||||
#include "utils/eoRealVectorBounds.h"
|
|
||||||
// also need the parser and param includes
|
|
||||||
#include "utils/eoParser.h"
|
#include "utils/eoParser.h"
|
||||||
|
#include "utils/eoRealVectorBounds.h"
|
||||||
#include "utils/eoState.h"
|
#include "utils/eoState.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -102,11 +92,7 @@ eoEsChromInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
|
||||||
to_scale = true;
|
to_scale = true;
|
||||||
sigmaString.resize(pos);
|
sigmaString.resize(pos);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::istringstream is(sigmaString);
|
std::istringstream is(sigmaString);
|
||||||
#else
|
|
||||||
std::istrstream is(sigmaString.c_str());
|
|
||||||
#endif
|
|
||||||
double sigma;
|
double sigma;
|
||||||
is >> sigma;
|
is >> sigma;
|
||||||
// minimum check
|
// minimum check
|
||||||
|
|
|
||||||
|
|
@ -27,33 +27,29 @@
|
||||||
#ifndef eoParseTree_h
|
#ifndef eoParseTree_h
|
||||||
#define eoParseTree_h
|
#define eoParseTree_h
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#include <EO.h>
|
#include <EO.h>
|
||||||
|
#include <eoInit.h>
|
||||||
#include <eoOp.h>
|
#include <eoOp.h>
|
||||||
#include <gp/parse_tree.h>
|
#include <gp/parse_tree.h>
|
||||||
#include <eoInit.h>
|
|
||||||
|
|
||||||
using namespace gp_parse_tree;
|
using namespace gp_parse_tree;
|
||||||
|
|
||||||
/**
|
/** @defgroup ParseTree
|
||||||
\defgroup ParseTree
|
|
||||||
|
|
||||||
Various functions for tree-based Genetic Programming
|
Various functions for tree-based Genetic Programming
|
||||||
*/
|
|
||||||
|
|
||||||
/** eoParseTree : implementation of parse-tree for genetic programming
|
|
||||||
\class eoParseTree eoParseTree.h gp/eoParseTree.h
|
|
||||||
\ingroup ParseTree
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Implementation of parse-tree for genetic programming
|
||||||
|
|
||||||
|
@class eoParseTree eoParseTree.h gp/eoParseTree.h
|
||||||
|
|
||||||
|
@ingroup ParseTree
|
||||||
|
*/
|
||||||
template <class FType, class Node>
|
template <class FType, class Node>
|
||||||
class eoParseTree : public EO<FType>, public parse_tree<Node>
|
class eoParseTree : public EO<FType>, public parse_tree<Node>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
PyEO
|
PyEO
|
||||||
|
|
||||||
Copyright (C) 2003 Maarten Keijzer
|
Copyright (C) 2003 Maarten Keijzer
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
|
@ -18,35 +18,31 @@
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "PyEO.h"
|
#include "PyEO.h"
|
||||||
#include <eoPop.h>
|
#include <eoPop.h>
|
||||||
|
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
#include <sstream>
|
|
||||||
#else
|
|
||||||
#include <strstream>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
//using namespace boost::python;
|
//using namespace boost::python;
|
||||||
|
|
||||||
// static member, needs to be instantiated somewhere
|
// static member, needs to be instantiated somewhere
|
||||||
std::vector<int> PyFitness::objective_info;
|
std::vector<int> PyFitness::objective_info;
|
||||||
|
|
||||||
bool PyFitness::dominates(const PyFitness& oth) const
|
bool PyFitness::dominates(const PyFitness& oth) const
|
||||||
{
|
{
|
||||||
bool dom = false;
|
bool dom = false;
|
||||||
|
|
||||||
for (unsigned i = 0; i < nObjectives(); ++i)
|
for (unsigned i = 0; i < nObjectives(); ++i)
|
||||||
{
|
{
|
||||||
int objective = objective_info[i];
|
int objective = objective_info[i];
|
||||||
|
|
||||||
if (objective == 0) // ignore
|
if (objective == 0) // ignore
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool maxim = objective > 0;
|
bool maxim = objective > 0;
|
||||||
|
|
||||||
double aval = maxim? (*this)[i] : -(*this)[i];
|
double aval = maxim? (*this)[i] : -(*this)[i];
|
||||||
double bval = maxim? oth[i] : -oth[i];
|
double bval = maxim? oth[i] : -oth[i];
|
||||||
|
|
||||||
|
|
@ -103,17 +99,9 @@ struct pyPop_pickle_suite : boost::python::pickle_suite
|
||||||
template <class T>
|
template <class T>
|
||||||
boost::python::str to_string(T& _p)
|
boost::python::str to_string(T& _p)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
_p.printOn(os);
|
_p.printOn(os);
|
||||||
return boost::python::str(os.str().c_str());
|
return boost::python::str(os.str().c_str());
|
||||||
#else
|
|
||||||
std::ostrstream os;
|
|
||||||
_p.printOn(os);
|
|
||||||
os << ends;
|
|
||||||
std::string s(os.str());
|
|
||||||
return boost::python::str(s.c_str());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop_sort(eoPop<PyEO>& pop) { pop.sort(); }
|
void pop_sort(eoPop<PyEO>& pop) { pop.sort(); }
|
||||||
|
|
@ -129,11 +117,11 @@ PyEO& pop_getitem(eoPop<PyEO>& pop, boost::python::object key)
|
||||||
boost::python::extract<int> x(key);
|
boost::python::extract<int> x(key);
|
||||||
if (!x.check())
|
if (!x.check())
|
||||||
throw index_error("Slicing not allowed");
|
throw index_error("Slicing not allowed");
|
||||||
|
|
||||||
int i = x();
|
int i = x();
|
||||||
|
|
||||||
if (static_cast<unsigned>(i) >= pop.size())
|
if (static_cast<unsigned>(i) >= pop.size())
|
||||||
{
|
{
|
||||||
throw index_error("Index out of bounds");
|
throw index_error("Index out of bounds");
|
||||||
}
|
}
|
||||||
return pop[i];
|
return pop[i];
|
||||||
|
|
@ -144,14 +132,14 @@ void pop_setitem(eoPop<PyEO>& pop, boost::python::object key, PyEO& value)
|
||||||
boost::python::extract<int> x(key);
|
boost::python::extract<int> x(key);
|
||||||
if (!x.check())
|
if (!x.check())
|
||||||
throw index_error("Slicing not allowed");
|
throw index_error("Slicing not allowed");
|
||||||
|
|
||||||
int i = x();
|
int i = x();
|
||||||
|
|
||||||
if (static_cast<unsigned>(i) >= pop.size())
|
if (static_cast<unsigned>(i) >= pop.size())
|
||||||
{
|
{
|
||||||
throw index_error("Index out of bounds");
|
throw index_error("Index out of bounds");
|
||||||
}
|
}
|
||||||
|
|
||||||
pop[i] = value;
|
pop[i] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,7 +167,7 @@ BOOST_PYTHON_MODULE(PyEO)
|
||||||
using namespace boost::python;
|
using namespace boost::python;
|
||||||
|
|
||||||
boost::python::register_exception_translator<index_error>(&translate_index_error);
|
boost::python::register_exception_translator<index_error>(&translate_index_error);
|
||||||
|
|
||||||
boost::python::class_<PyEO>("EO")
|
boost::python::class_<PyEO>("EO")
|
||||||
.add_property("fitness", &PyEO::getFitness, &PyEO::setFitness)
|
.add_property("fitness", &PyEO::getFitness, &PyEO::setFitness)
|
||||||
.add_property("genome", &PyEO::getGenome, &PyEO::setGenome)
|
.add_property("genome", &PyEO::getGenome, &PyEO::setGenome)
|
||||||
|
|
@ -204,8 +192,8 @@ BOOST_PYTHON_MODULE(PyEO)
|
||||||
.def_pickle(pyPop_pickle_suite())
|
.def_pickle(pyPop_pickle_suite())
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
// Other definitions in different compilation units,
|
// Other definitions in different compilation units,
|
||||||
// this to avoid having g++ to choke on the load
|
// this to avoid having g++ to choke on the load
|
||||||
random_numbers();
|
random_numbers();
|
||||||
valueParam();
|
valueParam();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
PyEO
|
PyEO
|
||||||
|
|
||||||
Copyright (C) 2003 Maarten Keijzer
|
Copyright (C) 2003 Maarten Keijzer
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
|
@ -24,30 +24,22 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <boost/python.hpp>
|
#include <boost/python.hpp>
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#else
|
|
||||||
#include <strstream>
|
|
||||||
#endif
|
|
||||||
/** Implements pickle support for eoPersistent derivatives */
|
/** Implements pickle support for eoPersistent derivatives */
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct T_pickle_suite : boost::python::pickle_suite
|
struct T_pickle_suite : boost::python::pickle_suite
|
||||||
{
|
{
|
||||||
static
|
static
|
||||||
std::string print_to_string(const T& t)
|
std::string print_to_string(const T& t)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
#else
|
|
||||||
std::ostrstream os;
|
|
||||||
#endif
|
|
||||||
t.printOn(os);
|
t.printOn(os);
|
||||||
os << std::ends;
|
os << std::ends;
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
boost::python::tuple getstate(const T& t)
|
boost::python::tuple getstate(const T& t)
|
||||||
{
|
{
|
||||||
|
|
@ -59,11 +51,7 @@ struct T_pickle_suite : boost::python::pickle_suite
|
||||||
void setstate(T& t, boost::python::tuple pickled)
|
void setstate(T& t, boost::python::tuple pickled)
|
||||||
{
|
{
|
||||||
std::string s = boost::python::extract<std::string>(pickled[0]);
|
std::string s = boost::python::extract<std::string>(pickled[0]);
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::istringstream is(s);
|
std::istringstream is(s);
|
||||||
#else
|
|
||||||
std::istrstream is(s.c_str(), s.size());
|
|
||||||
#endif
|
|
||||||
t.readFrom(is);
|
t.readFrom(is);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
PyEO
|
PyEO
|
||||||
|
|
||||||
Copyright (C) 2003 Maarten Keijzer
|
Copyright (C) 2003 Maarten Keijzer
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
|
@ -23,12 +23,7 @@
|
||||||
|
|
||||||
using namespace boost::python;
|
using namespace boost::python;
|
||||||
|
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#else
|
|
||||||
#include <strstream>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <boost/python/detail/api_placeholder.hpp>
|
#include <boost/python/detail/api_placeholder.hpp>
|
||||||
|
|
||||||
using namespace boost::python;
|
using namespace boost::python;
|
||||||
|
|
@ -43,11 +38,7 @@ double normal(eoRng& rng) { return rng.normal(); }
|
||||||
|
|
||||||
std::string rng_to_string(const eoRng& _rng)
|
std::string rng_to_string(const eoRng& _rng)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
#else
|
|
||||||
std::ostrstream os;
|
|
||||||
#endif
|
|
||||||
_rng.printOn(os);
|
_rng.printOn(os);
|
||||||
os << std::ends;
|
os << std::ends;
|
||||||
return os.str();
|
return os.str();
|
||||||
|
|
@ -56,11 +47,7 @@ std::string rng_to_string(const eoRng& _rng)
|
||||||
|
|
||||||
void rng_from_string(eoRng& _rng, std::string s)
|
void rng_from_string(eoRng& _rng, std::string s)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::istringstream is(s);
|
std::istringstream is(s);
|
||||||
#else
|
|
||||||
std::istrstream is(s.c_str(), s.size());
|
|
||||||
#endif
|
|
||||||
_rng.readFrom(is);
|
_rng.readFrom(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,7 +78,7 @@ int spin(eoRng& _rng, numeric::array values, double total)
|
||||||
}
|
}
|
||||||
|
|
||||||
double chance = _rng.uniform() * total;
|
double chance = _rng.uniform() * total;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (chance >= 0.0)
|
while (chance >= 0.0)
|
||||||
chance -= extract<double>(values[i++]);
|
chance -= extract<double>(values[i++]);
|
||||||
|
|
@ -115,6 +102,6 @@ void random_numbers()
|
||||||
.def("roulette_wheel", spin)
|
.def("roulette_wheel", spin)
|
||||||
.def_pickle(RNG_pickle_suite())
|
.def_pickle(RNG_pickle_suite())
|
||||||
;
|
;
|
||||||
|
|
||||||
def("rng", get_rng, return_value_policy<reference_existing_object>());
|
def("rng", get_rng, return_value_policy<reference_existing_object>());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
## Makefile.am for eo/src/utils
|
## Makefile.am for eo/src/utils
|
||||||
|
|
||||||
lib_LIBRARIES = libeoutils.a
|
lib_LIBRARIES = libeoutils.a
|
||||||
|
|
||||||
libeoutils_a_SOURCES = eoParser.cpp \
|
libeoutils_a_SOURCES = eoData.cpp \
|
||||||
|
eoParser.cpp \
|
||||||
eoRNG.cpp \
|
eoRNG.cpp \
|
||||||
eoState.cpp \
|
eoState.cpp \
|
||||||
eoUpdater.cpp \
|
eoUpdater.cpp \
|
||||||
|
|
@ -12,8 +13,6 @@ libeoutils_a_SOURCES = eoParser.cpp \
|
||||||
eoIntBounds.cpp \
|
eoIntBounds.cpp \
|
||||||
make_help.cpp
|
make_help.cpp
|
||||||
|
|
||||||
AM_CXXFLAGS = -I$(top_srcdir)/src
|
|
||||||
|
|
||||||
utilsincludedir = $(pkgincludedir)/utils
|
utilsincludedir = $(pkgincludedir)/utils
|
||||||
|
|
||||||
utilsinclude_HEADERS = checkpointing \
|
utilsinclude_HEADERS = checkpointing \
|
||||||
|
|
@ -50,3 +49,6 @@ utilsinclude_HEADERS = checkpointing \
|
||||||
pipecom.h \
|
pipecom.h \
|
||||||
rnd_generators.h \
|
rnd_generators.h \
|
||||||
selectors.h
|
selectors.h
|
||||||
|
|
||||||
|
AM_CXXFLAGS = -I$(top_srcdir)/src
|
||||||
|
|
||||||
|
|
|
||||||
30
eo/src/utils/eoData.cpp
Normal file
30
eo/src/utils/eoData.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright (C) 2005 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
|
// Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
// version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along with
|
||||||
|
// this program; see the file License. if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
|
||||||
|
#include "eoData.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_NUMERIC_LIMITS
|
||||||
|
int MAXINT = numeric_limits<int>::max();
|
||||||
|
#else
|
||||||
|
#include <limits.h>
|
||||||
|
int MAXINT = INT_MAX;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// c-file-style: "Stroustrup"
|
||||||
|
// fill-column: 80
|
||||||
|
// End:
|
||||||
|
|
@ -25,61 +25,31 @@
|
||||||
#ifndef EODATA_H
|
#ifndef EODATA_H
|
||||||
#define EODATA_H
|
#define EODATA_H
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
#ifdef MAXINT
|
||||||
|
#undef MAXINT
|
||||||
#include <vector> // std::vector
|
|
||||||
#include <set> // set
|
|
||||||
#include <string> // std::string
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <limits> // MAXDOUBLE
|
|
||||||
#define MAXFLOAT numeric_limits<float>::max()
|
|
||||||
#define MINFLOAT numeric_limits<float>::min()
|
|
||||||
#define MAXDOUBLE numeric_limits<double>::max()
|
|
||||||
#define MAXINT numeric_limits<int>::max()
|
|
||||||
#else
|
|
||||||
#include <float.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
extern int MAXINT;
|
||||||
#if !defined(_WIN32) && !defined(__CYGWIN__) && !(defined(__APPLE__) || defined(MACOSX)) && !defined(__FreeBSD__)
|
|
||||||
#include <values.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// for cygwin and windows (and possibly MacOsX)
|
|
||||||
#ifndef MINFLOAT
|
|
||||||
#define MINFLOAT ( (float)1e-127 )
|
|
||||||
#endif
|
|
||||||
#ifndef MAXFLOAT
|
|
||||||
#define MAXFLOAT ( (float)1e127 )
|
|
||||||
#endif
|
|
||||||
#ifndef MAXINT
|
|
||||||
#define MAXINT 2147483647
|
|
||||||
#endif
|
|
||||||
#ifndef MAXDOUBLE
|
|
||||||
#define MAXDOUBLE (double)1.79769313486231570e+308
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#define _isnan isnan
|
#define _isnan isnan
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// some defines to make things easier to get at first sight
|
// some defines to make things easier to get at first sight
|
||||||
|
|
||||||
// tuning the amount of output using a boolean argument:
|
// tuning the amount of output using a boolean argument:
|
||||||
// true should always mean more output
|
// true should always mean more output
|
||||||
#define eo_verbose true
|
#define eo_verbose true
|
||||||
#define eo_no_verbose false
|
#define eo_no_verbose false
|
||||||
// to be used in selection / replacement procedures to indicate whether
|
// to be used in selection / replacement procedures to indicate whether
|
||||||
// the argument (rate, a double) shoudl be treated as a rate (number=rate*popSize)
|
// the argument (rate, a double) shoudl be treated as a rate (number=rate*popSize)
|
||||||
// or as an absolute integer (number=rate regardless of popsize).
|
// or as an absolute integer (number=rate regardless of popsize).
|
||||||
// the default value shoudl ALWAYS be true (eo_as_a_rate).
|
// the default value shoudl ALWAYS be true (eo_as_a_rate).
|
||||||
//
|
//
|
||||||
// this construct is mandatory because in some cases you might not know the
|
// this construct is mandatory because in some cases you might not know the
|
||||||
// population size that will enter the replacement for instance - so you
|
// population size that will enter the replacement for instance - so you
|
||||||
// cannot simply have a pre-computed (double) rate of 1/popSize
|
// cannot simply have a pre-computed (double) rate of 1/popSize
|
||||||
#define eo_is_a_rate true
|
#define eo_is_a_rate true
|
||||||
#define eo_is_an_integer false
|
#define eo_is_an_integer false
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoFileSnapshot.h
|
// eoFileSnapshot.h
|
||||||
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2001
|
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2001
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
|
|
@ -27,10 +27,6 @@
|
||||||
#ifndef _eoFileSnapshot_h
|
#ifndef _eoFileSnapshot_h
|
||||||
#define _eoFileSnapshot_h
|
#define _eoFileSnapshot_h
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <utils/eoParam.h>
|
#include <utils/eoParam.h>
|
||||||
|
|
@ -39,15 +35,15 @@
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Prints snapshots of fitnesses to a (new) file every N generations
|
Prints snapshots of fitnesses to a (new) file every N generations
|
||||||
|
|
||||||
Assumes that the parameters that are passed to the monitor
|
Assumes that the parameters that are passed to the monitor
|
||||||
(method add in eoMonitor.h) are eoValueParam<std::vector<double> > of same size.
|
(method add in eoMonitor.h) are eoValueParam<std::vector<double> > of same size.
|
||||||
|
|
||||||
A dir is created and one file per snapshot is created there -
|
A dir is created and one file per snapshot is created there -
|
||||||
so you can later generate a movie!
|
so you can later generate a movie!
|
||||||
|
|
||||||
TODO: The counter is handled internally, but this should be changed
|
TODO: The counter is handled internally, but this should be changed
|
||||||
so that you can pass e.g. an evalcounter (minor)
|
so that you can pass e.g. an evalcounter (minor)
|
||||||
|
|
||||||
I failed to templatize everything so that it can handle eoParam<std::vector<T> >
|
I failed to templatize everything so that it can handle eoParam<std::vector<T> >
|
||||||
|
|
@ -103,17 +99,9 @@ public :
|
||||||
*/
|
*/
|
||||||
void setCurrentFileName()
|
void setCurrentFileName()
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SSTREAM
|
std::ostringstream oscount;
|
||||||
std::ostringstream oscount;
|
oscount << counter;
|
||||||
oscount << counter;
|
currentFileName = dirname + "/" + filename + oscount.str();
|
||||||
#else
|
|
||||||
char buff[255];
|
|
||||||
std::ostrstream oscount(buff, 254);
|
|
||||||
oscount << counter;
|
|
||||||
oscount << std::ends;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
currentFileName = dirname + "/" + filename + oscount.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The operator(void): opens the std::ostream and calls the write method
|
/** The operator(void): opens the std::ostream and calls the write method
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoGnuplot1DMonitor.h
|
// eoGnuplot1DMonitor.h
|
||||||
// (c) Marc Schoenauer, 2001
|
// (c) Marc Schoenauer, 2001
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
|
|
@ -26,10 +26,6 @@
|
||||||
#ifndef _eoGnuplot_H
|
#ifndef _eoGnuplot_H
|
||||||
#define _eoGnuplot_H
|
#define _eoGnuplot_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -52,13 +48,13 @@ class eoGnuplot
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Ctor
|
// Ctor
|
||||||
eoGnuplot(std::string _title, std::string _extra = std::string("")) :
|
eoGnuplot(std::string _title, std::string _extra = std::string("")) :
|
||||||
firstTime(true)
|
firstTime(true)
|
||||||
{
|
{
|
||||||
// opens pipe with Gnuplot
|
// opens pipe with Gnuplot
|
||||||
initGnuPlot(_title, _extra);
|
initGnuPlot(_title, _extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dtor
|
// Dtor
|
||||||
virtual ~eoGnuplot() {
|
virtual ~eoGnuplot() {
|
||||||
// close - the gnuplot windows if pipe was correctly opened
|
// close - the gnuplot windows if pipe was correctly opened
|
||||||
|
|
@ -109,24 +105,13 @@ private:
|
||||||
inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
|
inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
|
||||||
/////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "250x150-0+" << numWindow*170;
|
os << "250x150-0+" << numWindow*170;
|
||||||
#else
|
|
||||||
char snum[255];
|
|
||||||
std::ostrstream os(snum, 254);
|
|
||||||
os << "250x150-0+" << numWindow*170 << std::ends;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
numWindow++;
|
numWindow++;
|
||||||
char *args[6];
|
char *args[6];
|
||||||
args[0] = strdup( "gnuplot" );
|
args[0] = strdup( "gnuplot" );
|
||||||
args[1] = strdup( "-geometry" );
|
args[1] = strdup( "-geometry" );
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
args[2] = strdup( os.str().c_str());
|
args[2] = strdup( os.str().c_str());
|
||||||
#else
|
|
||||||
args[2] = strdup( os.str() );
|
|
||||||
#endif
|
|
||||||
args[3] = strdup( "-title" );
|
args[3] = strdup( "-title" );
|
||||||
args[4] = strdup( _title.c_str() );
|
args[4] = strdup( _title.c_str() );
|
||||||
args[5] = 0;
|
args[5] = 0;
|
||||||
|
|
@ -154,7 +139,7 @@ inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
|
||||||
* Created......: Mon Mar 13 13:50:11 1995
|
* Created......: Mon Mar 13 13:50:11 1995
|
||||||
* Description..: Communication par pipe bidirectionnel avec un autre process
|
* Description..: Communication par pipe bidirectionnel avec un autre process
|
||||||
*
|
*
|
||||||
* Ident........: $Id: eoGnuplot.h,v 1.12 2005-09-07 17:09:19 maartenkeijzer Exp $
|
* Ident........: $Id: eoGnuplot.h,v 1.13 2005-09-28 21:49:26 kuepper Exp $
|
||||||
* ----------------------------------------------------------------------
|
* ----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoGnuplot1DMonitor.h
|
// eoGnuplot1DMonitor.h
|
||||||
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
|
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
|
|
@ -28,10 +28,6 @@
|
||||||
#ifndef _eoGnuplot1DMonitor_H
|
#ifndef _eoGnuplot1DMonitor_H
|
||||||
#define _eoGnuplot1DMonitor_H
|
#define _eoGnuplot1DMonitor_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <utils/eoMonitor.h>
|
#include <utils/eoMonitor.h>
|
||||||
|
|
@ -93,10 +89,10 @@ inline eoMonitor& eoGnuplot1DMonitor::operator() (void)
|
||||||
FirstPlot();
|
FirstPlot();
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( gpCom ) {
|
if( gpCom ) {
|
||||||
PipeComSend( gpCom, "replot\n" );
|
PipeComSend( gpCom, "replot\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
|
|
@ -110,13 +106,7 @@ inline void eoGnuplot1DMonitor::FirstPlot()
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Must have some stats to plot!\n");
|
throw std::runtime_error("Must have some stats to plot!\n");
|
||||||
}
|
}
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
#else
|
|
||||||
char buff[1024];
|
|
||||||
std::ostrstream os(buff, 1024);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
os << "plot";
|
os << "plot";
|
||||||
for (unsigned i=1; i<vec.size(); i++) {
|
for (unsigned i=1; i<vec.size(); i++) {
|
||||||
os << " '" << getFileName().c_str() <<
|
os << " '" << getFileName().c_str() <<
|
||||||
|
|
@ -125,12 +115,7 @@ inline void eoGnuplot1DMonitor::FirstPlot()
|
||||||
os << ", ";
|
os << ", ";
|
||||||
}
|
}
|
||||||
os << '\n';
|
os << '\n';
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
PipeComSend( gpCom, os.str().c_str());
|
PipeComSend( gpCom, os.str().c_str());
|
||||||
#else
|
|
||||||
os << std::ends;
|
|
||||||
PipeComSend( gpCom, buff );
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoGnuplot1DSnapshot.h
|
// eoGnuplot1DSnapshot.h
|
||||||
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
|
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
|
|
@ -28,14 +28,8 @@
|
||||||
#ifndef _eoGnuplot1DSnapshot_H
|
#ifndef _eoGnuplot1DSnapshot_H
|
||||||
#define _eoGnuplot1DSnapshot_H
|
#define _eoGnuplot1DSnapshot_H
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#endif
|
#include <string>
|
||||||
|
|
||||||
#include <utils/eoFileSnapshot.h>
|
#include <utils/eoFileSnapshot.h>
|
||||||
#include <utils/eoGnuplot.h>
|
#include <utils/eoGnuplot.h>
|
||||||
|
|
@ -57,7 +51,7 @@ This class plots through gnuplot the eoStat given as argument
|
||||||
|
|
||||||
|
|
||||||
/** eoGnuplot1DSnapshot plots stats through gnuplot
|
/** eoGnuplot1DSnapshot plots stats through gnuplot
|
||||||
* assumes that the same file is re-written every so and so,
|
* assumes that the same file is re-written every so and so,
|
||||||
* and plots it from scratch everytime it's called
|
* and plots it from scratch everytime it's called
|
||||||
*/
|
*/
|
||||||
class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
|
class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
|
||||||
|
|
@ -107,14 +101,8 @@ class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
|
||||||
|
|
||||||
virtual void handleBounds(eoRealVectorBounds & _bounds)
|
virtual void handleBounds(eoRealVectorBounds & _bounds)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
#else
|
// std::ostrstream os;
|
||||||
// use strstream and not std::stringstream until strstream is in all distributions
|
|
||||||
char buf[1024];
|
|
||||||
std::ostrstream os(buf, 1023);
|
|
||||||
#endif
|
|
||||||
// std::ostrstream os;
|
|
||||||
os << "set autoscale\nset yrange [" ;
|
os << "set autoscale\nset yrange [" ;
|
||||||
if (_bounds.isMinBounded(0))
|
if (_bounds.isMinBounded(0))
|
||||||
os << _bounds.minimum(0);
|
os << _bounds.minimum(0);
|
||||||
|
|
@ -140,25 +128,13 @@ inline eoMonitor& eoGnuplot1DSnapshot::operator() (void)
|
||||||
eoFileSnapshot::operator()();
|
eoFileSnapshot::operator()();
|
||||||
|
|
||||||
// sends plot order to gnuplot
|
// sends plot order to gnuplot
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
//std::string buff; // need local memory
|
//std::string buff; // need local memory
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
#else
|
|
||||||
char buff[1024];
|
|
||||||
std::ostrstream os(buff, 1024);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
os << "set title 'Gen. " << getCounter() << "'; plot '"
|
os << "set title 'Gen. " << getCounter() << "'; plot '"
|
||||||
// mk: had to use getFilename().c_str(), because it seems the string(stream) lib is screwed in gcc3.2
|
// mk: had to use getFilename().c_str(), because it seems the string(stream) lib is screwed in gcc3.2
|
||||||
<< getFileName().c_str() << "' notitle with points ps " << pointSize;
|
<< getFileName().c_str() << "' notitle with points ps " << pointSize;
|
||||||
os << std::endl;
|
os << std::endl;
|
||||||
|
|
||||||
#ifdef HAVE_SSTREAM
|
|
||||||
PipeComSend( gpCom, os.str().c_str());
|
PipeComSend( gpCom, os.str().c_str());
|
||||||
#else
|
|
||||||
os << std::ends;
|
|
||||||
PipeComSend( gpCom, buff );
|
|
||||||
#endif
|
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue