* make_genotype_real.h (eoEsChromInit): Rewrite vecSigmaInit-handling:
If sigmaInit is relative (%), do not read vecSigmaInit. Otherwise always use vecSigmaInit with default all values of sigmaInit. * eoParser.h (eoParser::getORcreateParam): Make this a real if-then-else clause around ptParam (found or not). * eoParam.h (eoValueParam::setValue): Document. (eoValueParam<std::vector<double> >::setValue): Allow delimiters ',' and ';'. A plain ' ' does not work, as it is not correctly read by eoParser::readFrom.
This commit is contained in:
parent
20c3369349
commit
d7b935b645
8 changed files with 95 additions and 46 deletions
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
|
||||
|
||||
* Local Variables:
|
||||
* coding: iso-8859-1
|
||||
* mode: flyspell
|
||||
* fill-column: 80
|
||||
* End:
|
||||
15
eo/src/es/ChangeLog
Normal file
15
eo/src/es/ChangeLog
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
2006-11-16 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
||||
|
||||
* make_genotype_real.h (eoEsChromInit): Rewrite vecSigmaInit-handling:
|
||||
If sigmaInit is relative (%), do not read vecSigmaInit. Otherwise
|
||||
always use vecSigmaInit with default all values of sigmaInit.
|
||||
|
||||
* eoEsChromInit.h (class eoEsChromInit): Take const-reference to sigma-vector.
|
||||
|
||||
|
||||
|
||||
* Local Variables:
|
||||
* coding: iso-8859-1
|
||||
* mode: flyspell
|
||||
* fill-column: 80
|
||||
* End:
|
||||
|
|
@ -24,6 +24,7 @@ Contact: http://eodev.sourceforge.net
|
|||
#ifndef _eoEsChromInit_H
|
||||
#define _eoEsChromInit_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -106,9 +107,12 @@ public:
|
|||
@param _bounds bounds for uniform initialization
|
||||
@param _sigma initial value for the stddev
|
||||
*/
|
||||
eoEsChromInit(eoRealVectorBounds& _bounds, std::vector<double> _vecSigma)
|
||||
eoEsChromInit(eoRealVectorBounds& _bounds, const std::vector<double>& _vecSigma)
|
||||
: eoRealInitBounded<EOT>(_bounds), uniqueSigma(_vecSigma[0]), vecSigma(_vecSigma)
|
||||
{}
|
||||
{
|
||||
assert(_bounds.size() == size());
|
||||
assert(_vecSigma.size() == size());
|
||||
}
|
||||
|
||||
|
||||
void operator()(EOT& _eo)
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ It returns an eoInit<EOT> tha can later be used to initialize the population
|
|||
It uses a parser (to get user parameters) and a state (to store the memory) the
|
||||
last argument is to disambiguate the call upon different instanciations.
|
||||
|
||||
WARNING: that last argument will generally be the result of calling the default
|
||||
@warning: that last argument will generally be the result of calling the default
|
||||
ctor of EOT, resulting in most cases in an EOT that is ***not properly
|
||||
initialized***
|
||||
*/
|
||||
|
|
@ -68,7 +68,7 @@ eoEsChromInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
|
|||
eoValueParam<unsigned>& vecSize
|
||||
= _parser.getORcreateParam(unsigned(10), "vecSize",
|
||||
"The number of variables ",
|
||||
'n',"Genotype Initialization");
|
||||
'n', "Genotype Initialization");
|
||||
// to build an eoReal Initializer, we need bounds: [-1,1] by default
|
||||
eoValueParam<eoRealVectorBounds>& boundsParam
|
||||
= _parser.getORcreateParam(eoRealVectorBounds(vecSize.value(), -1, 1),
|
||||
|
|
@ -80,43 +80,30 @@ eoEsChromInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
|
|||
eoValueParam<std::string>& sigmaParam
|
||||
= _parser.getORcreateParam(std::string("0.3"), "sigmaInit",
|
||||
"Initial value for Sigmas (with a '%' -> scaled by the range of each variable)",
|
||||
's',"Genotype Initialization");
|
||||
// check if there is a vecSigmaInit
|
||||
eoParam *vecSigmaParam = _parser.getParamWithLongName("vecSigmaInit");
|
||||
if(vecSigmaParam) {
|
||||
eoValueParam<std::vector<double> >& vecSigmaParam
|
||||
= _parser.getORcreateParam(std::vector<double>(vecSize.value(), 0.3),
|
||||
"vecSigmaInit", "Initial value for Sigma(s)",
|
||||
'V',"Genotype Initialization");
|
||||
init = new eoEsChromInit<EOT>(boundsParam.value(), vecSigmaParam.value());
|
||||
} else {
|
||||
// now some initial value for sigmas - even if useless?
|
||||
// should be used in Normal mutation
|
||||
eoValueParam<std::string>& sigmaParam
|
||||
= _parser.getORcreateParam(std::string("0.3"), "sigmaInit",
|
||||
"Initial value for Sigmas "
|
||||
"(with '%' scaled by the range of each variable)",
|
||||
's',"Genotype Initialization");
|
||||
// check for %
|
||||
bool to_scale = false;
|
||||
size_t pos = sigmaParam.value().find('%');
|
||||
if(pos < sigmaParam.value().size())
|
||||
{
|
||||
// found a % - use scaling and get rid of '%'
|
||||
to_scale = true;
|
||||
sigmaParam.value().resize(pos);
|
||||
}
|
||||
std::istringstream is(sigmaParam.value());
|
||||
double sigma;
|
||||
is >> sigma;
|
||||
// minimum check
|
||||
if(sigma < 0)
|
||||
throw std::runtime_error("Negative sigma in make_genotype");
|
||||
's', "Genotype Initialization");
|
||||
// check for %
|
||||
bool to_scale = false;
|
||||
size_t pos = sigmaParam.value().find('%');
|
||||
if(pos < sigmaParam.value().size()) {
|
||||
// found a % - use scaling and get rid of '%'
|
||||
to_scale = true;
|
||||
sigmaParam.value().resize(pos);
|
||||
}
|
||||
std::istringstream is(sigmaParam.value());
|
||||
double sigma;
|
||||
is >> sigma;
|
||||
// minimum check
|
||||
if(sigma < 0)
|
||||
throw std::runtime_error("Negative sigma in make_genotype");
|
||||
if(to_scale)
|
||||
init = new eoEsChromInit<EOT>(boundsParam.value(), sigma, to_scale);
|
||||
else {
|
||||
// define parameter
|
||||
_parser.getORcreateParam(std::vector<double>(vecSize.value(), 0.3),
|
||||
"vecSigmaInit", "Initial value for Sigma(s)",
|
||||
'V',"Genotype Initialization");
|
||||
eoValueParam<std::vector<double> >& vecSigmaParam
|
||||
= _parser.getORcreateParam(std::vector<double>(vecSize.value(), sigma), "vecSigmaInit",
|
||||
"Initial value for Sigmas (only used when initSigma is not scaled)",
|
||||
'S', "Genotype Initialization");
|
||||
init = new eoEsChromInit<EOT>(boundsParam.value(), vecSigmaParam.value());
|
||||
}
|
||||
// store in state
|
||||
_state.storeFunctor(init);
|
||||
|
|
|
|||
15
eo/src/utils/ChangeLog
Normal file
15
eo/src/utils/ChangeLog
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
2006-11-16 Jochen Küpper <jochen@fhi-berlin.mpg.de>
|
||||
|
||||
* eoParser.h (eoParser::getORcreateParam): Make this a real if-then-else
|
||||
clause around ptParam (found or not).
|
||||
|
||||
* eoParam.h (eoValueParam::setValue): Document.
|
||||
(eoValueParam<std::vector<double> >::setValue): Allow delimiters ',' and
|
||||
';'. A plain ' ' does not work, as it is not correctly read by
|
||||
eoParser::readFrom.
|
||||
|
||||
* Local Variables:
|
||||
* coding: iso-8859-1
|
||||
* mode: flyspell
|
||||
* fill-column: 80
|
||||
* End:
|
||||
|
|
@ -184,6 +184,19 @@ public :
|
|||
}
|
||||
|
||||
|
||||
/** @brief Set value according to the speciied string
|
||||
|
||||
For scalar types the textual represenation is typically quite
|
||||
straigtforward.
|
||||
|
||||
For vector<double> we expect a list of numbers, where the first is
|
||||
an unsigned integer taken as the length ot the vector and then
|
||||
successively the vector elements. Vector elements can be separated
|
||||
by ',', ';', or ' '. Note, however, that eoParser does not deal
|
||||
correctly with parameter values contianing spaces (' ').
|
||||
|
||||
@param _value Textual representation of the new value
|
||||
*/
|
||||
void setValue(const std::string& _value)
|
||||
{
|
||||
std::istringstream is(_value);
|
||||
|
|
@ -290,11 +303,18 @@ inline std::string eoValueParam<std::vector<double> >::getValue(void) const
|
|||
template <>
|
||||
inline void eoValueParam<std::vector<double> >::setValue(const std::string& _value)
|
||||
{
|
||||
static const std::string delimiter(",;");
|
||||
std::istringstream is(_value);
|
||||
unsigned sz;
|
||||
is >> sz;
|
||||
repValue.resize(sz);
|
||||
std::copy(std::istream_iterator<double>(is), std::istream_iterator<double>(), repValue.begin());
|
||||
for(unsigned i=0; i<repValue.size(); ++i) {
|
||||
char c;
|
||||
do {
|
||||
is >> c;
|
||||
} while((std::string::npos != delimiter.find(c)) && (! is.eof()));
|
||||
is >> repValue[i];
|
||||
}
|
||||
}
|
||||
|
||||
// The std::vector<eoMinimizingFitness>
|
||||
|
|
|
|||
|
|
@ -218,7 +218,6 @@ void eoParser::readFrom(istream& is)
|
|||
|
||||
string name(str.begin() + 2, equalLocation);
|
||||
longNameMap[name] = value;
|
||||
|
||||
}
|
||||
else // it should be a char
|
||||
{
|
||||
|
|
|
|||
|
|
@ -180,13 +180,14 @@ public:
|
|||
eoParam* ptParam = getParamWithLongName(_longName);
|
||||
if (ptParam) {
|
||||
// found
|
||||
eoValueParam<ValueType>* ptTypedParam =
|
||||
dynamic_cast<eoValueParam<ValueType>*>(ptParam);
|
||||
eoValueParam<ValueType>* ptTypedParam(
|
||||
dynamic_cast<eoValueParam<ValueType>*>(ptParam));
|
||||
return *ptTypedParam;
|
||||
} else {
|
||||
// not found -> create it
|
||||
return createParam(_defaultValue, _longName, _description,
|
||||
_shortHand, _section, _required);
|
||||
}
|
||||
// not found -> create it
|
||||
return createParam (_defaultValue, _longName, _description,
|
||||
_shortHand, _section, _required);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Reference in a new issue