eoVector is back (eoFixedLength and eoVariableLength are gone)
Also: introducing eoRndGenerators.h for eoRndGenerator derived classes: eoNormalGenerator eoUniformGenerator eoBooleanGenerator eoNegExpGenerator Note the suffix that are added to aid in determining what these classes do
This commit is contained in:
parent
e0ace0794f
commit
025eb736ee
19 changed files with 222 additions and 350 deletions
|
|
@ -8,7 +8,7 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <stdlib.h> // exit EXIT_FAILURE
|
#include <stdlib.h> // exit EXIT_FAILURE
|
||||||
#include <eoFixedLength.h> // eoFixedLength
|
#include <eoVector.h> // eoVectorLength
|
||||||
#include <eoOp.h> // eoMonOp eoQuadraticOp
|
#include <eoOp.h> // eoMonOp eoQuadraticOp
|
||||||
#include <eoInit.h> // eoInit
|
#include <eoInit.h> // eoInit
|
||||||
#include <utils/rnd_generators.h> // uniform_generator
|
#include <utils/rnd_generators.h> // uniform_generator
|
||||||
|
|
@ -29,7 +29,7 @@ typedef vector<int> genotype;
|
||||||
// Chrom
|
// Chrom
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
typedef eoFixedLength<phenotype, int> Chrom;
|
typedef eoVector<phenotype, int> Chrom;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoChromEvaluator
|
// eoChromEvaluator
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ lib_LIBRARIES = libeo.a
|
||||||
libeo_a_SOURCES = eoPrintable.cpp eoPersistent.cpp eoFunctorStore.cpp
|
libeo_a_SOURCES = eoPrintable.cpp eoPersistent.cpp eoFunctorStore.cpp
|
||||||
|
|
||||||
libeoincdir = $(includedir)/eo
|
libeoincdir = $(includedir)/eo
|
||||||
libeoinc_HEADERS = eo EO.h apply.h eoAlgo.h eoBreed.h eoCombinedContinue.h eoContinue.h eoCounter.h eoDetSelect.h eoDetTournamentSelect.h eoEasyEA.h eoEvalFunc.h eoEvalFuncPtr.h eoFactory.h eoFitContinue.h eoFitnessScalingSelect.h eoFixedLength.h eoFunctor.h eoFunctorStore.h eoGenContinue.h eoInvalidateOps.h eoInit.h eoMerge.h eoMergeReduce.h eoObject.h eoOp.h eoOpSelMason.h eoPersistent.h eoPop.h eoPrintable.h eoProportionalCombinedOp.h eoProportionalSelect.h eoRandomSelect.h eoRankingSelect.h eoReduce.h eoReduceMerge.h eoReplacement.h eoSGA.h eoSGATransform.h eoScalarFitness.h eoSelect.h eoSelectFactory.h eoSelectMany.h eoSelectNumber.h eoSelectOne.h eoSelectPerc.h eoSteadyFitContinue.h eoStochTournamentSelect.h eoSurviveAndDie.h eoTransform.h eoVariableLength.h eoVariableLengthCrossover.h eoVariableLengthMutation.h eoPerf2Worth.h eoFitnessScalingSelect.h eoLinearFitScaling.h eoRanking.h es.h ga.h
|
libeoinc_HEADERS = eo EO.h apply.h eoAlgo.h eoBreed.h eoCombinedContinue.h eoContinue.h eoCounter.h eoDetSelect.h eoDetTournamentSelect.h eoEasyEA.h eoEvalFunc.h eoEvalFuncPtr.h eoFactory.h eoFitContinue.h eoFitnessScalingSelect.h eoVector.h eoFunctor.h eoFunctorStore.h eoGenContinue.h eoInvalidateOps.h eoInit.h eoMerge.h eoMergeReduce.h eoObject.h eoOp.h eoOpSelMason.h eoPersistent.h eoPop.h eoPrintable.h eoProportionalCombinedOp.h eoProportionalSelect.h eoRandomSelect.h eoRankingSelect.h eoReduce.h eoReduceMerge.h eoReplacement.h eoSGA.h eoSGATransform.h eoScalarFitness.h eoSelect.h eoSelectFactory.h eoSelectMany.h eoSelectNumber.h eoSelectOne.h eoSelectPerc.h eoSteadyFitContinue.h eoStochTournamentSelect.h eoSurviveAndDie.h eoTransform.h eoVariableLengthCrossover.h eoVariableLengthMutation.h eoPerf2Worth.h eoFitnessScalingSelect.h eoLinearFitScaling.h eoRanking.h es.h ga.h
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,7 @@
|
||||||
#include <apply.h>
|
#include <apply.h>
|
||||||
|
|
||||||
// eo's
|
// eo's
|
||||||
#include <eoVariableLength.h>
|
#include <eoVector.h>
|
||||||
#include <eoFixedLength.h>
|
|
||||||
|
|
||||||
#include <other/eoString.h>
|
#include <other/eoString.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,12 @@ It is an eoStat so
|
||||||
|
|
||||||
@see eoSelectFromWorth
|
@see eoSelectFromWorth
|
||||||
*/
|
*/
|
||||||
template <class EOT, class WorthT = double>
|
template <class EOT, class WorthT = typename EOT::Fitness>
|
||||||
class eoPerf2Worth : public eoStat<EOT, vector<WorthT> >
|
class eoPerf2Worth : public eoStat<EOT, vector<WorthT> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
eoPerf2Worth():eoStat<EOT, vector<WorthT> >(vector<WorthT>(0),
|
eoPerf2Worth():eoStat<EOT, vector<WorthT> >(vector<WorthT>(0),
|
||||||
"Worthes") {}
|
"Worths") {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,7 @@
|
||||||
* eoScalarFitness<ScalarType, Compare = less<ScalarType> >:
|
* eoScalarFitness<ScalarType, Compare = less<ScalarType> >:
|
||||||
* Wraps a scalar fitness values such as a double or int, with the option of
|
* Wraps a scalar fitness values such as a double or int, with the option of
|
||||||
* maximizing (using less<ScalarType>) or minimizing (using greater<ScalarType>)
|
* maximizing (using less<ScalarType>) or minimizing (using greater<ScalarType>)
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* It overrides operator<() to use the Compare template argument
|
* It overrides operator<() to use the Compare template argument
|
||||||
*
|
*
|
||||||
* Suitable constructors and assignments and casts are defined to work
|
* Suitable constructors and assignments and casts are defined to work
|
||||||
|
|
|
||||||
|
|
@ -1,104 +0,0 @@
|
||||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// eoVariableLength.h
|
|
||||||
// (c) GeNeura Team, 2000 - EEAAX 1999 - Maarten Keijzer 2000
|
|
||||||
/*
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
|
||||||
Marc.Schoenauer@polytechnique.fr
|
|
||||||
mak@dhi.dk
|
|
||||||
*/
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef _eoVariableLength_h
|
|
||||||
#define _eoVariableLength_h
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
/**
|
|
||||||
Base class for variable length chromosomes. Derives from EO and vector,
|
|
||||||
redirects the smaller than operator to EO (fitness based comparison),
|
|
||||||
and implements the virtual functions printOn() and readFrom()
|
|
||||||
*/
|
|
||||||
|
|
||||||
template <class FitT, class GeneType>
|
|
||||||
class eoVariableLength : public EO<FitT>, public std::vector<GeneType>
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
|
|
||||||
typedef GeneType AtomType;
|
|
||||||
typedef std::vector<GeneType> ContainerType;
|
|
||||||
|
|
||||||
// default ctor
|
|
||||||
eoVariableLength(unsigned size = 0, GeneType value = GeneType()) : EO<FitT>(), std::vector<GeneType>(size, value)
|
|
||||||
{}
|
|
||||||
|
|
||||||
// we can't have a Ctor from a vector, it would create ambiguity
|
|
||||||
// with the copy Ctor
|
|
||||||
void value(std::vector<GeneType> _v)
|
|
||||||
{
|
|
||||||
resize(_v.size());
|
|
||||||
copy(_v.begin(), _v.end(), begin());
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// printing...
|
|
||||||
void printOn(ostream& os) const
|
|
||||||
{
|
|
||||||
EO<FitT>::printOn(os);
|
|
||||||
os << ' ';
|
|
||||||
|
|
||||||
os << size() << ' ';
|
|
||||||
|
|
||||||
std::copy(begin(), end(), ostream_iterator<AtomType>(os, " "));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// reading...
|
|
||||||
void readFrom(istream& is)
|
|
||||||
{
|
|
||||||
EO<FitT>::readFrom(is);
|
|
||||||
|
|
||||||
unsigned sz;
|
|
||||||
is >> sz;
|
|
||||||
|
|
||||||
resize(sz);
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
for (i = 0; i < sz; ++i)
|
|
||||||
{
|
|
||||||
AtomType atom;
|
|
||||||
is >> atom;
|
|
||||||
operator[](i) = atom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// to avoid conflicts between EO::operator< and vector<double>::operator<
|
|
||||||
bool operator<(const eoVariableLength<FitT, GeneType>& _eo) const
|
|
||||||
{
|
|
||||||
return EO<FitT>::operator<(_eo);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/// to avoid conflicts between EO::operator< and vector<GeneType>::operator<
|
|
||||||
template <class FitT, class GeneType>
|
|
||||||
bool operator<(const eoVariableLength<FitT, GeneType>& _eo1, const eoVariableLength<FitT, GeneType>& _eo2)
|
|
||||||
{
|
|
||||||
return _eo1.operator<(_eo2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -28,7 +28,6 @@
|
||||||
#define _eoVariableLengthCrossover_h
|
#define _eoVariableLengthCrossover_h
|
||||||
|
|
||||||
#include <eoFunctor.h>
|
#include <eoFunctor.h>
|
||||||
#include <eoVariableLength.h>
|
|
||||||
#include <eoOp.h>
|
#include <eoOp.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// -*- 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; -*-
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoFixedLength.h
|
// eoVector.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
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _eoFixedLength_h
|
#ifndef _eoVector_h
|
||||||
#define _eoFixedLength_h
|
#define _eoVector_h
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <EO.h>
|
#include <EO.h>
|
||||||
|
|
@ -36,14 +36,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <class FitT, class GeneType>
|
template <class FitT, class GeneType>
|
||||||
class eoFixedLength : public EO<FitT>, public std::vector<GeneType>
|
class eoVector : public EO<FitT>, public std::vector<GeneType>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
typedef GeneType AtomType;
|
typedef GeneType AtomType;
|
||||||
typedef std::vector<GeneType> ContainerType;
|
typedef std::vector<GeneType> ContainerType;
|
||||||
|
|
||||||
eoFixedLength(unsigned size = 0, GeneType value = GeneType()) : EO<FitT>(), std::vector<GeneType>(size, value)
|
eoVector(unsigned size = 0, GeneType value = GeneType()) : EO<FitT>(), std::vector<GeneType>(size, value)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// we can't have a Ctor from a vector, it would create ambiguity
|
// we can't have a Ctor from a vector, it would create ambiguity
|
||||||
|
|
@ -51,13 +51,13 @@ class eoFixedLength : public EO<FitT>, public std::vector<GeneType>
|
||||||
void value(std::vector<GeneType> _v)
|
void value(std::vector<GeneType> _v)
|
||||||
{
|
{
|
||||||
if (_v.size() != size())
|
if (_v.size() != size())
|
||||||
throw runtime_error("Wrong size in vector assignation in eoFixedLength");
|
throw runtime_error("Wrong size in vector assignation in eoVector");
|
||||||
copy(_v.begin(), _v.end(), begin());
|
copy(_v.begin(), _v.end(), begin());
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// to avoid conflicts between EO::operator< and vector<GeneType>::operator<
|
/// to avoid conflicts between EO::operator< and vector<GeneType>::operator<
|
||||||
bool operator<(const eoFixedLength<FitT, GeneType>& _eo) const
|
bool operator<(const eoVector<FitT, GeneType>& _eo) const
|
||||||
{
|
{
|
||||||
return EO<FitT>::operator<(_eo);
|
return EO<FitT>::operator<(_eo);
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +95,7 @@ class eoFixedLength : public EO<FitT>, public std::vector<GeneType>
|
||||||
|
|
||||||
/// to avoid conflicts between EO::operator< and vector<double>::operator<
|
/// to avoid conflicts between EO::operator< and vector<double>::operator<
|
||||||
template <class FitT, class GeneType>
|
template <class FitT, class GeneType>
|
||||||
bool operator<(const eoFixedLength<FitT, GeneType>& _eo1, const eoFixedLength<FitT, GeneType>& _eo2)
|
bool operator<(const eoVector<FitT, GeneType>& _eo1, const eoVector<FitT, GeneType>& _eo2)
|
||||||
{
|
{
|
||||||
return _eo1.operator<(_eo2);
|
return _eo1.operator<(_eo2);
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
#ifndef _eoEsFull_h
|
#ifndef _eoEsFull_h
|
||||||
#define _eoEsFull_h
|
#define _eoEsFull_h
|
||||||
|
|
||||||
#include <eoFixedLength.h>
|
#include <eoVector.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\ingroup EvolutionStrategies
|
\ingroup EvolutionStrategies
|
||||||
|
|
@ -37,18 +37,18 @@ rates and correlated mutations.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <class Fit>
|
template <class Fit>
|
||||||
class eoEsFull : public eoFixedLength<Fit, double>
|
class eoEsFull : public eoVector<Fit, double>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
typedef double Type;
|
typedef double Type;
|
||||||
|
|
||||||
eoEsFull(void) : eoFixedLength<Fit, double>() {}
|
eoEsFull(void) : eoVector<Fit, double>() {}
|
||||||
|
|
||||||
std::string className(void) const { return "eoEsFull"; }
|
std::string className(void) const { return "eoEsFull"; }
|
||||||
|
|
||||||
void printOn(std::ostream& os) const
|
void printOn(std::ostream& os) const
|
||||||
{
|
{
|
||||||
eoFixedLength<Fit,double>::printOn(os);
|
eoVector<Fit,double>::printOn(os);
|
||||||
|
|
||||||
os << ' ';
|
os << ' ';
|
||||||
std::copy(stdevs.begin(), stdevs.end(), std::ostream_iterator<double>(os, " "));
|
std::copy(stdevs.begin(), stdevs.end(), std::ostream_iterator<double>(os, " "));
|
||||||
|
|
@ -62,7 +62,7 @@ class eoEsFull : public eoFixedLength<Fit, double>
|
||||||
|
|
||||||
void readFrom(istream& is)
|
void readFrom(istream& is)
|
||||||
{
|
{
|
||||||
eoFixedLength<Fit,double>::readFrom(is);
|
eoVector<Fit,double>::readFrom(is);
|
||||||
|
|
||||||
stdevs.resize(size());
|
stdevs.resize(size());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
#include <EO.h>
|
#include <EO.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <eoFixedLength.h>
|
#include <eoVector.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\ingroup EvolutionStrategies
|
\ingroup EvolutionStrategies
|
||||||
|
|
@ -44,26 +44,26 @@ see also eoEsStdev eoEsFull
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <class Fit>
|
template <class Fit>
|
||||||
class eoEsSimple : public eoFixedLength<Fit, double>
|
class eoEsSimple : public eoVector<Fit, double>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
typedef double Type;
|
typedef double Type;
|
||||||
|
|
||||||
eoEsSimple(void) : eoFixedLength<Fit, double>() {}
|
eoEsSimple(void) : eoVector<Fit, double>() {}
|
||||||
|
|
||||||
std::string className(void) const { return "eoEsSimple"; }
|
std::string className(void) const { return "eoEsSimple"; }
|
||||||
|
|
||||||
void printOn(std::ostream& os) const
|
void printOn(std::ostream& os) const
|
||||||
{
|
{
|
||||||
eoFixedLength<Fit,double>::printOn(os);
|
eoVector<Fit,double>::printOn(os);
|
||||||
|
|
||||||
os << ' ' << stdev << ' ';
|
os << ' ' << stdev << ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
void readFrom(istream& is)
|
void readFrom(istream& is)
|
||||||
{
|
{
|
||||||
eoFixedLength<Fit,double>::readFrom(is);
|
eoVector<Fit,double>::readFrom(is);
|
||||||
|
|
||||||
is >> stdev;
|
is >> stdev;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
#ifndef _eoEsStdev_h
|
#ifndef _eoEsStdev_h
|
||||||
#define _eoEsStdev_h
|
#define _eoEsStdev_h
|
||||||
|
|
||||||
#include <eoFixedLength.h>
|
#include <eoVector.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\ingroup EvolutionStrategies
|
\ingroup EvolutionStrategies
|
||||||
|
|
@ -37,19 +37,19 @@ deviations.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <class Fit>
|
template <class Fit>
|
||||||
class eoEsStdev : public eoFixedLength<Fit, double>
|
class eoEsStdev : public eoVector<Fit, double>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
typedef double Type;
|
typedef double Type;
|
||||||
|
|
||||||
eoEsStdev(void) : eoFixedLength<Fit, double>() {}
|
eoEsStdev(void) : eoVector<Fit, double>() {}
|
||||||
|
|
||||||
std::string className(void) const { return "eoEsStdev"; }
|
std::string className(void) const { return "eoEsStdev"; }
|
||||||
|
|
||||||
void printOn(std::ostream& os) const
|
void printOn(std::ostream& os) const
|
||||||
{
|
{
|
||||||
eoFixedLength<Fit,double>::printOn(os);
|
eoVector<Fit,double>::printOn(os);
|
||||||
|
|
||||||
os << ' ';
|
os << ' ';
|
||||||
std::copy(stdevs.begin(), stdevs.end(), std::ostream_iterator<double>(os, " "));
|
std::copy(stdevs.begin(), stdevs.end(), std::ostream_iterator<double>(os, " "));
|
||||||
|
|
@ -59,7 +59,7 @@ class eoEsStdev : public eoFixedLength<Fit, double>
|
||||||
|
|
||||||
void readFrom(istream& is)
|
void readFrom(istream& is)
|
||||||
{
|
{
|
||||||
eoFixedLength<Fit,double>::readFrom(is);
|
eoVector<Fit,double>::readFrom(is);
|
||||||
stdevs.resize(size());
|
stdevs.resize(size());
|
||||||
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,12 @@
|
||||||
#include <iostream> // ostream, istream
|
#include <iostream> // ostream, istream
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
|
|
||||||
#include <eoFixedLength.h>
|
#include <eoVector.h>
|
||||||
|
|
||||||
/** eoReal: implementation of simple real-valued chromosome.
|
/** eoReal: implementation of simple real-valued chromosome.
|
||||||
* based on eoFixedLength class
|
* based on eoVector class
|
||||||
*/
|
*/
|
||||||
template <class FitT> class eoReal: public eoFixedLength<FitT, double>
|
template <class FitT> class eoReal: public eoVector<FitT, double>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ template <class FitT> class eoReal: public eoFixedLength<FitT, double>
|
||||||
* @param size Size of the vector
|
* @param size Size of the vector
|
||||||
*/
|
*/
|
||||||
eoReal(unsigned size = 0, double value = 0.0):
|
eoReal(unsigned size = 0, double value = 0.0):
|
||||||
eoFixedLength<FitT, double>(size, value) {}
|
eoVector<FitT, double>(size, value) {}
|
||||||
|
|
||||||
/// My class name.
|
/// My class name.
|
||||||
string className() const
|
string className() const
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
#include <functional> // bind2nd
|
#include <functional> // bind2nd
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
|
|
||||||
#include <eoFixedLength.h>
|
#include <eoVector.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\defgroup bitstring
|
\defgroup bitstring
|
||||||
|
|
@ -52,7 +52,7 @@
|
||||||
\ingroup bitstring
|
\ingroup bitstring
|
||||||
* based on STL's vector<bool> specialization.
|
* based on STL's vector<bool> specialization.
|
||||||
*/
|
*/
|
||||||
template <class FitT> class eoBit: public eoFixedLength<FitT, bool>
|
template <class FitT> class eoBit: public eoVector<FitT, bool>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ template <class FitT> class eoBit: public eoFixedLength<FitT, bool>
|
||||||
* @param size Size of the binary string.
|
* @param size Size of the binary string.
|
||||||
*/
|
*/
|
||||||
eoBit(unsigned size = 0, bool value = false):
|
eoBit(unsigned size = 0, bool value = false):
|
||||||
eoFixedLength<FitT, bool>(size, value) {}
|
eoVector<FitT, bool>(size, value) {}
|
||||||
|
|
||||||
/// My class name.
|
/// My class name.
|
||||||
string className() const
|
string className() const
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ lib_LIBRARIES = libeoutils.a
|
||||||
libeoutils_a_SOURCES = eoParser.cpp eoRNG.cpp eoState.cpp eoUpdater.cpp eoFileMonitor.cpp eoStdoutMonitor.cpp
|
libeoutils_a_SOURCES = eoParser.cpp eoRNG.cpp eoState.cpp eoUpdater.cpp eoFileMonitor.cpp eoStdoutMonitor.cpp
|
||||||
|
|
||||||
libeoincdir = $(includedir)/eo/utils
|
libeoincdir = $(includedir)/eo/utils
|
||||||
libeoinc_HEADERS = compatibility.h eoCheckPoint.h eoData.h eoDistance.h eoFDCStat.h eoFileMonitor.h eoGnuplot1DMonitor.h eoGnuplot1DSnapshot.h eoHowMany.h eoMonitor.h eoParam.h eoParser.h eoRNG.h eoStat.h eoScalarFitnessStat.h eoState.h eoStdoutMonitor.h eoUpdatable.h eoUpdater.h rnd_generators.h selectors.h
|
libeoinc_HEADERS = compatibility.h eoCheckPoint.h eoData.h eoDistance.h eoFDCStat.h eoFileMonitor.h eoGnuplot1DMonitor.h eoGnuplot1DSnapshot.h eoHowMany.h eoMonitor.h eoParam.h eoParser.h eoRNG.h eoStat.h eoScalarFitnessStat.h eoState.h eoStdoutMonitor.h eoUpdatable.h eoUpdater.h rnd_generators.h eoRndGenerators.h selectors.h
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include "eoRNG.h"
|
#include "eoRNG.h"
|
||||||
|
|
||||||
/// The global object, should probably be initialized with an xor
|
|
||||||
/// between time and process_id.
|
|
||||||
namespace eo
|
namespace eo
|
||||||
{
|
{
|
||||||
|
/// The Global random number generator.
|
||||||
eoRng rng((uint32) time(0));
|
eoRng rng((uint32) time(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
eoRnd.h
|
|
||||||
(c) GeNeura Team, 1998
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
|
||||||
*/
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
CVS Info: $Date: 2001-02-13 22:35:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/utils/Attic/eoRnd.h,v 1.1 2001-02-13 22:35:07 jmerelo Exp $ $Author: jmerelo $ $Log$
|
|
||||||
*/
|
|
||||||
#ifndef _EORND_H
|
|
||||||
#define _EORND_H
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#include <eoObject.h>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Class eoRnd
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#include <stdlib.h> // srand
|
|
||||||
#include <time.h> // time
|
|
||||||
#include <stdexcept> // runtime_error
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#include <eoPersistent.h>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* Base class for a family of random 'number' generators. These 'numbers'
|
|
||||||
* can be anything, including full-fledged chromosomes.
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
class eoRnd
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
/** Main function: random generators act as functors, that return random numbers.
|
|
||||||
@return return a random number
|
|
||||||
*/
|
|
||||||
virtual T operator()() = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
149
eo/src/utils/eoRndGenerators.h
Normal file
149
eo/src/utils/eoRndGenerators.h
Normal file
|
|
@ -0,0 +1,149 @@
|
||||||
|
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
eoRndGenerators.h
|
||||||
|
|
||||||
|
mimics the rnd_generator.h by putting the generators in the EO-hierarchy
|
||||||
|
|
||||||
|
(c) Maarten Keijzer (mak@dhi.dk) and GeNeura Team, 1999, 2000
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library 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
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
|
*/
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef eoRND_GENERATORS_H
|
||||||
|
#define eoRND_GENERATORS_H
|
||||||
|
|
||||||
|
#include "eoRNG.h"
|
||||||
|
#include <eoFunctor.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
/**
|
||||||
|
By popular demand re-introducing a base class for a family of
|
||||||
|
random number generators. Derived members of this class are useful
|
||||||
|
to initialize fixed/variable length genotypes that have an 'atomic' type
|
||||||
|
in an indepent way (thus without employing any knowledge abou the problem domain).
|
||||||
|
|
||||||
|
The only change from previous EO's us the use of the suffix EO. This to
|
||||||
|
|
||||||
|
See derived classes eoUniformGenerator, eoBooleanGenerator, eoNormalGenerator and eoNegExpGenerator
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
class eoRndGenerator : public eoF<T>
|
||||||
|
{
|
||||||
|
typedef T AtomType;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
The class eoUniform can be used in the STL generate function
|
||||||
|
to easily generate random floats and doubles. It can also
|
||||||
|
be used for ints and unsigneds by virtue of the static_cast
|
||||||
|
in the generator function.
|
||||||
|
|
||||||
|
Also present is a specialization for boolean, that will
|
||||||
|
ignore the minima and maxima that are possibly set and will
|
||||||
|
return an unbiased flip of a coin. For a biased flip, use the eoBoolean
|
||||||
|
|
||||||
|
either in [0, _max) if only 1 value (_max) is given
|
||||||
|
(or none, as _max defaults to 1.0)
|
||||||
|
or in [_min,_max) if 2 values are given (_min, _max)
|
||||||
|
*/
|
||||||
|
template <class T = double> class eoUniformGenerator : public eoRndGenerator<T>
|
||||||
|
{
|
||||||
|
// added new ctor with 2 params, and modified the data to minim and range
|
||||||
|
// (was maxim only). MS 3/11/2000
|
||||||
|
public :
|
||||||
|
eoUniformGenerator(T _max = T(1.0), eoRng& _rng = rng) :
|
||||||
|
minim(T(0.0)), range(_max), uniform(_rng) {}
|
||||||
|
eoUniformGenerator(T _min, T _max, eoRng& _rng = rng) :
|
||||||
|
minim(_min), range(_max-_min), uniform(_rng)
|
||||||
|
{
|
||||||
|
if (_min>_max)
|
||||||
|
throw logic_error("Min is greater than Max in uniform_generator");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Generates the number, uses a static_cast to get the right behaviour
|
||||||
|
for ints and unsigneds
|
||||||
|
*/
|
||||||
|
T operator()(void) { return minim+static_cast<T>(uniform.uniform(range)); }
|
||||||
|
|
||||||
|
private :
|
||||||
|
T minim;
|
||||||
|
T range;
|
||||||
|
eoRng& uniform;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// Specialization for bool, does an unbiased coin flip
|
||||||
|
template <>
|
||||||
|
bool eoUniformGenerator<bool>::operator()(void)
|
||||||
|
{
|
||||||
|
return uniform.flip(0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
The class eoBooleanGenerator can be used in the STL generate function
|
||||||
|
to easily generate random booleans with a specified bias
|
||||||
|
*/
|
||||||
|
class eoBooleanGenerator : public eoRndGenerator<bool>
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
eoBooleanGenerator(float _bias = 0.5, eoRng& _rng = rng) : bias(_bias), gen(_rng) {}
|
||||||
|
|
||||||
|
bool operator()(void) { return gen.flip(bias); }
|
||||||
|
private :
|
||||||
|
float bias;
|
||||||
|
eoRng& gen;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
The class normal_generator can be used in the STL generate function
|
||||||
|
to easily generate gaussian distributed floats and doubles. The user
|
||||||
|
can supply a standard deviation which defaults to 1.
|
||||||
|
*/
|
||||||
|
template <class T = double> class eoNormalGenerator : public eoRndGenerator<T>
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
eoNormalGenerator(T _stdev = T(1.0), eoRng& _rng = rng) : stdev(_stdev), normal(_rng) {}
|
||||||
|
|
||||||
|
T operator()(void) { return (T) normal.normal(stdev); }
|
||||||
|
|
||||||
|
private :
|
||||||
|
T stdev;
|
||||||
|
eoRng& normal;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
The class negexp_generator can be used in the STL generate function
|
||||||
|
to easily generate negative exponential distributed floats and doubles. The user
|
||||||
|
can supply a mean.
|
||||||
|
*/
|
||||||
|
template <class T = double> class eoNegExpGenerator : public eoRndGenerator<T>
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
eoNegExpGenerator(T _mean = 1.0, eoRng& _rng = rng) : mean(_mean), negexp(_rng) {}
|
||||||
|
|
||||||
|
T operator()(void) { return (T) negexp.negexp(mean); }
|
||||||
|
|
||||||
|
private :
|
||||||
|
T mean;
|
||||||
|
eoRng& negexp;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -1,104 +0,0 @@
|
||||||
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
eoUniform.h
|
|
||||||
Uniform random number generator;
|
|
||||||
(c) GeNeura Team, 1998
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
CVS Info: $Date: 2001-02-13 22:35:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/utils/Attic/eoUniform.h,v 1.1 2001-02-13 22:35:07 jmerelo Exp $ $Author: jmerelo $ $Log$
|
|
||||||
*/
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef _EOUNIFORM_H
|
|
||||||
#define _EOUNIFORM_H
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#include <utils/eoRnd.h>
|
|
||||||
#include <utils/eoRNG.h>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Class eoUniform
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Generates uniform random number over the interval [min, max)
|
|
||||||
Uses the global variable rng
|
|
||||||
*/
|
|
||||||
|
|
||||||
using eo::rng;
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
class eoUniform: public eoRnd<T>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Default constructor.
|
|
||||||
* @param _min The minimum value in the interval.
|
|
||||||
* @param _max The maximum value in the interval.
|
|
||||||
*/
|
|
||||||
eoUniform(T _min = 0, T _max = 1)
|
|
||||||
: eoRnd<T>(), min(_min), diff(_max - _min) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* copy constructor.
|
|
||||||
* @param _rnd the other rnd
|
|
||||||
*/
|
|
||||||
eoUniform( const eoUniform& _rnd)
|
|
||||||
: eoRnd<T>( _rnd), min(_rnd.min), diff(_rnd.diff) {}
|
|
||||||
|
|
||||||
/** Returns an uniform random number over the interval [min, max)
|
|
||||||
Uses global rng object */
|
|
||||||
virtual T operator()() {
|
|
||||||
return min + T( rng.uniform( diff ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
T min;
|
|
||||||
double diff;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
class eoUniform<bool>: public eoRnd<bool>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Default constructor.
|
|
||||||
* @param _min The minimum value in the interval.
|
|
||||||
* @param _max The maximum value in the interval.
|
|
||||||
*/
|
|
||||||
eoUniform(bool _min = false, bool _max = true)
|
|
||||||
: eoRnd<bool>() {}
|
|
||||||
|
|
||||||
/** Returns an uniform random number over the interval [min, max)
|
|
||||||
Uses global rng object */
|
|
||||||
virtual bool operator()() {
|
|
||||||
return rng.flip(0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool min;
|
|
||||||
double diff;
|
|
||||||
};
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -24,23 +24,23 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
CVS Info: $Date: 2001-02-13 22:39:56 $ $Author: jmerelo $ $Revision: 1.7 $
|
CVS Info: $Date: 2001-02-17 10:51:31 $ $Author: maartenkeijzer $ $Revision: 1.8 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <iostream> // cout
|
#include <iostream> // cout
|
||||||
#include <strstream> // ostrstream, istrstream
|
#include <strstream> // ostrstream, istrstream
|
||||||
#include <utils/eoUniform.h> // eoBin
|
#include <utils/eoRndGenerators.h> // eoBin
|
||||||
//#include <eoNormal.h>
|
//#include <eoNormal.h>
|
||||||
//#include <eoNegExp.h>
|
//#include <eoNegExp.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
eoUniform<float> u1(-2.5,3.5);
|
eoUniformGenerator<float> u1(-2.5,3.5);
|
||||||
eoUniform<double> u2(0.003, 0.0005 );
|
eoUniformGenerator<double> u2(0.003, 0.0005 );
|
||||||
eoUniform<unsigned long> u3( 10000000U, 10000U);
|
eoUniformGenerator<unsigned long> u3( 10000000U, 10000U);
|
||||||
/* eoNegExp<float> e1(3.5);
|
/* eoNegExp<float> e1(3.5);
|
||||||
eoNegExp<double> e2(0.003 );
|
eoNegExp<double> e2(0.003 );
|
||||||
eoNegExp<long> e3( 10000U);
|
eoNegExp<long> e3( 10000U);
|
||||||
|
|
|
||||||
Reference in a new issue