Extreme cleanup, see src/obsolete for details

This commit is contained in:
mac 2000-08-10 14:18:34 +00:00
commit 6d8e3a6504
141 changed files with 3937 additions and 1815 deletions

View file

@ -7,7 +7,9 @@
INCLUDES = -I$(top_builddir)/src
lib_LIBRARIES = libeoutils.a
libeoutils_a_SOURCES = eoParser.cpp eoRNG.cpp eoState.cpp eoUpdater.cpp eoFileMonitor.cpp
libeoutils_a_SOURCES = eoParser.cpp eoRNG.cpp eoState.cpp eoUpdater.cpp eoFileMonitor.cpp eoStdoutMonitor.cpp
libeoincdir = $(includedir)/eo/utils
libeoinc_HEADERS = compatibility.h eoParam.h eoRNG.h rnd_generators.h eoData.h eoParser.h eoState.h selectors.h eoStat.h eoMonitor.h eoFileMonitor.h eoUpdater.h checkpointing eoCheckPoint.h
libeoinc_HEADERS = compatibility.h eoParam.h eoRNG.h rnd_generators.h eoData.h eoParser.h eoState.h selectors.h eoStat.h eoMonitor.h eoFileMonitor.h eoUpdater.h checkpointing eoCheckPoint.h eoStdoutMonitor.h

View file

@ -2,5 +2,6 @@
#include <utils/eoUpdater.h>
#include <utils/eoMonitor.h>
#include <utils/eoFileMonitor.h>
#include <utils/eoStdoutMonitor.h>
#include <utils/eoCheckPoint.h>
#include <utils/eoStat.h>

View file

@ -27,30 +27,30 @@
#ifndef _eoCheckPoint_h
#define _eoCheckPoint_h
#include <eoTerm.h>
#include <eoContinue.h>
template <class EOT> class eoStatBase;
class eoMonitor;
class eoUpdater;
template <class EOT>
class eoCheckPoint : public eoTerm<EOT>
class eoCheckPoint : public eoContinue<EOT>
{
public :
eoCheckPoint(eoTerm<EOT>& _term) : term(_term) {}
eoCheckPoint(eoContinue<EOT>& _cont) : cont(_cont) {}
bool operator()(const eoPop<EOT>& _pop);
void add(eoStatBase<EOT>& _stat) { stats.push_back(&_stat); }
void add(eoMonitor& _mon) { monitors.push_back(&_mon); }
void add(eoUpdater& _upd) { updaters.push_back(&_upd); }
void add(eoMonitor& _mon) { monitors.push_back(&_mon); }
void add(eoUpdater& _upd) { updaters.push_back(&_upd); }
std::string className(void) const { return "eoCheckPoint"; }
private :
eoTerm<EOT>& term;
eoContinue<EOT>& cont;
std::vector<eoStatBase<EOT>*> stats;
std::vector<eoMonitor*> monitors;
std::vector<eoUpdater*> updaters;
@ -69,7 +69,7 @@ bool eoCheckPoint<EOT>::operator()(const eoPop<EOT>& _pop)
for (i = 0; i < monitors.size(); ++i)
(*monitors[i])();
return term(_pop);
return cont(_pop);
}
#endif

View file

@ -23,13 +23,13 @@ eoMonitor& eoFileMonitor::operator()(void)
throw runtime_error(str);
}
iterator it = begin();
iterator it = vec.begin();
os << (*it)->longName();
++it;
for (; it != end(); ++it)
for (; it != vec.end(); ++it)
{
os << ',' << (*it)->longName();
}
@ -44,11 +44,11 @@ eoMonitor& eoFileMonitor::operator()(void)
throw runtime_error(str);
}
iterator it = begin();
iterator it = vec.begin();
os << '\n' << (*it)->getValue();
for(++it; it != end(); ++it)
for(++it; it != vec.end(); ++it)
{
os << ',' << (*it)->getValue();
}

View file

@ -20,7 +20,7 @@
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
Marc.Schoenauer@polytechnique.fr
mkeijzer@dhi.dk
mak@dhi.dk
*/
//-----------------------------------------------------------------------------
@ -30,6 +30,8 @@
#include <vector>
#include <eoFunctor.h>
class eoParam;
/**
@ -39,16 +41,16 @@ class eoParam;
will stream or pipe the current values of the parameters to wherever you
want it streamed or piped to.
*/
class eoMonitor : public std::vector<const eoParam*>
class eoMonitor : public eoProcedure<eoMonitor&>
{
public :
virtual ~eoMonitor() {}
void add(const eoParam& _param) { vec.push_back(&_param); }
/** Just do it! */
virtual eoMonitor& operator()(void) = 0;
void add(const eoParam& _param) { push_back(&_param); }
protected :
typedef std::vector<const eoParam*>::iterator iterator;
std::vector<const eoParam*> vec;
};
#endif

View file

@ -187,8 +187,10 @@ void eoValueParam<bool>::setValue(std::string _value)
/// Because MSVC does not support partial specialization, the pair is a double, not a T
template <>
std::string eoValueParam<std::pair<double, double> >::getValue(void) const
{
std::ostrstream os;
{
// use own buffer as MSVC's buffer leaks!
char buff[1024];
std::ostrstream os(buff, 1024);
os << repValue.first << ' ' << repValue.second << std::ends;
return os.str();
}

View file

@ -1,5 +1,7 @@
#include <ctime>
#include "eoRNG.h"
/// The global object, should probably be initialized with an xor
/// between time and process_id.
eoRng rng((uint32) time(0));

View file

@ -176,7 +176,15 @@ public :
{
return mean + normal(stdev);
}
/**
Generates random numbers using a negative exponential distribution
*/
double negexp(double mean)
{
return ( -mean*log((double)rand() / rand_max()));
}
/**
rand() returns a random number in the range [0, rand_max)
*/
@ -273,55 +281,6 @@ private :
*/
extern eoRng rng;
/**
The class uniform_generator can be used in the STL generate function
to easily generate random floats and doubles between [0, _max). _max
defaults to 1.0
*/
template <class T = double> class uniform_generator
{
public :
uniform_generator(T _max = T(1.0), eoRng& _rng = rng) : maxim(_max), uniform(_rng) {}
virtual T operator()(void) { return (T) uniform.uniform(maxim); }
private :
T maxim;
eoRng& uniform;
};
/**
The class random_generator can be used in the STL generate function
to easily generate random ints between [0, _max).
*/
template <class T = uint32> class random_generator
{
public :
random_generator(int _max, eoRng& _rng = rng) : maxim(_max), random(_rng) {}
virtual T operator()(void) { return (T) random.random(max); }
private :
T maxim;
eoRng& random;
};
/**
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 normal_generator
{
public :
normal_generator(T _stdev = T(1.0), eoRng& _rng = rng) : stdev(_stdev), normal(_rng) {}
virtual T operator()(void) { return (T) normal.normal(stdev); }
private :
T stdev;
eoRng& normal;
};
// Implementation of some eoRng members.... Don't mind the mess, it does work.

View file

@ -27,11 +27,12 @@
#ifndef _eoStat_h
#define _eoStat_h
#include <eoFunctor.h>
#include <utils/eoParam.h>
#include <eoPop.h>
template <class EOT>
class eoStatBase
class eoStatBase : public eoUnaryFunctor<void, const eoPop<EOT>&>
{
public :
virtual ~eoStatBase(){}
@ -98,7 +99,7 @@ public :
double n = _pop.size();
value().first = result.first / n; // average
value().second = sqrt( (result.second - value().first) / (n - 1.0)); // stdev
value().second = sqrt( (result.second - n * value().first * value().first) / (n - 1.0)); // stdev
}
};

View file

@ -0,0 +1,37 @@
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <utils/eoStdoutMonitor.h>
#include <utils/compatibility.h>
#include <utils/eoParam.h>
using namespace std;
eoMonitor& eoStdoutMonitor::operator()(void)
{
if (firsttime)
{
cout << "First Generation" << endl;
firsttime = false;
}
// ok, now the real saving. write out
if (!cout)
{
string str = "eoStdoutMonitor: Could not write to cout";
throw runtime_error(str);
}
for(iterator it = vec.begin(); it != vec.end(); ++it)
{
cout << (*it)->longName() << ": " << (*it)->getValue() << '\n';
}
cout << "\n****** End of Generation ******\n\n";
return *this;
}

View file

@ -0,0 +1,49 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// eoFileMonitor.h
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 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
mkeijzer@dhi.dk
*/
//-----------------------------------------------------------------------------
#ifndef _eoStdoutMonitor_h
#define _eoStdoutMonitor_h
#include <string>
#include <utils/eoMonitor.h>
#include <eoObject.h>
/**
Prints statistics to stdout
*/
class eoStdoutMonitor : public eoMonitor
{
public :
eoStdoutMonitor(std::string _delim = "\t") : delim(_delim), firsttime(true) {}
eoMonitor& operator()(void);
private :
std::string delim;
bool firsttime;
};
#endif

View file

@ -27,21 +27,15 @@
#ifndef _eoUpdater_h
#define _eoUpdater_h
#include <eoFunctor.h>
#include <utils/eoState.h>
/**
eoUpdater is a generic procudere for updating whatever you want.
It is about as abstract as you can get.
Yet again an empty name
*/
class eoUpdater
{
public :
/// virtual classes have virtual dtors
virtual ~eoUpdater(void) {}
/**
does the work, what it is is quite undefined
*/
virtual void operator()(void) = 0;
};
class eoUpdater : public eoProcedure<void>
{};
/**
*/

View file

@ -43,12 +43,27 @@ template <class T = double> class uniform_generator
public :
uniform_generator(T _max = T(1.0), eoRng& _rng = rng) : maxim(_max), uniform(_rng) {}
virtual T operator()(void) { return (T) uniform.uniform(maxim); }
T operator()(void) { return (T) uniform.uniform(maxim); }
private :
T maxim;
eoRng& uniform;
};
/**
The class boolean_generator can be used in the STL generate function
to easily generate random booleans with a specified bias
*/
class boolean_generator
{
public :
boolean_generator(float _bias = 0.5, eoRng& _rng = rng) : bias(_bias), gen(_rng) {}
bool operator()(void) { return gen.flip(0.5); }
private :
float bias;
eoRng& gen;
};
/**
The class random_generator can be used in the STL generate function
to easily generate random ints between [0, _max).
@ -56,15 +71,23 @@ template <class T = double> class uniform_generator
template <class T = uint32> class random_generator
{
public :
random_generator(int _max, eoRng& _rng = rng) : maxim(_max), random(_rng) {}
random_generator(T _max, eoRng& _rng = rng) : maxim(_max), random(_rng) {}
virtual T operator()(void) { return (T) random.random(max); }
T operator()(void) { return (T) random.random(max); }
private :
T maxim;
eoRng& random;
};
/// Specialization for bool
template <>
bool random_generator<bool>::operator()(void)
{
return random.flip(0.5);
}
/**
The class normal_generator can be used in the STL generate function
to easily generate gaussian distributed floats and doubles. The user
@ -75,11 +98,28 @@ template <class T = double> class normal_generator
public :
normal_generator(T _stdev = T(1.0), eoRng& _rng = rng) : stdev(_stdev), normal(_rng) {}
virtual T operator()(void) { return (T) normal.normal(stdev); }
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 negexp_generator
{
public :
negexp_generator(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