* indentations + whitespace cleanup
This commit is contained in:
parent
8457e39efe
commit
56c6edab04
285 changed files with 6068 additions and 6223 deletions
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/*
|
||||
* C++ification of Nikolaus Hansen's original C-source code for the
|
||||
* CMA-ES
|
||||
|
|
@ -7,7 +6,7 @@
|
|||
* the LGPL. Original copyright of Nikolaus Hansen can be found below
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------- */
|
||||
|
|
@ -30,7 +29,7 @@
|
|||
* 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.
|
||||
*
|
||||
*
|
||||
* */
|
||||
/* --- Changes : ---
|
||||
* 03/03/21: argument const double *rgFunVal of
|
||||
|
|
@ -54,138 +53,138 @@ using namespace std;
|
|||
namespace eo {
|
||||
|
||||
CMAParams::CMAParams(eoParser& parser, unsigned dimensionality) {
|
||||
|
||||
|
||||
string section = "CMA parameters";
|
||||
|
||||
|
||||
n = parser.createParam(dimensionality, "dimensionality", "Dimensionality (N) of the problem", 'N', section, dimensionality == 0).value();
|
||||
|
||||
|
||||
maxgen = parser.createParam(
|
||||
1000,
|
||||
"max-gen",
|
||||
"Maximum number of generations that the system will run (needed for damping)",
|
||||
'M',
|
||||
section).value();
|
||||
|
||||
|
||||
1000,
|
||||
"max-gen",
|
||||
"Maximum number of generations that the system will run (needed for damping)",
|
||||
'M',
|
||||
section).value();
|
||||
|
||||
|
||||
if (n == 0) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
defaults(n, maxgen);
|
||||
|
||||
|
||||
/* handle lambda */
|
||||
lambda = parser.createParam(
|
||||
lambda,
|
||||
"lambda",
|
||||
"Number of offspring",
|
||||
'l',
|
||||
section).value();
|
||||
lambda,
|
||||
"lambda",
|
||||
"Number of offspring",
|
||||
'l',
|
||||
section).value();
|
||||
|
||||
if (lambda < 2) {
|
||||
lambda = 4+(int)(3*log((double) n));
|
||||
cerr << "Too small lambda specified, setting it to " << lambda << endl;
|
||||
lambda = 4+(int)(3*log((double) n));
|
||||
cerr << "Too small lambda specified, setting it to " << lambda << endl;
|
||||
}
|
||||
|
||||
|
||||
/* handle mu */
|
||||
mu = parser.createParam(
|
||||
mu,
|
||||
"mu",
|
||||
"Population size",
|
||||
'm',
|
||||
section).value();
|
||||
mu,
|
||||
"mu",
|
||||
"Population size",
|
||||
'm',
|
||||
section).value();
|
||||
|
||||
if (mu >= lambda) {
|
||||
mu = lambda/2;
|
||||
cerr << "Mu set larger/equal to lambda, setting it to " << mu << endl;
|
||||
mu = lambda/2;
|
||||
cerr << "Mu set larger/equal to lambda, setting it to " << mu << endl;
|
||||
}
|
||||
|
||||
|
||||
/* handle selection weights */
|
||||
|
||||
|
||||
int weight_type = parser.createParam(
|
||||
0,
|
||||
"weighting",
|
||||
"Weighting scheme (for 'selection'): 0 = logarithmic, 1 = equal, 2 = linear",
|
||||
'w',
|
||||
section).value();
|
||||
0,
|
||||
"weighting",
|
||||
"Weighting scheme (for 'selection'): 0 = logarithmic, 1 = equal, 2 = linear",
|
||||
'w',
|
||||
section).value();
|
||||
|
||||
switch (weight_type) {
|
||||
case 1:
|
||||
{
|
||||
for (unsigned i = 0; i < weights.size(); ++i) {
|
||||
weights[i] = mu - i;
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
weights = 1.;
|
||||
}
|
||||
default :
|
||||
{
|
||||
for (unsigned i = 0; i < weights.size(); ++i) {
|
||||
weights[i] = log(mu+1.)-log(i+1.);
|
||||
}
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
for (unsigned i = 0; i < weights.size(); ++i) {
|
||||
weights[i] = mu - i;
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
weights = 1.;
|
||||
}
|
||||
default :
|
||||
{
|
||||
for (unsigned i = 0; i < weights.size(); ++i) {
|
||||
weights[i] = log(mu+1.)-log(i+1.);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Normalize weights and set mu_eff */
|
||||
double sumw = weights.sum();
|
||||
mueff = sumw * sumw / (weights * weights).sum();
|
||||
weights /= sumw;
|
||||
|
||||
|
||||
|
||||
/* most of the rest depends on mu_eff, so needs to be set again */
|
||||
|
||||
|
||||
/* set the others using Nikolaus logic. If you want to tweak, you can parameterize over these defaults */
|
||||
mucov = mueff;
|
||||
ccumsig = (mueff + 2.) / (n + mueff + 3.);
|
||||
ccumcov = 4. / (n + 4);
|
||||
|
||||
|
||||
double t1 = 2. / ((n+1.4142)*(n+1.4142));
|
||||
double t2 = (2.*mucov-1.) / ((n+2.)*(n+2.)+mucov);
|
||||
t2 = (t2 > 1) ? 1 : t2;
|
||||
t2 = (1./mucov) * t1 + (1.-1./mucov) * t2;
|
||||
|
||||
|
||||
ccov = t2;
|
||||
|
||||
damp = 1 + std::max(0.3,(1.-(double)n/(double)maxgen))
|
||||
* (1+2*std::max(0.,sqrt((mueff-1.)/(n+1.))-1)) /* limit sigma increase */
|
||||
/ ccumsig;
|
||||
|
||||
* (1+2*std::max(0.,sqrt((mueff-1.)/(n+1.))-1)) /* limit sigma increase */
|
||||
/ ccumsig;
|
||||
|
||||
vector<double> mins(1,0.0);
|
||||
mins = parser.createParam(
|
||||
mins,
|
||||
"min-stdev",
|
||||
"Array of minimum stdevs, last one will apply for all remaining axes",
|
||||
0,
|
||||
section).value();
|
||||
|
||||
mins,
|
||||
"min-stdev",
|
||||
"Array of minimum stdevs, last one will apply for all remaining axes",
|
||||
0,
|
||||
section).value();
|
||||
|
||||
if (mins.size() > n) mins.resize(n);
|
||||
|
||||
if (mins.size()) {
|
||||
minStdevs = mins.back();
|
||||
for (unsigned i = 0; i < mins.size(); ++i) {
|
||||
minStdevs[i] = mins[i];
|
||||
}
|
||||
minStdevs = mins.back();
|
||||
for (unsigned i = 0; i < mins.size(); ++i) {
|
||||
minStdevs[i] = mins[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
vector<double> inits(1,0.3);
|
||||
inits = parser.createParam(
|
||||
inits,
|
||||
"init-stdev",
|
||||
"Array of initial stdevs, last one will apply for all remaining axes",
|
||||
0,
|
||||
section).value();
|
||||
|
||||
inits,
|
||||
"init-stdev",
|
||||
"Array of initial stdevs, last one will apply for all remaining axes",
|
||||
0,
|
||||
section).value();
|
||||
|
||||
if (inits.size() > n) inits.resize(n);
|
||||
|
||||
if (inits.size()) {
|
||||
initialStdevs = inits.back();
|
||||
for (unsigned i = 0; i < inits.size(); ++i) {
|
||||
initialStdevs[i] = inits[i];
|
||||
}
|
||||
initialStdevs = inits.back();
|
||||
for (unsigned i = 0; i < inits.size(); ++i) {
|
||||
initialStdevs[i] = inits[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CMAParams::defaults(unsigned n_, unsigned maxgen_) {
|
||||
|
|
@ -194,39 +193,39 @@ void CMAParams::defaults(unsigned n_, unsigned maxgen_) {
|
|||
|
||||
lambda = 4+(int)(3*log((double) n));
|
||||
mu = lambda / 2;
|
||||
|
||||
|
||||
weights.resize(mu);
|
||||
|
||||
|
||||
for (unsigned i = 0; i < weights.size(); ++i) {
|
||||
weights[i] = log(mu+1.)-log(i+1.);
|
||||
weights[i] = log(mu+1.)-log(i+1.);
|
||||
}
|
||||
|
||||
|
||||
/* Normalize weights and set mu_eff */
|
||||
double sumw = weights.sum();
|
||||
mueff = sumw * sumw / (weights * weights).sum();
|
||||
weights /= sumw;
|
||||
|
||||
|
||||
mucov = mueff;
|
||||
ccumsig *= (mueff + 2.) / (n + mueff + 3.);
|
||||
ccumcov = 4. / (n + 4);
|
||||
|
||||
|
||||
double t1 = 2. / ((n+1.4142)*(n+1.4142));
|
||||
double t2 = (2.*mucov-1.) / ((n+2.)*(n+2.)+mucov);
|
||||
t2 = (t2 > 1) ? 1 : t2;
|
||||
t2 = (1./mucov) * t1 + (1.-1./mucov) * t2;
|
||||
|
||||
|
||||
ccov = t2;
|
||||
|
||||
damp = 1 + std::max(0.3,(1.-(double)n/maxgen))
|
||||
* (1+2*std::max(0.,sqrt((mueff-1.)/(n+1.))-1)) /* limit sigma increase */
|
||||
/ ccumsig;
|
||||
* (1+2*std::max(0.,sqrt((mueff-1.)/(n+1.))-1)) /* limit sigma increase */
|
||||
/ ccumsig;
|
||||
|
||||
minStdevs.resize(n);
|
||||
minStdevs = 0.0;
|
||||
|
||||
|
||||
initialStdevs.resize(n);
|
||||
initialStdevs = 0.3;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
* C++ification of Nikolaus Hansen's original C-source code for the
|
||||
* CMA-ES.
|
||||
* CMA-ES.
|
||||
*
|
||||
* Copyright (C) 1996, 2003, Nikolaus Hansen
|
||||
* (C) 2005, Maarten Keijzer
|
||||
* (C) 2005, Maarten Keijzer
|
||||
*
|
||||
* License: LGPL
|
||||
*
|
||||
* License: LGPL
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CMAPARAMS_H__
|
||||
|
|
@ -18,25 +18,25 @@ class eoParser;
|
|||
namespace eo {
|
||||
|
||||
class CMAParams {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
CMAParams() { /* Call this and all values need to be set by hand */ }
|
||||
CMAParams(eoParser& parser, unsigned dimensionality = 0); // 0 dimensionality -> user needs to set it
|
||||
|
||||
|
||||
void defaults(unsigned n_, unsigned maxgen_); /* apply all defaults using n and maxgen */
|
||||
|
||||
|
||||
unsigned n;
|
||||
unsigned maxgen;
|
||||
|
||||
|
||||
unsigned lambda; /* -> mu */
|
||||
unsigned mu; /* -> weights, lambda */
|
||||
|
||||
|
||||
std::valarray<double> weights; /* <- mu, -> mueff -> mucov -> ccov */
|
||||
double mueff; /* <- weights */
|
||||
|
||||
|
||||
double mucov;
|
||||
|
||||
|
||||
double damp; /* <- ccumsig, maxeval, lambda */
|
||||
double ccumsig; /* -> damp, <- N */
|
||||
double ccumcov;
|
||||
|
|
@ -49,4 +49,3 @@ class CMAParams {
|
|||
} // namespace eo
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@
|
|||
* algorithm:
|
||||
*
|
||||
* - Numerical issues are now treated 'before' going into the eigenvector decomposition
|
||||
* (this was done out of convenience)
|
||||
* (this was done out of convenience)
|
||||
* - dMaxSignifiKond (smallest x such that x == x + 1.0) replaced by
|
||||
* numeric_limits<double>::epsilon() (smallest x such that 1.0 != 1.0 + x)
|
||||
*
|
||||
*
|
||||
* numeric_limits<double>::epsilon() (smallest x such that 1.0 != 1.0 + x)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------- */
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
* 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.
|
||||
*
|
||||
*
|
||||
* */
|
||||
/* --- Changes : ---
|
||||
* 03/03/21: argument const double *rgFunVal of
|
||||
|
|
@ -66,289 +66,289 @@
|
|||
using namespace std;
|
||||
|
||||
namespace eo {
|
||||
|
||||
|
||||
struct CMAStateImpl {
|
||||
|
||||
|
||||
CMAParams p;
|
||||
|
||||
|
||||
lower_triangular_matrix C; // Covariance matrix
|
||||
square_matrix B; // Eigen vectors (in columns)
|
||||
valarray<double> d; // eigen values (diagonal matrix)
|
||||
valarray<double> pc; // Evolution path
|
||||
valarray<double> ps; // Evolution path for stepsize;
|
||||
|
||||
|
||||
vector<double> mean; // current mean to sample around
|
||||
double sigma; // global step size
|
||||
|
||||
|
||||
unsigned gen;
|
||||
vector<double> fitnessHistory;
|
||||
|
||||
|
||||
|
||||
|
||||
CMAStateImpl(const CMAParams& params_, const vector<double>& m, double sigma_) :
|
||||
p(params_),
|
||||
C(p.n), B(p.n), d(p.n), pc(p.n), ps(p.n), mean(m), sigma(sigma_),
|
||||
gen(0), fitnessHistory(3)
|
||||
p(params_),
|
||||
C(p.n), B(p.n), d(p.n), pc(p.n), ps(p.n), mean(m), sigma(sigma_),
|
||||
gen(0), fitnessHistory(3)
|
||||
{
|
||||
double trace = (p.initialStdevs * p.initialStdevs).sum();
|
||||
/* Initialize covariance structure */
|
||||
for (unsigned i = 0; i < p.n; ++i)
|
||||
{
|
||||
B[i][i] = 1.;
|
||||
d[i] = p.initialStdevs[i] * sqrt(p.n / trace);
|
||||
C[i][i] = d[i] * d[i];
|
||||
pc[i] = 0.;
|
||||
ps[i] = 0.;
|
||||
}
|
||||
|
||||
double trace = (p.initialStdevs * p.initialStdevs).sum();
|
||||
/* Initialize covariance structure */
|
||||
for (unsigned i = 0; i < p.n; ++i)
|
||||
{
|
||||
B[i][i] = 1.;
|
||||
d[i] = p.initialStdevs[i] * sqrt(p.n / trace);
|
||||
C[i][i] = d[i] * d[i];
|
||||
pc[i] = 0.;
|
||||
ps[i] = 0.;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void sample(vector<double>& v) {
|
||||
unsigned n = p.n;
|
||||
v.resize(n);
|
||||
|
||||
vector<double> tmp(n);
|
||||
for (unsigned i = 0; i < n; ++i)
|
||||
tmp[i] = d[i] * rng.normal();
|
||||
|
||||
/* add mutation (sigma * B * (D*z)) */
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
double sum = 0;
|
||||
for (unsigned j = 0; j < n; ++j) {
|
||||
sum += B[i][j] * tmp[j];
|
||||
}
|
||||
v[i] = mean[i] + sigma * sum;
|
||||
}
|
||||
unsigned n = p.n;
|
||||
v.resize(n);
|
||||
|
||||
vector<double> tmp(n);
|
||||
for (unsigned i = 0; i < n; ++i)
|
||||
tmp[i] = d[i] * rng.normal();
|
||||
|
||||
/* add mutation (sigma * B * (D*z)) */
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
double sum = 0;
|
||||
for (unsigned j = 0; j < n; ++j) {
|
||||
sum += B[i][j] * tmp[j];
|
||||
}
|
||||
v[i] = mean[i] + sigma * sum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void reestimate(const vector<const vector<double>* >& pop, double muBest, double muWorst) {
|
||||
|
||||
assert(pop.size() == p.mu);
|
||||
|
||||
unsigned n = p.n;
|
||||
|
||||
fitnessHistory[gen % fitnessHistory.size()] = muBest; // needed for divergence check
|
||||
|
||||
vector<double> oldmean = mean;
|
||||
valarray<double> BDz(n);
|
||||
|
||||
/* calculate xmean and rgBDz~N(0,C) */
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
mean[i] = 0.;
|
||||
for (unsigned j = 0; j < pop.size(); ++j) {
|
||||
mean[i] += p.weights[j] * (*pop[j])[i];
|
||||
}
|
||||
BDz[i] = sqrt(p.mueff)*(mean[i] - oldmean[i])/sigma;
|
||||
}
|
||||
assert(pop.size() == p.mu);
|
||||
|
||||
vector<double> tmp(n);
|
||||
/* calculate z := D^(-1) * B^(-1) * rgBDz into rgdTmp */
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
double sum = 0.0;
|
||||
for (unsigned j = 0; j < n; ++j) {
|
||||
sum += B[j][i] * BDz[j];
|
||||
}
|
||||
tmp[i] = sum / d[i];
|
||||
}
|
||||
unsigned n = p.n;
|
||||
|
||||
/* cumulation for sigma (ps) using B*z */
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
double sum = 0.0;
|
||||
for (unsigned j = 0; j < n; ++j)
|
||||
sum += B[i][j] * tmp[j];
|
||||
|
||||
ps[i] = (1. - p.ccumsig) * ps[i] + sqrt(p.ccumsig * (2. - p.ccumsig)) * sum;
|
||||
}
|
||||
fitnessHistory[gen % fitnessHistory.size()] = muBest; // needed for divergence check
|
||||
|
||||
/* calculate norm(ps)^2 */
|
||||
double psxps = (ps * ps).sum();
|
||||
vector<double> oldmean = mean;
|
||||
valarray<double> BDz(n);
|
||||
|
||||
|
||||
double chiN = sqrt((double) p.n) * (1. - 1./(4.*p.n) + 1./(21.*p.n*p.n));
|
||||
/* cumulation for covariance matrix (pc) using B*D*z~N(0,C) */
|
||||
double hsig = sqrt(psxps) / sqrt(1. - pow(1.-p.ccumsig, 2.*gen)) / chiN < 1.5 + 1./(p.n-0.5);
|
||||
|
||||
pc = (1. - p.ccumcov) * pc + hsig * sqrt(p.ccumcov * (2. - p.ccumcov)) * BDz;
|
||||
|
||||
/* stop initial phase (MK, this was not reachable in the org code, deleted) */
|
||||
/* calculate xmean and rgBDz~N(0,C) */
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
mean[i] = 0.;
|
||||
for (unsigned j = 0; j < pop.size(); ++j) {
|
||||
mean[i] += p.weights[j] * (*pop[j])[i];
|
||||
}
|
||||
BDz[i] = sqrt(p.mueff)*(mean[i] - oldmean[i])/sigma;
|
||||
}
|
||||
|
||||
/* remove momentum in ps, if ps is large and fitness is getting worse */
|
||||
vector<double> tmp(n);
|
||||
/* calculate z := D^(-1) * B^(-1) * rgBDz into rgdTmp */
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
double sum = 0.0;
|
||||
for (unsigned j = 0; j < n; ++j) {
|
||||
sum += B[j][i] * BDz[j];
|
||||
}
|
||||
tmp[i] = sum / d[i];
|
||||
}
|
||||
|
||||
if (gen >= fitnessHistory.size()) {
|
||||
/* cumulation for sigma (ps) using B*z */
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
double sum = 0.0;
|
||||
for (unsigned j = 0; j < n; ++j)
|
||||
sum += B[i][j] * tmp[j];
|
||||
|
||||
// find direction from muBest and muWorst (muBest == muWorst handled seperately
|
||||
double direction = muBest < muWorst? -1.0 : 1.0;
|
||||
|
||||
unsigned now = gen % fitnessHistory.size();
|
||||
unsigned prev = (gen-1) % fitnessHistory.size();
|
||||
unsigned prevprev = (gen-2) % fitnessHistory.size();
|
||||
ps[i] = (1. - p.ccumsig) * ps[i] + sqrt(p.ccumsig * (2. - p.ccumsig)) * sum;
|
||||
}
|
||||
|
||||
bool fitnessWorsens = (muBest == muWorst) || // <- increase norm also when population has converged (this deviates from Hansen's scheme)
|
||||
( (direction * fitnessHistory[now] < direction * fitnessHistory[prev])
|
||||
&&
|
||||
(direction * fitnessHistory[now] < direction * fitnessHistory[prevprev]));
|
||||
|
||||
if(psxps/p.n > 1.5 + 10.*sqrt(2./p.n) && fitnessWorsens) {
|
||||
double tfac = sqrt((1 + std::max(0., log(psxps/p.n))) * p.n / psxps);
|
||||
ps *= tfac;
|
||||
psxps *= tfac*tfac;
|
||||
}
|
||||
}
|
||||
/* calculate norm(ps)^2 */
|
||||
double psxps = (ps * ps).sum();
|
||||
|
||||
/* update of C */
|
||||
/* Adapt_C(t); not used anymore */
|
||||
if (p.ccov != 0.) {
|
||||
//flgEigensysIsUptodate = 0;
|
||||
|
||||
/* update covariance matrix */
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
vector<double>::iterator c_row = C[i];
|
||||
for (unsigned j = 0; j <= i; ++j) {
|
||||
c_row[j] =
|
||||
(1 - p.ccov) * c_row[j]
|
||||
+
|
||||
p.ccov * (1./p.mucov) * pc[i] * pc[j]
|
||||
+
|
||||
(1-hsig) * p.ccumcov * (2. - p.ccumcov) * c_row[j];
|
||||
|
||||
/*C[i][j] = (1 - p.ccov) * C[i][j]
|
||||
+ sp.ccov * (1./sp.mucov)
|
||||
* (rgpc[i] * rgpc[j]
|
||||
+ (1-hsig)*sp.ccumcov*(2.-sp.ccumcov) * C[i][j]); */
|
||||
for (unsigned k = 0; k < p.mu; ++k) { /* additional rank mu update */
|
||||
c_row[j] += p.ccov * (1-1./p.mucov) * p.weights[k]
|
||||
* ( (*pop[k])[i] - oldmean[i])
|
||||
* ( (*pop[k])[j] - oldmean[j])
|
||||
/ sigma / sigma;
|
||||
|
||||
// * (rgrgx[index[k]][i] - rgxold[i])
|
||||
// * (rgrgx[index[k]][j] - rgxold[j])
|
||||
// / sigma / sigma;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
double chiN = sqrt((double) p.n) * (1. - 1./(4.*p.n) + 1./(21.*p.n*p.n));
|
||||
/* cumulation for covariance matrix (pc) using B*D*z~N(0,C) */
|
||||
double hsig = sqrt(psxps) / sqrt(1. - pow(1.-p.ccumsig, 2.*gen)) / chiN < 1.5 + 1./(p.n-0.5);
|
||||
|
||||
/* update of sigma */
|
||||
sigma *= exp(((sqrt(psxps)/chiN)-1.)/p.damp);
|
||||
/* calculate eigensystem, must be done by caller */
|
||||
//cmaes_UpdateEigensystem(0);
|
||||
pc = (1. - p.ccumcov) * pc + hsig * sqrt(p.ccumcov * (2. - p.ccumcov)) * BDz;
|
||||
|
||||
|
||||
/* treat minimal standard deviations and numeric problems
|
||||
* Note that in contrast with the original code, some numerical issues are treated *before* we
|
||||
* go into the eigenvalue calculation */
|
||||
|
||||
treatNumericalIssues(muBest, muWorst);
|
||||
/* stop initial phase (MK, this was not reachable in the org code, deleted) */
|
||||
|
||||
gen++; // increase generation
|
||||
/* remove momentum in ps, if ps is large and fitness is getting worse */
|
||||
|
||||
if (gen >= fitnessHistory.size()) {
|
||||
|
||||
// find direction from muBest and muWorst (muBest == muWorst handled seperately
|
||||
double direction = muBest < muWorst? -1.0 : 1.0;
|
||||
|
||||
unsigned now = gen % fitnessHistory.size();
|
||||
unsigned prev = (gen-1) % fitnessHistory.size();
|
||||
unsigned prevprev = (gen-2) % fitnessHistory.size();
|
||||
|
||||
bool fitnessWorsens = (muBest == muWorst) || // <- increase norm also when population has converged (this deviates from Hansen's scheme)
|
||||
( (direction * fitnessHistory[now] < direction * fitnessHistory[prev])
|
||||
&&
|
||||
(direction * fitnessHistory[now] < direction * fitnessHistory[prevprev]));
|
||||
|
||||
if(psxps/p.n > 1.5 + 10.*sqrt(2./p.n) && fitnessWorsens) {
|
||||
double tfac = sqrt((1 + std::max(0., log(psxps/p.n))) * p.n / psxps);
|
||||
ps *= tfac;
|
||||
psxps *= tfac*tfac;
|
||||
}
|
||||
}
|
||||
|
||||
/* update of C */
|
||||
/* Adapt_C(t); not used anymore */
|
||||
if (p.ccov != 0.) {
|
||||
//flgEigensysIsUptodate = 0;
|
||||
|
||||
/* update covariance matrix */
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
vector<double>::iterator c_row = C[i];
|
||||
for (unsigned j = 0; j <= i; ++j) {
|
||||
c_row[j] =
|
||||
(1 - p.ccov) * c_row[j]
|
||||
+
|
||||
p.ccov * (1./p.mucov) * pc[i] * pc[j]
|
||||
+
|
||||
(1-hsig) * p.ccumcov * (2. - p.ccumcov) * c_row[j];
|
||||
|
||||
/*C[i][j] = (1 - p.ccov) * C[i][j]
|
||||
+ sp.ccov * (1./sp.mucov)
|
||||
* (rgpc[i] * rgpc[j]
|
||||
+ (1-hsig)*sp.ccumcov*(2.-sp.ccumcov) * C[i][j]); */
|
||||
for (unsigned k = 0; k < p.mu; ++k) { /* additional rank mu update */
|
||||
c_row[j] += p.ccov * (1-1./p.mucov) * p.weights[k]
|
||||
* ( (*pop[k])[i] - oldmean[i])
|
||||
* ( (*pop[k])[j] - oldmean[j])
|
||||
/ sigma / sigma;
|
||||
|
||||
// * (rgrgx[index[k]][i] - rgxold[i])
|
||||
// * (rgrgx[index[k]][j] - rgxold[j])
|
||||
// / sigma / sigma;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* update of sigma */
|
||||
sigma *= exp(((sqrt(psxps)/chiN)-1.)/p.damp);
|
||||
/* calculate eigensystem, must be done by caller */
|
||||
//cmaes_UpdateEigensystem(0);
|
||||
|
||||
|
||||
/* treat minimal standard deviations and numeric problems
|
||||
* Note that in contrast with the original code, some numerical issues are treated *before* we
|
||||
* go into the eigenvalue calculation */
|
||||
|
||||
treatNumericalIssues(muBest, muWorst);
|
||||
|
||||
gen++; // increase generation
|
||||
}
|
||||
|
||||
void treatNumericalIssues(double best, double worst) {
|
||||
|
||||
/* treat stdevs */
|
||||
for (unsigned i = 0; i < p.n; ++i) {
|
||||
if (sigma * sqrt(C[i][i]) < p.minStdevs[i]) {
|
||||
// increase stdev
|
||||
sigma *= exp(0.05+1./p.damp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* treat convergence */
|
||||
if (best == worst) {
|
||||
sigma *= exp(0.2 + 1./p.damp);
|
||||
}
|
||||
|
||||
/* Jede Hauptachse i testen, ob x == x + 0.1 * sigma * rgD[i] * B[i] */
|
||||
/* Test if all the means are not numerically out of whack with our coordinate system*/
|
||||
for (unsigned axis = 0; axis < p.n; ++axis) {
|
||||
double fac = 0.1 * sigma * d[axis];
|
||||
unsigned coord;
|
||||
for (coord = 0; coord < p.n; ++coord) {
|
||||
if (mean[coord] != mean[coord] + fac * B[coord][axis]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (coord == p.n) { // means are way too big (little) for numerical accuraccy. Start rocking the craddle a bit more
|
||||
sigma *= exp(0.2+1./p.damp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Testen ob eine Komponente des Objektparameters festhaengt */
|
||||
/* Correct issues with scale between objective values and covariances */
|
||||
bool theresAnIssue = false;
|
||||
/* treat stdevs */
|
||||
for (unsigned i = 0; i < p.n; ++i) {
|
||||
if (sigma * sqrt(C[i][i]) < p.minStdevs[i]) {
|
||||
// increase stdev
|
||||
sigma *= exp(0.05+1./p.damp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < p.n; ++i) {
|
||||
if (mean[i] == mean[i] + 0.2 * sigma * sqrt(C[i][i])) {
|
||||
C[i][i] *= (1. + p.ccov);
|
||||
theresAnIssue = true;
|
||||
}
|
||||
}
|
||||
/* treat convergence */
|
||||
if (best == worst) {
|
||||
sigma *= exp(0.2 + 1./p.damp);
|
||||
}
|
||||
|
||||
if (theresAnIssue) {
|
||||
sigma *= exp(0.05 + 1./p.damp);
|
||||
}
|
||||
/* Jede Hauptachse i testen, ob x == x + 0.1 * sigma * rgD[i] * B[i] */
|
||||
/* Test if all the means are not numerically out of whack with our coordinate system*/
|
||||
for (unsigned axis = 0; axis < p.n; ++axis) {
|
||||
double fac = 0.1 * sigma * d[axis];
|
||||
unsigned coord;
|
||||
for (coord = 0; coord < p.n; ++coord) {
|
||||
if (mean[coord] != mean[coord] + fac * B[coord][axis]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (coord == p.n) { // means are way too big (little) for numerical accuraccy. Start rocking the craddle a bit more
|
||||
sigma *= exp(0.2+1./p.damp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Testen ob eine Komponente des Objektparameters festhaengt */
|
||||
/* Correct issues with scale between objective values and covariances */
|
||||
bool theresAnIssue = false;
|
||||
|
||||
for (unsigned i = 0; i < p.n; ++i) {
|
||||
if (mean[i] == mean[i] + 0.2 * sigma * sqrt(C[i][i])) {
|
||||
C[i][i] *= (1. + p.ccov);
|
||||
theresAnIssue = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (theresAnIssue) {
|
||||
sigma *= exp(0.05 + 1./p.damp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool updateEigenSystem(unsigned max_tries, unsigned max_iters) {
|
||||
|
||||
if (max_iters==0) max_iters = 30 * p.n;
|
||||
|
||||
static double lastGoodMinimumEigenValue = 1.0;
|
||||
|
||||
/* Try to get a valid calculation */
|
||||
for (unsigned tries = 0; tries < max_tries; ++tries) {
|
||||
|
||||
unsigned iters = eig( p.n, C, d, B, max_iters);
|
||||
if (iters < max_iters)
|
||||
{ // all is well
|
||||
|
||||
/* find largest/smallest eigenvalues */
|
||||
double minEV = d.min();
|
||||
double maxEV = d.max();
|
||||
if (max_iters==0) max_iters = 30 * p.n;
|
||||
|
||||
/* (MK Original comment was) :Limit Condition of C to dMaxSignifKond+1
|
||||
* replaced dMaxSignifKond with 1./numeric_limits<double>::epsilon()
|
||||
* */
|
||||
if (maxEV * numeric_limits<double>::epsilon() > minEV) {
|
||||
double tmp = maxEV * numeric_limits<double>::epsilon() - minEV;
|
||||
minEV += tmp;
|
||||
for (unsigned i=0;i<p.n;++i) {
|
||||
C[i][i] += tmp;
|
||||
d[i] += tmp;
|
||||
}
|
||||
} /* if */
|
||||
lastGoodMinimumEigenValue = minEV;
|
||||
static double lastGoodMinimumEigenValue = 1.0;
|
||||
|
||||
d = sqrt(d);
|
||||
/* Try to get a valid calculation */
|
||||
for (unsigned tries = 0; tries < max_tries; ++tries) {
|
||||
|
||||
//flgEigensysIsUptodate = 1;
|
||||
//genOfEigensysUpdate = gen;
|
||||
//clockeigensum += clock() - clockeigenbegin;
|
||||
return true;
|
||||
} /* if cIterEig < ... */
|
||||
unsigned iters = eig( p.n, C, d, B, max_iters);
|
||||
if (iters < max_iters)
|
||||
{ // all is well
|
||||
|
||||
// numerical problems, ignore them and try again
|
||||
|
||||
/* Addition des letzten minEW auf die Diagonale von C */
|
||||
/* Add the last known good eigen value to the diagonal of C */
|
||||
double summand = lastGoodMinimumEigenValue * exp((double) tries);
|
||||
for (unsigned i = 0; i < p.n; ++i)
|
||||
C[i][i] += summand;
|
||||
/* find largest/smallest eigenvalues */
|
||||
double minEV = d.min();
|
||||
double maxEV = d.max();
|
||||
|
||||
/* (MK Original comment was) :Limit Condition of C to dMaxSignifKond+1
|
||||
* replaced dMaxSignifKond with 1./numeric_limits<double>::epsilon()
|
||||
* */
|
||||
if (maxEV * numeric_limits<double>::epsilon() > minEV) {
|
||||
double tmp = maxEV * numeric_limits<double>::epsilon() - minEV;
|
||||
minEV += tmp;
|
||||
for (unsigned i=0;i<p.n;++i) {
|
||||
C[i][i] += tmp;
|
||||
d[i] += tmp;
|
||||
}
|
||||
} /* if */
|
||||
lastGoodMinimumEigenValue = minEV;
|
||||
|
||||
d = sqrt(d);
|
||||
|
||||
//flgEigensysIsUptodate = 1;
|
||||
//genOfEigensysUpdate = gen;
|
||||
//clockeigensum += clock() - clockeigenbegin;
|
||||
return true;
|
||||
} /* if cIterEig < ... */
|
||||
|
||||
// numerical problems, ignore them and try again
|
||||
|
||||
/* Addition des letzten minEW auf die Diagonale von C */
|
||||
/* Add the last known good eigen value to the diagonal of C */
|
||||
double summand = lastGoodMinimumEigenValue * exp((double) tries);
|
||||
for (unsigned i = 0; i < p.n; ++i)
|
||||
C[i][i] += summand;
|
||||
|
||||
} /* for iEigenCalcVers */
|
||||
|
||||
return false;
|
||||
|
||||
} /* for iEigenCalcVers */
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
CMAState::CMAState(const CMAParams& params, const std::vector<double>& initial_point, const double initial_sigma)
|
||||
CMAState::CMAState(const CMAParams& params, const std::vector<double>& initial_point, const double initial_sigma)
|
||||
: pimpl(new CMAStateImpl(params, initial_point, initial_sigma)) {}
|
||||
|
||||
CMAState::~CMAState() { delete pimpl; }
|
||||
|
|
@ -362,4 +362,3 @@ bool CMAState::updateEigenSystem(unsigned max_tries, unsigned max_iters) { retur
|
|||
|
||||
|
||||
} // namespace eo
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
|
||||
/*
|
||||
* C++ification of Nikolaus Hansen's original C-source code for the
|
||||
* CMA-ES.
|
||||
* CMA-ES.
|
||||
*
|
||||
* Copyright (C) 1996, 2003, Nikolaus Hansen
|
||||
* (C) 2005, Maarten Keijzer
|
||||
* (C) 2005, Maarten Keijzer
|
||||
*
|
||||
* License: LGPL (see source file)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CMASTATE_H_
|
||||
|
|
@ -17,14 +16,14 @@
|
|||
#include <valarray>
|
||||
|
||||
namespace eo {
|
||||
|
||||
|
||||
|
||||
class CMAStateImpl;
|
||||
class CMAParams;
|
||||
class CMAState {
|
||||
|
||||
|
||||
CMAStateImpl* pimpl; /* pointer to implementation, hidden in source file */
|
||||
|
||||
|
||||
public:
|
||||
|
||||
CMAState(const CMAParams&, const std::vector<double>& initial_point, const double initial_sigma = 1.0);
|
||||
|
|
@ -35,34 +34,34 @@ class CMAState {
|
|||
/**
|
||||
* sample a vector from the distribution
|
||||
*
|
||||
* If the sample is not to your liking (i.e., not within bounds)
|
||||
* you can do one of two things:
|
||||
* If the sample is not to your liking (i.e., not within bounds)
|
||||
* you can do one of two things:
|
||||
*
|
||||
* a) Call sample again
|
||||
* b) multiply the entire vector with a number between -1 and 1
|
||||
*
|
||||
* Do not modify the sample in any other way as this will invalidate the
|
||||
* internal consistency of the system.
|
||||
* a) Call sample again
|
||||
* b) multiply the entire vector with a number between -1 and 1
|
||||
*
|
||||
* A final approach is to copy the sample and modify the copy externally (in the evaluation function)
|
||||
* and possibly add a penalty depending on the size of the modification.
|
||||
* Do not modify the sample in any other way as this will invalidate the
|
||||
* internal consistency of the system.
|
||||
*
|
||||
* A final approach is to copy the sample and modify the copy externally (in the evaluation function)
|
||||
* and possibly add a penalty depending on the size of the modification.
|
||||
*
|
||||
*/
|
||||
void sample(std::vector<double>& v) const;
|
||||
|
||||
|
||||
/**
|
||||
* Reestimate covariance matrix and other internal parameters
|
||||
* Does NOT update the eigen system (call that seperately)
|
||||
*
|
||||
* Needs a population of mu individuals, sorted on fitness, plus
|
||||
*
|
||||
* muBest: the best fitness in the population
|
||||
* muBest: the best fitness in the population
|
||||
* muWorst: the worst fitness in the population
|
||||
*/
|
||||
|
||||
|
||||
void reestimate(const std::vector<const std::vector<double>* >& sorted_population, double muBest, double muWorst);
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* call this function after reestimate in order to update the eigen system
|
||||
* It is a seperate call to allow the user to periodically skip this expensive step
|
||||
*
|
||||
|
|
@ -71,7 +70,7 @@ class CMAState {
|
|||
* If after max_tries still no numerically sound eigen system is constructed,
|
||||
* the function returns false
|
||||
*/
|
||||
bool updateEigenSystem(unsigned max_tries = 1, unsigned max_iters = 0);
|
||||
bool updateEigenSystem(unsigned max_tries = 1, unsigned max_iters = 0);
|
||||
};
|
||||
|
||||
} // namespace eo
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/*
|
||||
* C++ification of Nikolaus Hansen's original C-source code for the
|
||||
* CMA-ES. These are the eigenvector calculations
|
||||
|
|
@ -8,7 +7,7 @@
|
|||
*
|
||||
* This algorithm is held almost completely intact. Some other datatypes are used,
|
||||
* but hardly any code has changed
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------- */
|
||||
|
|
@ -31,7 +30,7 @@
|
|||
* 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.
|
||||
*
|
||||
*
|
||||
* */
|
||||
/* --- Changes : ---
|
||||
* 03/03/21: argument const double *rgFunVal of
|
||||
|
|
@ -49,21 +48,21 @@
|
|||
using namespace std;
|
||||
|
||||
/* ========================================================= */
|
||||
/*
|
||||
/*
|
||||
Householder Transformation einer symmetrischen Matrix
|
||||
auf tridiagonale Form.
|
||||
-> n : Dimension
|
||||
-> ma : symmetrische nxn-Matrix
|
||||
<- ma : Transformationsmatrix (ist orthogonal):
|
||||
<- ma : Transformationsmatrix (ist orthogonal):
|
||||
Tridiag.-Matrix == <-ma * ->ma * (<-ma)^t
|
||||
<- diag : Diagonale der resultierenden Tridiagonalmatrix
|
||||
<- neben[0..n-1] : Nebendiagonale (==1..n-1) der res. Tridiagonalmatrix
|
||||
|
||||
*/
|
||||
static void
|
||||
static void
|
||||
Householder( int N, square_matrix& ma, valarray<double>& diag, double* neben)
|
||||
{
|
||||
double epsilon;
|
||||
double epsilon;
|
||||
int i, j, k;
|
||||
double h, sum, tmp, tmp2;
|
||||
|
||||
|
|
@ -82,34 +81,34 @@ Householder( int N, square_matrix& ma, valarray<double>& diag, double* neben)
|
|||
else
|
||||
{
|
||||
for(k = i-1, sum = 0.0; k >= 0; --k)
|
||||
{ /* i-te Zeile von i-1 bis links normieren */
|
||||
{ /* i-te Zeile von i-1 bis links normieren */
|
||||
ma[i][k] /= epsilon;
|
||||
sum += ma[i][k]*ma[i][k];
|
||||
}
|
||||
tmp = (ma[i][i-1] > 0) ? -sqrt(sum) : sqrt(sum);
|
||||
neben[i] = epsilon*tmp;
|
||||
h = sum - ma[i][i-1]*tmp;
|
||||
ma[i][i-1] -= tmp;
|
||||
for (j = 0, sum = 0.0; j < i; ++j)
|
||||
{
|
||||
ma[j][i] = ma[i][j]/h;
|
||||
tmp = 0.0;
|
||||
for (k = j; k >= 0; --k)
|
||||
tmp += ma[j][k]*ma[i][k];
|
||||
for (k = j+1; k < i; ++k)
|
||||
tmp += ma[k][j]*ma[i][k];
|
||||
neben[j] = tmp/h;
|
||||
sum += neben[j] * ma[i][j];
|
||||
} /* for j */
|
||||
sum /= 2.*h;
|
||||
for (j = 0; j < i; ++j)
|
||||
{
|
||||
neben[j] -= ma[i][j]*sum;
|
||||
tmp = ma[i][j];
|
||||
tmp2 = neben[j];
|
||||
for (k = j; k >= 0; --k)
|
||||
ma[j][k] -= (tmp*neben[k] + tmp2*ma[i][k]);
|
||||
} /* for j */
|
||||
sum += ma[i][k]*ma[i][k];
|
||||
}
|
||||
tmp = (ma[i][i-1] > 0) ? -sqrt(sum) : sqrt(sum);
|
||||
neben[i] = epsilon*tmp;
|
||||
h = sum - ma[i][i-1]*tmp;
|
||||
ma[i][i-1] -= tmp;
|
||||
for (j = 0, sum = 0.0; j < i; ++j)
|
||||
{
|
||||
ma[j][i] = ma[i][j]/h;
|
||||
tmp = 0.0;
|
||||
for (k = j; k >= 0; --k)
|
||||
tmp += ma[j][k]*ma[i][k];
|
||||
for (k = j+1; k < i; ++k)
|
||||
tmp += ma[k][j]*ma[i][k];
|
||||
neben[j] = tmp/h;
|
||||
sum += neben[j] * ma[i][j];
|
||||
} /* for j */
|
||||
sum /= 2.*h;
|
||||
for (j = 0; j < i; ++j)
|
||||
{
|
||||
neben[j] -= ma[i][j]*sum;
|
||||
tmp = ma[i][j];
|
||||
tmp2 = neben[j];
|
||||
for (k = j; k >= 0; --k)
|
||||
ma[j][k] -= (tmp*neben[k] + tmp2*ma[i][k]);
|
||||
} /* for j */
|
||||
} /* else epsilon */
|
||||
} /* else i == 1 */
|
||||
diag[i] = h;
|
||||
|
|
@ -117,16 +116,16 @@ Householder( int N, square_matrix& ma, valarray<double>& diag, double* neben)
|
|||
|
||||
diag[0] = 0.0;
|
||||
neben[0] = 0.0;
|
||||
|
||||
|
||||
for (i = 0; i < N; ++i)
|
||||
{
|
||||
if(diag[i] != 0.0)
|
||||
for (j = 0; j < i; ++j)
|
||||
{
|
||||
for (k = i-1, tmp = 0.0; k >= 0; --k)
|
||||
tmp += ma[i][k] * ma[k][j];
|
||||
for (k = i-1, tmp = 0.0; k >= 0; --k)
|
||||
tmp += ma[i][k] * ma[k][j];
|
||||
for (k = i-1; k >= 0; --k)
|
||||
ma[k][j] -= tmp*ma[k][i];
|
||||
ma[k][j] -= tmp*ma[k][i];
|
||||
} /* for j */
|
||||
diag[i] = ma[i][i];
|
||||
ma[i][i] = 1.0;
|
||||
|
|
@ -137,21 +136,21 @@ Householder( int N, square_matrix& ma, valarray<double>& diag, double* neben)
|
|||
|
||||
/*
|
||||
QL-Algorithmus mit implizitem Shift, zur Berechnung von Eigenwerten
|
||||
und -vektoren einer symmetrischen Tridiagonalmatrix.
|
||||
-> n : Dimension.
|
||||
-> diag : Diagonale der Tridiagonalmatrix.
|
||||
und -vektoren einer symmetrischen Tridiagonalmatrix.
|
||||
-> n : Dimension.
|
||||
-> diag : Diagonale der Tridiagonalmatrix.
|
||||
-> neben[0..n-1] : Nebendiagonale (==0..n-2), n-1. Eintrag beliebig
|
||||
-> mq : Matrix output von Householder()
|
||||
-> maxIt : maximale Zahl der Iterationen
|
||||
-> mq : Matrix output von Householder()
|
||||
-> maxIt : maximale Zahl der Iterationen
|
||||
<- diag : Eigenwerte
|
||||
<- neben : Garbage
|
||||
<- mq : k-te Spalte ist normalisierter Eigenvektor zu diag[k]
|
||||
|
||||
*/
|
||||
|
||||
static int
|
||||
QLalgo( int N, valarray<double>& diag, square_matrix& mq,
|
||||
int maxIter, double* neben)
|
||||
static int
|
||||
QLalgo( int N, valarray<double>& diag, square_matrix& mq,
|
||||
int maxIter, double* neben)
|
||||
{
|
||||
int i, j, k, kp1, l;
|
||||
double tmp, diff, cneben, c1, c2, p;
|
||||
|
|
@ -163,77 +162,77 @@ QLalgo( int N, valarray<double>& diag, square_matrix& mq,
|
|||
{
|
||||
for (j = i; j < N-1; ++j)
|
||||
{
|
||||
tmp = fabs(diag[j]) + fabs(diag[j+1]);
|
||||
if (fabs(neben[j]) + tmp == tmp)
|
||||
break;
|
||||
tmp = fabs(diag[j]) + fabs(diag[j+1]);
|
||||
if (fabs(neben[j]) + tmp == tmp)
|
||||
break;
|
||||
}
|
||||
if (j != i)
|
||||
{
|
||||
if (++iter > maxIter) return maxIter-1;
|
||||
diff = (diag[i+1]-diag[i])/neben[i]/2.0;
|
||||
if (diff >= 0)
|
||||
diff = diag[j] - diag[i] +
|
||||
neben[i] / (diff + sqrt(diff * diff + 1.0));
|
||||
else
|
||||
diff = diag[j] - diag[i] +
|
||||
neben[i] / (diff - sqrt(diff * diff + 1.0));
|
||||
c2 = c1 = 1.0;
|
||||
p = 0.0;
|
||||
for (k = j-1; k >= i; --k)
|
||||
{
|
||||
kp1 = k + 1;
|
||||
tmp = c2 * neben[k];
|
||||
cneben = c1 * neben[k];
|
||||
if (fabs(tmp) >= fabs(diff))
|
||||
{
|
||||
c1 = diff / tmp;
|
||||
c2 = 1. / sqrt(c1*c1 + 1.0);
|
||||
neben[kp1] = tmp / c2;
|
||||
c1 *= c2;
|
||||
}
|
||||
else
|
||||
{
|
||||
c2 = tmp / diff;
|
||||
c1 = 1. / sqrt(c2*c2 + 1.0);
|
||||
neben[kp1] = diff / c1;
|
||||
c2 *= c1;
|
||||
} /* else */
|
||||
tmp = (diag[k] - diag[kp1] + p) * c2 + 2.0 * c1 * cneben;
|
||||
diag[kp1] += tmp * c2 - p;
|
||||
p = tmp * c2;
|
||||
diff = tmp * c1 - cneben;
|
||||
for (l = N-1; l >= 0; --l) /* TF-Matrix Q */
|
||||
{
|
||||
tmp = mq[l][kp1];
|
||||
mq[l][kp1] = c2 * mq[l][k] + c1 * tmp;
|
||||
mq[l][k] = c1 * mq[l][k] - c2 * tmp;
|
||||
} /* for l */
|
||||
} /* for k */
|
||||
diag[i] -= p;
|
||||
neben[i] = diff;
|
||||
neben[j] = 0.0;
|
||||
if (++iter > maxIter) return maxIter-1;
|
||||
diff = (diag[i+1]-diag[i])/neben[i]/2.0;
|
||||
if (diff >= 0)
|
||||
diff = diag[j] - diag[i] +
|
||||
neben[i] / (diff + sqrt(diff * diff + 1.0));
|
||||
else
|
||||
diff = diag[j] - diag[i] +
|
||||
neben[i] / (diff - sqrt(diff * diff + 1.0));
|
||||
c2 = c1 = 1.0;
|
||||
p = 0.0;
|
||||
for (k = j-1; k >= i; --k)
|
||||
{
|
||||
kp1 = k + 1;
|
||||
tmp = c2 * neben[k];
|
||||
cneben = c1 * neben[k];
|
||||
if (fabs(tmp) >= fabs(diff))
|
||||
{
|
||||
c1 = diff / tmp;
|
||||
c2 = 1. / sqrt(c1*c1 + 1.0);
|
||||
neben[kp1] = tmp / c2;
|
||||
c1 *= c2;
|
||||
}
|
||||
else
|
||||
{
|
||||
c2 = tmp / diff;
|
||||
c1 = 1. / sqrt(c2*c2 + 1.0);
|
||||
neben[kp1] = diff / c1;
|
||||
c2 *= c1;
|
||||
} /* else */
|
||||
tmp = (diag[k] - diag[kp1] + p) * c2 + 2.0 * c1 * cneben;
|
||||
diag[kp1] += tmp * c2 - p;
|
||||
p = tmp * c2;
|
||||
diff = tmp * c1 - cneben;
|
||||
for (l = N-1; l >= 0; --l) /* TF-Matrix Q */
|
||||
{
|
||||
tmp = mq[l][kp1];
|
||||
mq[l][kp1] = c2 * mq[l][k] + c1 * tmp;
|
||||
mq[l][k] = c1 * mq[l][k] - c2 * tmp;
|
||||
} /* for l */
|
||||
} /* for k */
|
||||
diag[i] -= p;
|
||||
neben[i] = diff;
|
||||
neben[j] = 0.0;
|
||||
} /* if */
|
||||
} while (j != i);
|
||||
return iter;
|
||||
} /* QLalgo() */
|
||||
|
||||
/* ========================================================= */
|
||||
/*
|
||||
Calculating eigenvalues and vectors.
|
||||
Input:
|
||||
/*
|
||||
Calculating eigenvalues and vectors.
|
||||
Input:
|
||||
N: dimension.
|
||||
C: lower_triangular NxN-matrix.
|
||||
niter: number of maximal iterations for QL-Algorithm.
|
||||
rgtmp: N+1-dimensional vector for temporal use.
|
||||
Output:
|
||||
niter: number of maximal iterations for QL-Algorithm.
|
||||
rgtmp: N+1-dimensional vector for temporal use.
|
||||
Output:
|
||||
diag: N eigenvalues.
|
||||
Q: Columns are normalized eigenvectors.
|
||||
return: number of iterations in QL-Algorithm.
|
||||
*/
|
||||
|
||||
namespace eo {
|
||||
int
|
||||
eig( int N, const lower_triangular_matrix& C, valarray<double>& diag, square_matrix& Q,
|
||||
int
|
||||
eig( int N, const lower_triangular_matrix& C, valarray<double>& diag, square_matrix& Q,
|
||||
int niter)
|
||||
{
|
||||
int ret;
|
||||
|
|
@ -245,15 +244,15 @@ eig( int N, const lower_triangular_matrix& C, valarray<double>& diag, square_ma
|
|||
{
|
||||
vector<double>::const_iterator row = C[i];
|
||||
for (j = 0; j <= i; ++j)
|
||||
Q[i][j] = Q[j][i] = row[j];
|
||||
Q[i][j] = Q[j][i] = row[j];
|
||||
}
|
||||
|
||||
|
||||
double* rgtmp = new double[N+1];
|
||||
Householder( N, Q, diag, rgtmp);
|
||||
ret = QLalgo( N, diag, Q, niter, rgtmp+1);
|
||||
delete [] rgtmp;
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace eo
|
||||
|
|
|
|||
|
|
@ -6,18 +6,18 @@
|
|||
|
||||
namespace eo {
|
||||
/* ========================================================= */
|
||||
/*
|
||||
Calculating eigenvalues and vectors.
|
||||
Input:
|
||||
/*
|
||||
Calculating eigenvalues and vectors.
|
||||
Input:
|
||||
N: dimension.
|
||||
C: lower_triangular NxN-matrix.
|
||||
niter: number of maximal iterations for QL-Algorithm.
|
||||
Output:
|
||||
niter: number of maximal iterations for QL-Algorithm.
|
||||
Output:
|
||||
diag: N eigenvalues.
|
||||
Q: Columns are normalized eigenvectors.
|
||||
return: number of iterations in QL-Algorithm.
|
||||
*/
|
||||
extern int eig( int N, const lower_triangular_matrix& C, std::valarray<double>& diag, square_matrix& Q,
|
||||
extern int eig( int N, const lower_triangular_matrix& C, std::valarray<double>& diag, square_matrix& Q,
|
||||
int niter = 0);
|
||||
|
||||
} // namespace eo
|
||||
|
|
|
|||
|
|
@ -34,43 +34,43 @@
|
|||
/// @todo handle bounds
|
||||
template <class FitT>
|
||||
class eoCMABreed : public eoBreed< eoVector<FitT, double> > {
|
||||
|
||||
|
||||
eo::CMAState& state;
|
||||
unsigned lambda;
|
||||
|
||||
|
||||
typedef eoVector<FitT, double> EOT;
|
||||
|
||||
|
||||
public:
|
||||
eoCMABreed(eo::CMAState& state_, unsigned lambda_) : state(state_), lambda(lambda_) {}
|
||||
|
||||
|
||||
void operator()(const eoPop<EOT>& parents, eoPop<EOT>& offspring) {
|
||||
|
||||
// two temporary arrays of pointers to store the sorted population
|
||||
std::vector<const EOT*> sorted(parents.size());
|
||||
|
||||
|
||||
// two temporary arrays of pointers to store the sorted population
|
||||
std::vector<const EOT*> sorted(parents.size());
|
||||
|
||||
// mu stores population as vector (instead of eoPop)
|
||||
std::vector<const std::vector<double>* > mu(parents.size());
|
||||
|
||||
parents.sort(sorted);
|
||||
for (unsigned i = 0; i < sorted.size(); ++i) {
|
||||
mu[i] = static_cast< const std::vector<double>* >( sorted[i] );
|
||||
}
|
||||
|
||||
// learn
|
||||
state.reestimate(mu, sorted[0]->fitness(), sorted.back()->fitness());
|
||||
|
||||
if (!state.updateEigenSystem(10)) {
|
||||
std::cerr << "No good eigensystem found" << std::endl;
|
||||
}
|
||||
|
||||
// generate
|
||||
offspring.resize(lambda);
|
||||
|
||||
for (unsigned i = 0; i < lambda; ++i) {
|
||||
state.sample( static_cast< std::vector<double>& >( offspring[i] ));
|
||||
offspring[i].invalidate();
|
||||
}
|
||||
|
||||
parents.sort(sorted);
|
||||
for (unsigned i = 0; i < sorted.size(); ++i) {
|
||||
mu[i] = static_cast< const std::vector<double>* >( sorted[i] );
|
||||
}
|
||||
|
||||
// learn
|
||||
state.reestimate(mu, sorted[0]->fitness(), sorted.back()->fitness());
|
||||
|
||||
if (!state.updateEigenSystem(10)) {
|
||||
std::cerr << "No good eigensystem found" << std::endl;
|
||||
}
|
||||
|
||||
// generate
|
||||
offspring.resize(lambda);
|
||||
|
||||
for (unsigned i = 0; i < lambda; ++i) {
|
||||
state.sample( static_cast< std::vector<double>& >( offspring[i] ));
|
||||
offspring[i].invalidate();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; fill-column: 80; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoCMAInit
|
||||
// eoCMAInit
|
||||
// (c) Maarten Keijzer 2005
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -35,18 +35,18 @@
|
|||
/// @todo handle bounds
|
||||
template <class FitT>
|
||||
class eoCMAInit : public eoInit< eoVector<FitT, double> > {
|
||||
|
||||
|
||||
const eo::CMAState& state;
|
||||
|
||||
typedef eoVector<FitT, double> EOT;
|
||||
|
||||
|
||||
public:
|
||||
eoCMAInit(const eo::CMAState& state_) : state(state_) {}
|
||||
|
||||
|
||||
|
||||
void operator()(EOT& v) {
|
||||
state.sample(static_cast<std::vector<double>& >(v));
|
||||
v.invalidate();
|
||||
state.sample(static_cast<std::vector<double>& >(v));
|
||||
v.invalidate();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -75,12 +75,12 @@ public:
|
|||
// first, the object variables
|
||||
for (unsigned i=0; i<parent.size(); i++)
|
||||
{
|
||||
// get extra parents - use private selector
|
||||
// _plop.source() is the eoPop<EOT> used by _plop to get parents
|
||||
const EOT& realParent1 = sel(_plop.source());
|
||||
const EOT& realParent2 = sel(_plop.source());
|
||||
parent[i] = realParent1[i];
|
||||
crossObj(parent[i], realParent2[i]); // apply eoBinOp
|
||||
// get extra parents - use private selector
|
||||
// _plop.source() is the eoPop<EOT> used by _plop to get parents
|
||||
const EOT& realParent1 = sel(_plop.source());
|
||||
const EOT& realParent2 = sel(_plop.source());
|
||||
parent[i] = realParent1[i];
|
||||
crossObj(parent[i], realParent2[i]); // apply eoBinOp
|
||||
}
|
||||
// then the self-adaptation parameters
|
||||
cross_self_adapt(parent, _plop.source());
|
||||
|
|
@ -110,10 +110,10 @@ private:
|
|||
{
|
||||
for (unsigned i=0; i<_parent.size(); i++)
|
||||
{
|
||||
const EOT& realParent1 = sel(_pop);
|
||||
const EOT& realParent2 = sel(_pop);
|
||||
_parent.stdevs[i] = realParent1.stdevs[i];
|
||||
crossMut(_parent.stdevs[i], realParent2.stdevs[i]); // apply eoBinOp
|
||||
const EOT& realParent1 = sel(_pop);
|
||||
const EOT& realParent2 = sel(_pop);
|
||||
_parent.stdevs[i] = realParent1.stdevs[i];
|
||||
crossMut(_parent.stdevs[i], realParent2.stdevs[i]); // apply eoBinOp
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,18 +127,18 @@ private:
|
|||
// the StDev
|
||||
for (i=0; i<_parent.size(); i++)
|
||||
{
|
||||
const EOT& realParent1 = sel(_pop);
|
||||
const EOT& realParent2 = sel(_pop);
|
||||
_parent.stdevs[i] = realParent1.stdevs[i];
|
||||
crossMut(_parent.stdevs[i], realParent2.stdevs[i]); // apply eoBinOp
|
||||
const EOT& realParent1 = sel(_pop);
|
||||
const EOT& realParent2 = sel(_pop);
|
||||
_parent.stdevs[i] = realParent1.stdevs[i];
|
||||
crossMut(_parent.stdevs[i], realParent2.stdevs[i]); // apply eoBinOp
|
||||
}
|
||||
// the roataion angles
|
||||
for (i=0; i<_parent.correlations.size(); i++)
|
||||
{
|
||||
const EOT& realParent1 = sel(_pop);
|
||||
const EOT& realParent2 = sel(_pop);
|
||||
_parent.correlations[i] = realParent1.correlations[i];
|
||||
crossMut(_parent.correlations[i], realParent2.correlations[i]); // apply eoBinOp
|
||||
const EOT& realParent1 = sel(_pop);
|
||||
const EOT& realParent2 = sel(_pop);
|
||||
_parent.correlations[i] = realParent1.correlations[i];
|
||||
crossMut(_parent.correlations[i], realParent2.correlations[i]); // apply eoBinOp
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ public:
|
|||
{
|
||||
_eo.stdev *= exp(TauLcl * rng.normal());
|
||||
if (_eo.stdev < stdev_eps)
|
||||
_eo.stdev = stdev_eps;
|
||||
_eo.stdev = stdev_eps;
|
||||
// now apply to all
|
||||
for (unsigned i = 0; i < _eo.size(); ++i)
|
||||
{
|
||||
|
|
@ -218,7 +218,7 @@ public:
|
|||
unsigned size = bounds.size();
|
||||
TauLcl = _init.TauLcl();
|
||||
TauLcl /= sqrt(2*(double) size);
|
||||
std::cout << "Init<eoEsSimple>: tau local " << TauLcl << std::endl;
|
||||
std::cout << "Init<eoEsSimple>: tau local " << TauLcl << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public :
|
|||
@param _section Parser section for \f$\tau\f$-parameters.
|
||||
*/
|
||||
eoEsMutationInit(eoParser& _parser,
|
||||
std::string _section="ES mutation parameters" ) :
|
||||
std::string _section="ES mutation parameters" ) :
|
||||
parser(_parser), repSection(_section),
|
||||
TauLclParam(0), TauGlbParam(0), TauBetaParam(0) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -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; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoEsLocalXover.h : ES global crossover
|
||||
|
|
@ -8,16 +8,16 @@
|
|||
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: marc.schoenauer@polytechnique.fr http://eeaax.cmap.polytchnique.fr/
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -45,7 +45,7 @@
|
|||
* @ingroup Real
|
||||
* @ingroup Variators
|
||||
*/
|
||||
template<class EOT>
|
||||
template<class EOT>
|
||||
class eoEsStandardXover: public eoBinOp<EOT>
|
||||
{
|
||||
public:
|
||||
|
|
@ -70,13 +70,13 @@ public:
|
|||
// first, the object variables
|
||||
for (unsigned i=0; i<_eo1.size(); i++)
|
||||
{
|
||||
bLoc |= crossObj(_eo1[i], _eo2[i]); // apply eoBinOp
|
||||
bLoc |= crossObj(_eo1[i], _eo2[i]); // apply eoBinOp
|
||||
}
|
||||
// then the self-adaptation parameters
|
||||
bLoc |= cross_self_adapt(_eo1, _eo2);
|
||||
return bLoc;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// the method to cross slef-adaptation parameters: need to specialize
|
||||
|
|
@ -91,7 +91,7 @@ private:
|
|||
bool bLoc=false;
|
||||
for (unsigned i=0; i<_parent1.size(); i++)
|
||||
{
|
||||
bLoc |= crossMut(_parent1.stdevs[i], _parent2.stdevs[i]); // apply eoBinOp
|
||||
bLoc |= crossMut(_parent1.stdevs[i], _parent2.stdevs[i]); // apply eoBinOp
|
||||
}
|
||||
return bLoc;
|
||||
}
|
||||
|
|
@ -103,12 +103,12 @@ private:
|
|||
// the StDev
|
||||
for (i=0; i<_parent1.size(); i++)
|
||||
{
|
||||
bLoc |= crossMut(_parent1.stdevs[i], _parent2.stdevs[i]); // apply eoBinOp
|
||||
bLoc |= crossMut(_parent1.stdevs[i], _parent2.stdevs[i]); // apply eoBinOp
|
||||
}
|
||||
// the roataion angles
|
||||
for (i=0; i<_parent1.correlations.size(); i++)
|
||||
{
|
||||
bLoc |= crossMut(_parent1.correlations[i], _parent2.correlations[i]); // apply eoBinOp
|
||||
bLoc |= crossMut(_parent1.correlations[i], _parent2.correlations[i]); // apply eoBinOp
|
||||
}
|
||||
return bLoc;
|
||||
|
||||
|
|
|
|||
|
|
@ -69,13 +69,13 @@ template<class EOT> class eoNormalVecMutation: public eoMonOp<EOT>
|
|||
* for each component, the sigma is scaled to the range of the bound, if bounded
|
||||
*/
|
||||
eoNormalVecMutation(eoRealVectorBounds & _bounds,
|
||||
double _sigma, const double& _p_change = 1.0):
|
||||
double _sigma, const double& _p_change = 1.0):
|
||||
sigma(_bounds.size(), _sigma), bounds(_bounds), p_change(_p_change)
|
||||
{
|
||||
// scale to the range - if any
|
||||
for (unsigned i=0; i<bounds.size(); i++)
|
||||
if (bounds.isBounded(i))
|
||||
sigma[i] *= _sigma*bounds.range(i);
|
||||
sigma[i] *= _sigma*bounds.range(i);
|
||||
}
|
||||
|
||||
/** The class name */
|
||||
|
|
@ -89,14 +89,14 @@ template<class EOT> class eoNormalVecMutation: public eoMonOp<EOT>
|
|||
{
|
||||
bool hasChanged=false;
|
||||
for (unsigned lieu=0; lieu<_eo.size(); lieu++)
|
||||
{
|
||||
if (rng.flip(p_change))
|
||||
{
|
||||
_eo[lieu] += sigma[lieu]*rng.normal();
|
||||
bounds.foldsInBounds(lieu, _eo[lieu]);
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (rng.flip(p_change))
|
||||
{
|
||||
_eo[lieu] += sigma[lieu]*rng.normal();
|
||||
bounds.foldsInBounds(lieu, _eo[lieu]);
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ public:
|
|||
* @param _p_change the probability to change a given coordinate
|
||||
*/
|
||||
eoNormalMutation(eoRealVectorBounds & _bounds,
|
||||
double _sigma, const double& _p_change = 1.0):
|
||||
double _sigma, const double& _p_change = 1.0):
|
||||
sigma(_sigma), bounds(_bounds), p_change(_p_change) {}
|
||||
|
||||
/** The class name */
|
||||
|
|
@ -152,14 +152,14 @@ public:
|
|||
{
|
||||
bool hasChanged=false;
|
||||
for (unsigned lieu=0; lieu<_eo.size(); lieu++)
|
||||
{
|
||||
if (rng.flip(p_change))
|
||||
{
|
||||
_eo[lieu] += sigma*rng.normal();
|
||||
bounds.foldsInBounds(lieu, _eo[lieu]);
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (rng.flip(p_change))
|
||||
{
|
||||
_eo[lieu] += sigma*rng.normal();
|
||||
bounds.foldsInBounds(lieu, _eo[lieu]);
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
|
|
@ -199,8 +199,8 @@ public:
|
|||
* @param _threshold the threshold (the 1/5 - 0.2)
|
||||
*/
|
||||
eoOneFifthMutation(eoEvalFunc<EOT> & _eval, double & _sigmaInit,
|
||||
unsigned _windowSize = 10, double _updateFactor=0.83,
|
||||
double _threshold=0.2):
|
||||
unsigned _windowSize = 10, double _updateFactor=0.83,
|
||||
double _threshold=0.2):
|
||||
eoNormalMutation<EOT>(_sigmaInit), eval(_eval),
|
||||
threshold(_threshold), updateFactor(_updateFactor),
|
||||
nbMut(_windowSize, 0), nbSuccess(_windowSize, 0), genIndex(0)
|
||||
|
|
@ -221,21 +221,21 @@ public:
|
|||
*/
|
||||
bool operator()(EOT & _eo)
|
||||
{
|
||||
if (_eo.invalid()) // due to some crossover???
|
||||
eval(_eo);
|
||||
if (_eo.invalid()) // due to some crossover???
|
||||
eval(_eo);
|
||||
Fitness oldFitness = _eo.fitness(); // save old fitness
|
||||
|
||||
// call standard operator - then count the successes
|
||||
if (eoNormalMutation<EOT>::operator()(_eo)) // _eo has been modified
|
||||
{
|
||||
_eo.invalidate(); // don't forget!!!
|
||||
nbMut[genIndex]++;
|
||||
eval(_eo); // compute fitness of offspring
|
||||
{
|
||||
_eo.invalidate(); // don't forget!!!
|
||||
nbMut[genIndex]++;
|
||||
eval(_eo); // compute fitness of offspring
|
||||
|
||||
if (_eo.fitness() > oldFitness)
|
||||
nbSuccess[genIndex]++; // update counter
|
||||
}
|
||||
return false; // because eval has reset the validity flag
|
||||
if (_eo.fitness() > oldFitness)
|
||||
nbSuccess[genIndex]++; // update counter
|
||||
}
|
||||
return false; // because eval has reset the validity flag
|
||||
}
|
||||
|
||||
/** the method that will be called every generation
|
||||
|
|
@ -248,18 +248,18 @@ public:
|
|||
// compute the average stats over the time window
|
||||
for ( unsigned i=0; i<nbMut.size(); i++)
|
||||
{
|
||||
totalMut += nbMut[i];
|
||||
totalSuccess += nbSuccess[i];
|
||||
totalMut += nbMut[i];
|
||||
totalSuccess += nbSuccess[i];
|
||||
}
|
||||
|
||||
// update sigma accordingly
|
||||
double prop = double(totalSuccess) / totalMut;
|
||||
if (prop > threshold) {
|
||||
Sigma() /= updateFactor; // increase sigma
|
||||
Sigma() /= updateFactor; // increase sigma
|
||||
}
|
||||
else
|
||||
{
|
||||
Sigma() *= updateFactor; // decrease sigma
|
||||
Sigma() *= updateFactor; // decrease sigma
|
||||
}
|
||||
genIndex = (genIndex+1) % nbMut.size() ;
|
||||
nbMut[genIndex] = nbSuccess[genIndex] = 0;
|
||||
|
|
@ -268,15 +268,14 @@ public:
|
|||
|
||||
private:
|
||||
eoEvalFunc<EOT> & eval;
|
||||
double threshold; // 1/5 !
|
||||
double updateFactor ; // the multiplicative factor
|
||||
std::vector<unsigned> nbMut; // total number of mutations per gen
|
||||
std::vector<unsigned> nbSuccess; // number of successful mutations per gen
|
||||
unsigned genIndex ; // current index in std::vectors (circular)
|
||||
double threshold; // 1/5 !
|
||||
double updateFactor ; // the multiplicative factor
|
||||
std::vector<unsigned> nbMut; // total number of mutations per gen
|
||||
std::vector<unsigned> nbSuccess; // number of successful mutations per gen
|
||||
unsigned genIndex ; // current index in std::vectors (circular)
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//@}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: Marc.Schoenauer@polytechnique.fr
|
||||
todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
mkeijzer@dhi.dk
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -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; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoRealAtomXover.h : helper classes for std::vector<real> crossover
|
||||
|
|
@ -8,16 +8,16 @@
|
|||
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: marc.schoenauer@polytechnique.fr http://eeaax.cmap.polytchnique.fr/
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
#include <eoOp.h>
|
||||
|
||||
/**
|
||||
/**
|
||||
Discrete crossover == exchange of values
|
||||
*
|
||||
* @ingroup Real
|
||||
|
|
@ -55,20 +55,20 @@ public:
|
|||
/**
|
||||
Exchanges or not the values
|
||||
*/
|
||||
bool operator()(double& r1, const double& r2)
|
||||
bool operator()(double& r1, const double& r2)
|
||||
{
|
||||
if (eo::rng.flip())
|
||||
if (r1 != r2) // if r1 == r2 you must return false
|
||||
{
|
||||
r1 = r2;
|
||||
return true;
|
||||
}
|
||||
if (r1 != r2) // if r1 == r2 you must return false
|
||||
{
|
||||
r1 = r2;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
Intermediate crossover == linear combination
|
||||
*
|
||||
* @ingroup Real
|
||||
|
|
@ -88,13 +88,13 @@ public:
|
|||
/**
|
||||
Linear combination of both parents
|
||||
*/
|
||||
bool operator()(double& r1, const double& r2)
|
||||
bool operator()(double& r1, const double& r2)
|
||||
{
|
||||
double alpha = eo::rng.uniform();
|
||||
r1 = alpha * r2 + (1-alpha) * r1;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// eoRealInitBounded.h
|
||||
// (c) EEAAX 2000 - 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
|
||||
|
|
@ -33,8 +33,8 @@
|
|||
#include <es/eoReal.h>
|
||||
#include <utils/eoRealVectorBounds.h>
|
||||
|
||||
/** Simple initialization for any EOT that derives from std::vector<double>
|
||||
* uniformly in some bounds
|
||||
/** Simple initialization for any EOT that derives from std::vector<double>
|
||||
* uniformly in some bounds
|
||||
*
|
||||
* @ingroup Real
|
||||
* @ingroup Variators
|
||||
|
|
@ -44,7 +44,7 @@ class eoRealInitBounded : public eoInit<EOT>
|
|||
{
|
||||
public:
|
||||
/** Ctor - from eoRealVectorBounds */
|
||||
eoRealInitBounded(eoRealVectorBounds & _bounds):bounds(_bounds)
|
||||
eoRealInitBounded(eoRealVectorBounds & _bounds):bounds(_bounds)
|
||||
{
|
||||
if (!bounds.isBounded())
|
||||
throw std::runtime_error("Needs bounded bounds to initialize a std::vector<double>");
|
||||
|
|
@ -54,7 +54,7 @@ class eoRealInitBounded : public eoInit<EOT>
|
|||
virtual void operator()(EOT & _eo)
|
||||
{
|
||||
bounds.uniform(_eo); // resizes, and fills uniformly in bounds
|
||||
_eo.invalidate(); // was MISSING!!!!
|
||||
_eo.invalidate(); // was MISSING!!!!
|
||||
}
|
||||
|
||||
/** accessor to the bounds */
|
||||
|
|
@ -67,5 +67,4 @@ class eoRealInitBounded : public eoInit<EOT>
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
//@}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -66,14 +66,14 @@ template<class EOT> class eoUniformMutation: public eoMonOp<EOT>
|
|||
* @param _p_change the one probability to change all coordinates
|
||||
*/
|
||||
eoUniformMutation(eoRealVectorBounds & _bounds,
|
||||
const double& _epsilon, const double& _p_change = 1.0):
|
||||
const double& _epsilon, const double& _p_change = 1.0):
|
||||
homogeneous(false), bounds(_bounds), epsilon(_bounds.size(), _epsilon),
|
||||
p_change(_bounds.size(), _p_change)
|
||||
{
|
||||
// scale to the range - if any
|
||||
for (unsigned i=0; i<bounds.size(); i++)
|
||||
if (bounds.isBounded(i))
|
||||
epsilon[i] *= _epsilon*bounds.range(i);
|
||||
epsilon[i] *= _epsilon*bounds.range(i);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,8 +83,8 @@ template<class EOT> class eoUniformMutation: public eoMonOp<EOT>
|
|||
* @param _p_change the VECTOR of probabilities for each coordinates
|
||||
*/
|
||||
eoUniformMutation(eoRealVectorBounds & _bounds,
|
||||
const std::vector<double>& _epsilon,
|
||||
const std::vector<double>& _p_change):
|
||||
const std::vector<double>& _epsilon,
|
||||
const std::vector<double>& _p_change):
|
||||
homogeneous(false), bounds(_bounds), epsilon(_epsilon),
|
||||
p_change(_p_change) {}
|
||||
|
||||
|
|
@ -98,43 +98,43 @@ template<class EOT> class eoUniformMutation: public eoMonOp<EOT>
|
|||
bool operator()(EOT& _eo)
|
||||
{
|
||||
bool hasChanged=false;
|
||||
if (homogeneous) // implies no bounds object
|
||||
for (unsigned lieu=0; lieu<_eo.size(); lieu++)
|
||||
{
|
||||
if (rng.flip(p_change[0]))
|
||||
{
|
||||
_eo[lieu] += 2*epsilon[0]*rng.uniform()-epsilon[0];
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
if (homogeneous) // implies no bounds object
|
||||
for (unsigned lieu=0; lieu<_eo.size(); lieu++)
|
||||
{
|
||||
if (rng.flip(p_change[0]))
|
||||
{
|
||||
_eo[lieu] += 2*epsilon[0]*rng.uniform()-epsilon[0];
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// sanity check ?
|
||||
if (_eo.size() != bounds.size())
|
||||
throw std::runtime_error("Invalid size of indi in eoUniformMutation");
|
||||
{
|
||||
// sanity check ?
|
||||
if (_eo.size() != bounds.size())
|
||||
throw std::runtime_error("Invalid size of indi in eoUniformMutation");
|
||||
|
||||
for (unsigned lieu=0; lieu<_eo.size(); lieu++)
|
||||
if (rng.flip(p_change[lieu]))
|
||||
{
|
||||
// check the bounds
|
||||
double emin = _eo[lieu]-epsilon[lieu];
|
||||
double emax = _eo[lieu]+epsilon[lieu];
|
||||
if (bounds.isMinBounded(lieu))
|
||||
emin = std::max(bounds.minimum(lieu), emin);
|
||||
if (bounds.isMaxBounded(lieu))
|
||||
emax = std::min(bounds.maximum(lieu), emax);
|
||||
_eo[lieu] = emin + (emax-emin)*rng.uniform();
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
for (unsigned lieu=0; lieu<_eo.size(); lieu++)
|
||||
if (rng.flip(p_change[lieu]))
|
||||
{
|
||||
// check the bounds
|
||||
double emin = _eo[lieu]-epsilon[lieu];
|
||||
double emax = _eo[lieu]+epsilon[lieu];
|
||||
if (bounds.isMinBounded(lieu))
|
||||
emin = std::max(bounds.minimum(lieu), emin);
|
||||
if (bounds.isMaxBounded(lieu))
|
||||
emax = std::min(bounds.maximum(lieu), emax);
|
||||
_eo[lieu] = emin + (emax-emin)*rng.uniform();
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
private:
|
||||
bool homogeneous; // == no bounds passed in the ctor
|
||||
eoRealVectorBounds & bounds;
|
||||
std::vector<double> epsilon; // the ranges for mutation
|
||||
std::vector<double> p_change; // the proba that each variable is modified
|
||||
std::vector<double> epsilon; // the ranges for mutation
|
||||
std::vector<double> p_change; // the proba that each variable is modified
|
||||
};
|
||||
|
||||
/** eoDetUniformMutation --> changes exactly k values of the std::vector
|
||||
|
|
@ -166,14 +166,14 @@ template<class EOT> class eoDetUniformMutation: public eoMonOp<EOT>
|
|||
* @param _no number of coordinate to modify
|
||||
*/
|
||||
eoDetUniformMutation(eoRealVectorBounds & _bounds,
|
||||
const double& _epsilon, const unsigned& _no = 1):
|
||||
const double& _epsilon, const unsigned& _no = 1):
|
||||
homogeneous(false), bounds(_bounds),
|
||||
epsilon(_bounds.size(), _epsilon), no(_no)
|
||||
{
|
||||
// scale to the range - if any
|
||||
for (unsigned i=0; i<bounds.size(); i++)
|
||||
if (bounds.isBounded(i))
|
||||
epsilon[i] *= _epsilon*bounds.range(i);
|
||||
epsilon[i] *= _epsilon*bounds.range(i);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -183,14 +183,14 @@ template<class EOT> class eoDetUniformMutation: public eoMonOp<EOT>
|
|||
* @param _no number of coordinates to modify
|
||||
*/
|
||||
eoDetUniformMutation(eoRealVectorBounds & _bounds,
|
||||
const std::vector<double>& _epsilon,
|
||||
const unsigned& _no = 1):
|
||||
const std::vector<double>& _epsilon,
|
||||
const unsigned& _no = 1):
|
||||
homogeneous(false), bounds(_bounds), epsilon(_epsilon), no(_no)
|
||||
{
|
||||
// scale to the range - if any
|
||||
for (unsigned i=0; i<bounds.size(); i++)
|
||||
if (bounds.isBounded(i))
|
||||
epsilon[i] *= _epsilon[i]*bounds.range(i);
|
||||
epsilon[i] *= _epsilon[i]*bounds.range(i);
|
||||
}
|
||||
|
||||
/// The class name.
|
||||
|
|
@ -203,39 +203,39 @@ template<class EOT> class eoDetUniformMutation: public eoMonOp<EOT>
|
|||
bool operator()(EOT& _eo)
|
||||
{
|
||||
if (homogeneous)
|
||||
for (unsigned i=0; i<no; i++)
|
||||
{
|
||||
unsigned lieu = rng.random(_eo.size());
|
||||
// actually, we should test that we don't re-modify same variable!
|
||||
_eo[lieu] = 2*epsilon[0]*rng.uniform()-epsilon[0];
|
||||
}
|
||||
for (unsigned i=0; i<no; i++)
|
||||
{
|
||||
unsigned lieu = rng.random(_eo.size());
|
||||
// actually, we should test that we don't re-modify same variable!
|
||||
_eo[lieu] = 2*epsilon[0]*rng.uniform()-epsilon[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
// sanity check ?
|
||||
if (_eo.size() != bounds.size())
|
||||
throw std::runtime_error("Invalid size of indi in eoDetUniformMutation");
|
||||
for (unsigned i=0; i<no; i++)
|
||||
{
|
||||
unsigned lieu = rng.random(_eo.size());
|
||||
// actually, we should test that we don't re-modify same variable!
|
||||
{
|
||||
// sanity check ?
|
||||
if (_eo.size() != bounds.size())
|
||||
throw std::runtime_error("Invalid size of indi in eoDetUniformMutation");
|
||||
for (unsigned i=0; i<no; i++)
|
||||
{
|
||||
unsigned lieu = rng.random(_eo.size());
|
||||
// actually, we should test that we don't re-modify same variable!
|
||||
|
||||
// check the bounds
|
||||
double emin = _eo[lieu]-epsilon[lieu];
|
||||
double emax = _eo[lieu]+epsilon[lieu];
|
||||
if (bounds.isMinBounded(lieu))
|
||||
emin = std::max(bounds.minimum(lieu), emin);
|
||||
if (bounds.isMaxBounded(lieu))
|
||||
emax = std::min(bounds.maximum(lieu), emax);
|
||||
_eo[lieu] = emin + (emax-emin)*rng.uniform();
|
||||
}
|
||||
}
|
||||
// check the bounds
|
||||
double emin = _eo[lieu]-epsilon[lieu];
|
||||
double emax = _eo[lieu]+epsilon[lieu];
|
||||
if (bounds.isMinBounded(lieu))
|
||||
emin = std::max(bounds.minimum(lieu), emin);
|
||||
if (bounds.isMaxBounded(lieu))
|
||||
emax = std::min(bounds.maximum(lieu), emax);
|
||||
_eo[lieu] = emin + (emax-emin)*rng.uniform();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
bool homogeneous; // == no bounds passed in the ctor
|
||||
eoRealVectorBounds & bounds;
|
||||
std::vector<double> epsilon; // the ranges of mutation
|
||||
std::vector<double> epsilon; // the ranges of mutation
|
||||
unsigned no;
|
||||
};
|
||||
|
||||
|
|
@ -274,7 +274,7 @@ template<class EOT> class eoSegmentCrossover: public eoQuadOp<EOT>
|
|||
* Must be positive
|
||||
*/
|
||||
eoSegmentCrossover(eoRealVectorBounds & _bounds,
|
||||
const double& _alpha = 0.0) :
|
||||
const double& _alpha = 0.0) :
|
||||
bounds(_bounds), alpha(_alpha), range(1+2*_alpha) {}
|
||||
|
||||
/// The class name.
|
||||
|
|
@ -291,47 +291,47 @@ template<class EOT> class eoSegmentCrossover: public eoQuadOp<EOT>
|
|||
double r1, r2, fact;
|
||||
double alphaMin = -alpha;
|
||||
double alphaMax = 1+alpha;
|
||||
if (alpha == 0.0) // no check to perform
|
||||
fact = -alpha + rng.uniform(range); // in [-alpha,1+alpha)
|
||||
else // look for the bounds for fact
|
||||
{
|
||||
for (i=0; i<_eo1.size(); i++)
|
||||
{
|
||||
r1=_eo1[i];
|
||||
r2=_eo2[i];
|
||||
if (r1 != r2) { // otherwise you'll get NAN's
|
||||
double rmin = std::min(r1, r2);
|
||||
double rmax = std::max(r1, r2);
|
||||
double length = rmax - rmin;
|
||||
if (bounds.isMinBounded(i))
|
||||
{
|
||||
alphaMin = std::max(alphaMin, (bounds.minimum(i)-rmin)/length);
|
||||
alphaMax = std::min(alphaMax, (rmax-bounds.minimum(i))/length);
|
||||
}
|
||||
if (bounds.isMaxBounded(i))
|
||||
{
|
||||
alphaMax = std::min(alphaMax, (bounds.maximum(i)-rmin)/length);
|
||||
alphaMin = std::max(alphaMin, (rmax-bounds.maximum(i))/length);
|
||||
}
|
||||
}
|
||||
}
|
||||
fact = alphaMin + (alphaMax-alphaMin)*rng.uniform();
|
||||
}
|
||||
if (alpha == 0.0) // no check to perform
|
||||
fact = -alpha + rng.uniform(range); // in [-alpha,1+alpha)
|
||||
else // look for the bounds for fact
|
||||
{
|
||||
for (i=0; i<_eo1.size(); i++)
|
||||
{
|
||||
r1=_eo1[i];
|
||||
r2=_eo2[i];
|
||||
if (r1 != r2) { // otherwise you'll get NAN's
|
||||
double rmin = std::min(r1, r2);
|
||||
double rmax = std::max(r1, r2);
|
||||
double length = rmax - rmin;
|
||||
if (bounds.isMinBounded(i))
|
||||
{
|
||||
alphaMin = std::max(alphaMin, (bounds.minimum(i)-rmin)/length);
|
||||
alphaMax = std::min(alphaMax, (rmax-bounds.minimum(i))/length);
|
||||
}
|
||||
if (bounds.isMaxBounded(i))
|
||||
{
|
||||
alphaMax = std::min(alphaMax, (bounds.maximum(i)-rmin)/length);
|
||||
alphaMin = std::max(alphaMin, (rmax-bounds.maximum(i))/length);
|
||||
}
|
||||
}
|
||||
}
|
||||
fact = alphaMin + (alphaMax-alphaMin)*rng.uniform();
|
||||
}
|
||||
|
||||
for (i=0; i<_eo1.size(); i++)
|
||||
{
|
||||
r1=_eo1[i];
|
||||
r2=_eo2[i];
|
||||
_eo1[i] = fact * r1 + (1-fact) * r2;
|
||||
_eo2[i] = (1-fact) * r1 + fact * r2;
|
||||
}
|
||||
return true; // shoudl test if fact was 0 or 1 :-)))
|
||||
{
|
||||
r1=_eo1[i];
|
||||
r2=_eo2[i];
|
||||
_eo1[i] = fact * r1 + (1-fact) * r2;
|
||||
_eo2[i] = (1-fact) * r1 + fact * r2;
|
||||
}
|
||||
return true; // shoudl test if fact was 0 or 1 :-)))
|
||||
}
|
||||
|
||||
protected:
|
||||
eoRealVectorBounds & bounds;
|
||||
double alpha;
|
||||
double range; // == 1+2*alpha
|
||||
double range; // == 1+2*alpha
|
||||
};
|
||||
|
||||
/** eoHypercubeCrossover --> uniform choice in hypercube
|
||||
|
|
@ -369,7 +369,7 @@ template<class EOT> class eoHypercubeCrossover: public eoQuadOp<EOT>
|
|||
* Must be positive
|
||||
*/
|
||||
eoHypercubeCrossover(eoRealVectorBounds & _bounds,
|
||||
const double& _alpha = 0.0):
|
||||
const double& _alpha = 0.0):
|
||||
bounds(_bounds), alpha(_alpha), range(1+2*_alpha)
|
||||
{
|
||||
if (_alpha < 0)
|
||||
|
|
@ -389,62 +389,62 @@ template<class EOT> class eoHypercubeCrossover: public eoQuadOp<EOT>
|
|||
bool hasChanged = false;
|
||||
unsigned i;
|
||||
double r1, r2, fact;
|
||||
if (alpha == 0.0) // no check to perform
|
||||
for (i=0; i<_eo1.size(); i++)
|
||||
{
|
||||
r1=_eo1[i];
|
||||
r2=_eo2[i];
|
||||
if (r1 != r2) { // otherwise do nothing
|
||||
fact = rng.uniform(range); // in [0,1)
|
||||
_eo1[i] = fact * r1 + (1-fact) * r2;
|
||||
_eo2[i] = (1-fact) * r1 + fact * r2;
|
||||
hasChanged = true; // forget (im)possible alpha=0
|
||||
}
|
||||
}
|
||||
else // check the bounds
|
||||
// do not try to get a bound on the linear factor, but rather
|
||||
// on the object variables themselves
|
||||
for (i=0; i<_eo1.size(); i++)
|
||||
{
|
||||
r1=_eo1[i];
|
||||
r2=_eo2[i];
|
||||
if (r1 != r2) { // otherwise do nothing
|
||||
double rmin = std::min(r1, r2);
|
||||
double rmax = std::max(r1, r2);
|
||||
if (alpha == 0.0) // no check to perform
|
||||
for (i=0; i<_eo1.size(); i++)
|
||||
{
|
||||
r1=_eo1[i];
|
||||
r2=_eo2[i];
|
||||
if (r1 != r2) { // otherwise do nothing
|
||||
fact = rng.uniform(range); // in [0,1)
|
||||
_eo1[i] = fact * r1 + (1-fact) * r2;
|
||||
_eo2[i] = (1-fact) * r1 + fact * r2;
|
||||
hasChanged = true; // forget (im)possible alpha=0
|
||||
}
|
||||
}
|
||||
else // check the bounds
|
||||
// do not try to get a bound on the linear factor, but rather
|
||||
// on the object variables themselves
|
||||
for (i=0; i<_eo1.size(); i++)
|
||||
{
|
||||
r1=_eo1[i];
|
||||
r2=_eo2[i];
|
||||
if (r1 != r2) { // otherwise do nothing
|
||||
double rmin = std::min(r1, r2);
|
||||
double rmax = std::max(r1, r2);
|
||||
|
||||
// compute min and max for object variables
|
||||
double objMin = -alpha * rmax + (1+alpha) * rmin;
|
||||
double objMax = -alpha * rmin + (1+alpha) * rmax;
|
||||
// compute min and max for object variables
|
||||
double objMin = -alpha * rmax + (1+alpha) * rmin;
|
||||
double objMax = -alpha * rmin + (1+alpha) * rmax;
|
||||
|
||||
// first find the limits on the alpha's
|
||||
if (bounds.isMinBounded(i))
|
||||
{
|
||||
objMin = std::max(objMin, bounds.minimum(i));
|
||||
}
|
||||
if (bounds.isMaxBounded(i))
|
||||
{
|
||||
objMax = std::min(objMax, bounds.maximum(i));
|
||||
}
|
||||
// then draw variables
|
||||
double median = (objMin+objMax)/2.0; // uniform within bounds
|
||||
// double median = (rmin+rmax)/2.0; // Bounce on bounds
|
||||
double valMin = objMin + (median-objMin)*rng.uniform();
|
||||
double valMax = median + (objMax-median)*rng.uniform();
|
||||
// don't always put large value in _eo1 - or what?
|
||||
if (rng.flip(0.5))
|
||||
{
|
||||
_eo1[i] = valMin;
|
||||
_eo2[i] = valMax;
|
||||
}
|
||||
else
|
||||
{
|
||||
_eo1[i] = valMax;
|
||||
_eo2[i] = valMin;
|
||||
}
|
||||
// seomthing has changed
|
||||
hasChanged = true; // forget (im)possible alpha=0
|
||||
}
|
||||
}
|
||||
// first find the limits on the alpha's
|
||||
if (bounds.isMinBounded(i))
|
||||
{
|
||||
objMin = std::max(objMin, bounds.minimum(i));
|
||||
}
|
||||
if (bounds.isMaxBounded(i))
|
||||
{
|
||||
objMax = std::min(objMax, bounds.maximum(i));
|
||||
}
|
||||
// then draw variables
|
||||
double median = (objMin+objMax)/2.0; // uniform within bounds
|
||||
// double median = (rmin+rmax)/2.0; // Bounce on bounds
|
||||
double valMin = objMin + (median-objMin)*rng.uniform();
|
||||
double valMax = median + (objMax-median)*rng.uniform();
|
||||
// don't always put large value in _eo1 - or what?
|
||||
if (rng.flip(0.5))
|
||||
{
|
||||
_eo1[i] = valMin;
|
||||
_eo2[i] = valMax;
|
||||
}
|
||||
else
|
||||
{
|
||||
_eo1[i] = valMax;
|
||||
_eo2[i] = valMin;
|
||||
}
|
||||
// seomthing has changed
|
||||
hasChanged = true; // forget (im)possible alpha=0
|
||||
}
|
||||
}
|
||||
|
||||
return hasChanged;
|
||||
}
|
||||
|
|
@ -452,7 +452,7 @@ template<class EOT> class eoHypercubeCrossover: public eoQuadOp<EOT>
|
|||
protected:
|
||||
eoRealVectorBounds & bounds;
|
||||
double alpha;
|
||||
double range; // == 1+2*alphaMin
|
||||
double range; // == 1+2*alphaMin
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -473,7 +473,7 @@ template<class EOT> class eoRealUXover: public eoQuadOp<EOT>
|
|||
eoRealUXover(const float& _preference = 0.5): preference(_preference)
|
||||
{
|
||||
if ( (_preference <= 0.0) || (_preference >= 1.0) )
|
||||
std::runtime_error("UxOver --> invalid preference");
|
||||
std::runtime_error("UxOver --> invalid preference");
|
||||
}
|
||||
|
||||
/// The class name.
|
||||
|
|
@ -488,19 +488,19 @@ template<class EOT> class eoRealUXover: public eoQuadOp<EOT>
|
|||
bool operator()(EOT& _eo1, EOT& _eo2)
|
||||
{
|
||||
if ( _eo1.size() != _eo2.size())
|
||||
std::runtime_error("UxOver --> chromosomes sizes don't match" );
|
||||
std::runtime_error("UxOver --> chromosomes sizes don't match" );
|
||||
bool changed = false;
|
||||
for (unsigned int i=0; i<_eo1.size(); i++)
|
||||
{
|
||||
if (rng.flip(preference))
|
||||
if (_eo1[i] != _eo2[i])
|
||||
{
|
||||
double tmp = _eo1[i];
|
||||
_eo1[i]=_eo2[i];
|
||||
_eo2[i] = tmp;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (rng.flip(preference))
|
||||
if (_eo1[i] != _eo2[i])
|
||||
{
|
||||
double tmp = _eo1[i];
|
||||
_eo1[i]=_eo2[i];
|
||||
_eo2[i] = tmp;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// eoSBXcross.h
|
||||
// (c) Maarten Keijzer 2000 - Marc Schoenauer 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -43,7 +43,7 @@ template<class EOT> class eoSBXCrossover: public eoQuadOp<EOT>
|
|||
* (Default) Constructor.
|
||||
* The bounds are initialized with the global object that says: no bounds.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
eoSBXCrossover(const double& _eta = 1.0) :
|
||||
bounds(eoDummyVectorNoBounds), eta(_eta), range(1) {}
|
||||
|
|
@ -54,7 +54,7 @@ template<class EOT> class eoSBXCrossover: public eoQuadOp<EOT>
|
|||
/**
|
||||
* Constructor with bounds
|
||||
* @param _bounds an eoRealVectorBounds that contains the bounds
|
||||
* @param _eta the amount of exploration OUTSIDE the parents
|
||||
* @param _eta the amount of exploration OUTSIDE the parents
|
||||
* as in BLX-alpha notation (Eshelman and Schaffer)
|
||||
* 0 == contractive application
|
||||
* Must be positive
|
||||
|
|
@ -62,8 +62,8 @@ template<class EOT> class eoSBXCrossover: public eoQuadOp<EOT>
|
|||
|
||||
|
||||
|
||||
eoSBXCrossover(eoRealVectorBounds & _bounds,
|
||||
const double& _eta = 1.0) :
|
||||
eoSBXCrossover(eoRealVectorBounds & _bounds,
|
||||
const double& _eta = 1.0) :
|
||||
bounds(_bounds), eta(_eta), range(1) {}
|
||||
|
||||
///////////////////////////////////////////////
|
||||
|
|
@ -76,14 +76,14 @@ template<class EOT> class eoSBXCrossover: public eoQuadOp<EOT>
|
|||
* eta, the SBX parameter
|
||||
*/
|
||||
|
||||
eoSBXCrossover(eoParser & _parser) :
|
||||
eoSBXCrossover(eoParser & _parser) :
|
||||
// First, decide whether the objective variables are bounded
|
||||
// Warning, must be the same keywords than other possible objectBounds elsewhere
|
||||
bounds (_parser.getORcreateParam(eoDummyVectorNoBounds, "objectBounds", "Bounds for variables", 'B', "Variation Operators").value()) ,
|
||||
// then get eta value
|
||||
eta (_parser.getORcreateParam(1.0, "eta", "SBX eta parameter", '\0', "Variation Operators").value()) ,
|
||||
range(1) {}
|
||||
|
||||
|
||||
|
||||
/// The class name.
|
||||
virtual std::string className() const { return "eoSBXCrossover"; }
|
||||
|
|
@ -91,47 +91,45 @@ template<class EOT> class eoSBXCrossover: public eoQuadOp<EOT>
|
|||
/*****************************************
|
||||
* SBX crossover - modifies both parents *
|
||||
* @param _eo1 The first parent *
|
||||
* @param _eo2 The first parent *
|
||||
* @param _eo2 The first parent *
|
||||
*****************************************/
|
||||
bool operator()(EOT& _eo1, EOT& _eo2)
|
||||
{
|
||||
unsigned i;
|
||||
double r1, r2, beta;
|
||||
|
||||
for (i=0; i<_eo1.size(); i++)
|
||||
{
|
||||
for (i=0; i<_eo1.size(); i++)
|
||||
{
|
||||
double u = rng.uniform(range) ;
|
||||
|
||||
if ( u <= 0.5 )
|
||||
beta = exp( (1/(eta+1))*log(2*u));
|
||||
if ( u <= 0.5 )
|
||||
beta = exp( (1/(eta+1))*log(2*u));
|
||||
else
|
||||
beta = exp((1/(eta+1))*log(1/(2*(1-u))));
|
||||
|
||||
|
||||
|
||||
r1=_eo1[i];
|
||||
r2=_eo2[i];
|
||||
_eo1[i] =0.5*((1+beta)*r1+(1-beta)*r2);
|
||||
_eo2[i] =0.5*((1-beta)*r1+(1+beta)*r2);
|
||||
|
||||
|
||||
if(!(bounds.isInBounds(i,_eo1[i])))
|
||||
bounds.foldsInBounds(i,_eo1[i]);
|
||||
if(!(bounds.isInBounds(i,_eo2[i])))
|
||||
bounds.foldsInBounds(i,_eo2[i]);
|
||||
beta = exp((1/(eta+1))*log(1/(2*(1-u))));
|
||||
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
r1=_eo1[i];
|
||||
r2=_eo2[i];
|
||||
_eo1[i] =0.5*((1+beta)*r1+(1-beta)*r2);
|
||||
_eo2[i] =0.5*((1-beta)*r1+(1+beta)*r2);
|
||||
|
||||
|
||||
if(!(bounds.isInBounds(i,_eo1[i])))
|
||||
bounds.foldsInBounds(i,_eo1[i]);
|
||||
if(!(bounds.isInBounds(i,_eo2[i])))
|
||||
bounds.foldsInBounds(i,_eo2[i]);
|
||||
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
eoRealVectorBounds & bounds;
|
||||
double eta;
|
||||
double range; // == 1
|
||||
double range; // == 1
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_algo_scalar_es.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains ***INSTANCIATED DEFINITIONS*** of select/replace fns
|
||||
* of the library for evolution of ***eoEs genotypes*** inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in src/es/es.h
|
||||
* while the TEMPLATIZED code is define in make_algo_scalar.h in the src/do dir
|
||||
*/
|
||||
|
|
@ -43,9 +43,9 @@
|
|||
// The templatized code
|
||||
#include <do/make_algo_scalar.h>
|
||||
// the instanciating EOType(s)
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
|
||||
/// The following function merely call the templatized do_* functions above
|
||||
|
||||
|
|
@ -82,4 +82,3 @@ eoAlgo<eoEsFull<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoS
|
|||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_algo_scalar_real.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains ***INSTANCIATED DEFINITIONS*** of select/replace fns
|
||||
* of the library for evolution of ***eoReal*** inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in src/es/real.h
|
||||
* while the TEMPLATIZED code is define in make_algo_scalar.h in the src/do dir
|
||||
*/
|
||||
|
|
@ -58,4 +58,3 @@ eoAlgo<eoReal<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoSta
|
|||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_checkpoint_es.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains ***INSTANCIATED DEFINITIONS*** of checkpoint fns
|
||||
* of the library for evolution of ***ES genotypes*** inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in src/es/es.h
|
||||
* while the TEMPLATIZED code is define in make_checkpoint.h in the src/do dir
|
||||
*/
|
||||
|
|
@ -43,11 +43,11 @@
|
|||
// The templatized code
|
||||
#include <do/make_checkpoint.h>
|
||||
// the instanciating EOType(s)
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
|
||||
/// The following function merely call the templatized do_* functions
|
||||
/// The following function merely call the templatized do_* functions
|
||||
|
||||
// checkpoint
|
||||
/////////////
|
||||
|
|
@ -55,7 +55,7 @@ eoCheckPoint<eoEsSimple<double> >& make_checkpoint(eoParser& _parser, eoState& _
|
|||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
eoCheckPoint<eoEsSimple<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoEsSimple<eoMinimizingFitness> >& _eval, eoContinue<eoEsSimple<eoMinimizingFitness> >& _continue)
|
||||
eoCheckPoint<eoEsSimple<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoEsSimple<eoMinimizingFitness> >& _eval, eoContinue<eoEsSimple<eoMinimizingFitness> >& _continue)
|
||||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ eoCheckPoint<eoEsStdev<double> >& make_checkpoint(eoParser& _parser, eoState& _s
|
|||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
eoCheckPoint<eoEsStdev<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoEsStdev<eoMinimizingFitness> >& _eval, eoContinue<eoEsStdev<eoMinimizingFitness> >& _continue)
|
||||
eoCheckPoint<eoEsStdev<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoEsStdev<eoMinimizingFitness> >& _eval, eoContinue<eoEsStdev<eoMinimizingFitness> >& _continue)
|
||||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
|
@ -75,9 +75,7 @@ eoCheckPoint<eoEsFull<double> >& make_checkpoint(eoParser& _parser, eoState& _st
|
|||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
eoCheckPoint<eoEsFull<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoEsFull<eoMinimizingFitness> >& _eval, eoContinue<eoEsFull<eoMinimizingFitness> >& _continue)
|
||||
eoCheckPoint<eoEsFull<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoEsFull<eoMinimizingFitness> >& _eval, eoContinue<eoEsFull<eoMinimizingFitness> >& _continue)
|
||||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_checkpoint_real.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains ***INSTANCIATED DEFINITIONS*** of checkpoint fns
|
||||
* of the library for evolution of ***eoReal*** inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in src/es/real.h
|
||||
* while the TEMPLATIZED code is define in make_checkpoint.h in the src/do dir
|
||||
*/
|
||||
|
|
@ -45,7 +45,7 @@
|
|||
// the instanciating EOType
|
||||
#include <es/eoReal.h>
|
||||
|
||||
/// The following function merely call the templatized do_* functions
|
||||
/// The following function merely call the templatized do_* functions
|
||||
|
||||
// checkpoint
|
||||
/////////////
|
||||
|
|
@ -53,9 +53,7 @@ eoCheckPoint<eoReal<double> >& make_checkpoint(eoParser& _parser, eoState& _stat
|
|||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
eoCheckPoint<eoReal<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoReal<eoMinimizingFitness> >& _eval, eoContinue<eoReal<eoMinimizingFitness> >& _continue)
|
||||
eoCheckPoint<eoReal<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoReal<eoMinimizingFitness> >& _eval, eoContinue<eoReal<eoMinimizingFitness> >& _continue)
|
||||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_continue_es.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains ***INSTANCIATED DEFINITIONS*** of continuator fns
|
||||
* of the library for evolution of ***ES genotypes*** inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in src/es/es.h
|
||||
* while the TEMPLATIZED code is define in make_continue.h in the src/do dir
|
||||
*/
|
||||
|
|
@ -43,9 +43,9 @@
|
|||
// The templatized code
|
||||
#include <do/make_continue.h>
|
||||
// the instanciating EOType(s)
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
|
||||
/// The following function merely call the templatized do_* functions
|
||||
|
||||
|
|
@ -79,5 +79,3 @@ eoContinue<eoEsFull<eoMinimizingFitness> >& make_continue(eoParser& _parser, eoS
|
|||
{
|
||||
return do_make_continue(_parser, _state, _eval);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_continue_real.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains ***INSTANCIATED DEFINITIONS*** of continuator fns
|
||||
* of the library for evolution of ***REAL vectors*** inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in src/es/real.h
|
||||
* while the TEMPLATIZED code is define in make_continue.h in the src/do dir
|
||||
*/
|
||||
|
|
@ -57,5 +57,3 @@ eoContinue<eoReal<eoMinimizingFitness> >& make_continue(eoParser& _parser, eoSta
|
|||
{
|
||||
return do_make_continue(_parser, _state, _eval);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// es.h
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -24,20 +24,20 @@
|
|||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** This file contains all ***INSTANCIATED*** declarations of all components
|
||||
/** This file contains all ***INSTANCIATED*** declarations of all components
|
||||
* of the library for ***ES-like gnptype*** evolution inside EO.
|
||||
* It should be included in the file that calls any of the corresponding fns
|
||||
*
|
||||
* The corresponding ***INSTANCIATED*** definitions are contained in
|
||||
* the different .cpp files in the src/es dir,
|
||||
* The corresponding ***INSTANCIATED*** definitions are contained in
|
||||
* the different .cpp files in the src/es dir,
|
||||
* while the TEMPLATIZED code is define in the different make_XXX.h files
|
||||
* either in hte src/do dir for representation independant functions,
|
||||
* either in hte src/do dir for representation independant functions,
|
||||
* or in the src/es dir for representation dependent stuff.
|
||||
*
|
||||
* See also real.h for the similar declarations of eoReal genotypes
|
||||
* See also real.h for the similar declarations of eoReal genotypes
|
||||
* i.e. ***without*** mutation parameters attached to individuals
|
||||
*
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* just declarations
|
||||
*/
|
||||
|
||||
|
|
@ -54,9 +54,9 @@
|
|||
#include <eoPop.h>
|
||||
#include <utils/eoDistance.h>
|
||||
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
|
||||
// include all similar declaration for eoReal - i.e. real-valued genotyes
|
||||
// without self-adaptation
|
||||
|
|
@ -68,7 +68,7 @@
|
|||
|
||||
//Representation dependent - rewrite everything anew for each representation
|
||||
//////////////////////////
|
||||
// the genotypes
|
||||
// the genotypes
|
||||
eoRealInitBounded<eoEsSimple<double> > & make_genotype(eoParser& _parser, eoState& _state, eoEsSimple<double> _eo);
|
||||
eoRealInitBounded<eoEsSimple<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoEsSimple<eoMinimizingFitness> _eo);
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ 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");
|
||||
's', "Genotype Initialization");
|
||||
// check for %
|
||||
bool to_scale = false;
|
||||
size_t pos = sigmaParam.value().find('%');
|
||||
|
|
|
|||
|
|
@ -97,23 +97,23 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
|
|||
std::vector<double> v;
|
||||
std::vector<std::string>::iterator it;
|
||||
for (it=ppBounds.second.begin(); it<ppBounds.second.end(); it++)
|
||||
{
|
||||
istrstream is(it->c_str());
|
||||
double r;
|
||||
is >> r;
|
||||
v.push_back(r);
|
||||
}
|
||||
{
|
||||
istrstream is(it->c_str());
|
||||
double r;
|
||||
is >> r;
|
||||
v.push_back(r);
|
||||
}
|
||||
// now create the eoRealVectorBounds object
|
||||
if (v.size() == 2) // a min and a max for all variables
|
||||
ptBounds = new eoRealVectorBounds(vecSize, v[0], v[1]);
|
||||
else // no time now
|
||||
throw std::runtime_error("Sorry, only unique bounds for all variables implemented at the moment. Come back later");
|
||||
ptBounds = new eoRealVectorBounds(vecSize, v[0], v[1]);
|
||||
else // no time now
|
||||
throw std::runtime_error("Sorry, only unique bounds for all variables implemented at the moment. Come back later");
|
||||
// we need to give ownership of this pointer to somebody
|
||||
/////////// end of temporary code
|
||||
}
|
||||
else // no param for bounds was given
|
||||
else // no param for bounds was given
|
||||
ptBounds = new eoRealVectorNoBounds(vecSize); // DON'T USE eoDummyVectorNoBounds
|
||||
// as it does not have any dimension
|
||||
// as it does not have any dimension
|
||||
|
||||
// this is a temporary version(!),
|
||||
// while Maarten codes the full tree-structured general operator input
|
||||
|
|
@ -185,7 +185,7 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
|
|||
_state.storeFunctor(ptQuad);
|
||||
ptCombinedQuadOp = new eoPropCombinedQuadOp<EOT>(*ptQuad, segmentRateParam.value());
|
||||
|
||||
// arithmetic crossover
|
||||
// arithmetic crossover
|
||||
ptQuad = new eoArithmeticCrossover<EOT>(*ptBounds);
|
||||
_state.storeFunctor(ptQuad);
|
||||
ptCombinedQuadOp->add(*ptQuad, arithmeticRateParam.value());
|
||||
|
|
@ -258,7 +258,7 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
|
|||
// create the CombinedMonOp
|
||||
ptCombinedMonOp = new eoPropCombinedMonOp<EOT>(*ptMon, uniformMutRateParam.value());
|
||||
|
||||
// mutate exactly 1 component (uniformly) per individual
|
||||
// mutate exactly 1 component (uniformly) per individual
|
||||
ptMon = new eoDetUniformMutation<EOT>(*ptBounds, epsilonParam.value());
|
||||
_state.storeFunctor(ptMon);
|
||||
ptCombinedMonOp->add(*ptMon, detMutRateParam.value());
|
||||
|
|
@ -289,7 +289,7 @@ eoGenOp<EOT> & do_make_op(eoParameterLoader& _parser, eoState& _state, eoInit<EO
|
|||
// now the sequential
|
||||
eoSequentialOp<EOT> *op = new eoSequentialOp<EOT>;
|
||||
_state.storeFunctor(op);
|
||||
op->add(*cross, 1.0); // always crossover (but clone with prob 1-pCross
|
||||
op->add(*cross, 1.0); // always crossover (but clone with prob 1-pCross
|
||||
op->add(*ptCombinedMonOp, pMutParam.value());
|
||||
|
||||
// that's it!
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_op_real.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains ***INSTANCIATED DEFINITIONS*** of operators fns
|
||||
* of the library for ***eoReal*** evolution inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in es.h in src/es dir
|
||||
* while the TEMPLATIZED code is define in make_op.h in the es dir
|
||||
*
|
||||
|
|
@ -77,4 +77,3 @@ eoGenOp<eoEsFull<eoMinimizingFitness> >& make_op(eoParser& _parser, eoState& _s
|
|||
{
|
||||
return do_make_op(_parser, _state, _init);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -154,10 +154,10 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
|
|||
if (crossTypeParam.value() == std::string("global"))
|
||||
ptCross = new eoEsGlobalXover<EOT>(*ptObjAtomCross, *ptStdevAtomCross);
|
||||
else if (crossTypeParam.value() == std::string("standard"))
|
||||
{ // using a standard eoBinOp, but wrap it into an eoGenOp
|
||||
{ // using a standard eoBinOp, but wrap it into an eoGenOp
|
||||
eoBinOp<EOT> & crossTmp = _state.storeFunctor(
|
||||
new eoEsStandardXover<EOT>(*ptObjAtomCross, *ptStdevAtomCross)
|
||||
);
|
||||
new eoEsStandardXover<EOT>(*ptObjAtomCross, *ptStdevAtomCross)
|
||||
);
|
||||
ptCross = new eoBinGenOp<EOT>(crossTmp);
|
||||
}
|
||||
else throw std::runtime_error("Invalide Object variable crossover type");
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_op_real.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains ***INSTANCIATED DEFINITIONS*** of operators fns
|
||||
* of the library for ***eoReal*** evolution inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in es.h in src/es dir
|
||||
* while the TEMPLATIZED code is define in make_op.h in the es dir
|
||||
*
|
||||
|
|
|
|||
|
|
@ -168,12 +168,12 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
|
|||
_state.storeFunctor(ptQuad);
|
||||
ptCombinedQuadOp = new eoPropCombinedQuadOp<EOT>(*ptQuad, segmentRateParam.value());
|
||||
|
||||
// hypercube crossover
|
||||
// hypercube crossover
|
||||
ptQuad = new eoHypercubeCrossover<EOT>(boundsParam.value(), alphaParam.value());
|
||||
_state.storeFunctor(ptQuad);
|
||||
ptCombinedQuadOp->add(*ptQuad, hypercubeRateParam.value());
|
||||
|
||||
// uniform crossover
|
||||
// uniform crossover
|
||||
ptQuad = new eoRealUXover<EOT>();
|
||||
_state.storeFunctor(ptQuad);
|
||||
ptCombinedQuadOp->add(*ptQuad, uxoverRateParam.value());
|
||||
|
|
@ -249,7 +249,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
|
|||
// create the CombinedMonOp
|
||||
ptCombinedMonOp = new eoPropCombinedMonOp<EOT>(*ptMon, uniformMutRateParam.value());
|
||||
|
||||
// mutate exactly 1 component (uniformly) per individual
|
||||
// mutate exactly 1 component (uniformly) per individual
|
||||
ptMon = new eoDetUniformMutation<EOT>(boundsParam.value(), epsilonParam.value());
|
||||
_state.storeFunctor(ptMon);
|
||||
ptCombinedMonOp->add(*ptMon, detMutRateParam.value());
|
||||
|
|
@ -279,7 +279,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<
|
|||
|
||||
// now the sequential
|
||||
eoSequentialOp<EOT> & op = _state.storeFunctor(new eoSequentialOp<EOT>);
|
||||
op.add(*cross, 1.0); // always crossover (but clone with prob 1-pCross
|
||||
op.add(*cross, 1.0); // always crossover (but clone with prob 1-pCross
|
||||
op.add(*ptCombinedMonOp, pMutParam.value());
|
||||
|
||||
// that's it!
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_pop_es.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains ***INSTANCIATED DEFINITIONS*** of pop. init. fns
|
||||
* of the library for evolution of ***ES genotypes*** indis inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in src/es/es.h
|
||||
* while the TEMPLATIZED code is define in make_pop.h in the src/do dir
|
||||
*/
|
||||
|
|
@ -43,9 +43,9 @@
|
|||
// The templatized code
|
||||
#include <do/make_pop.h>
|
||||
// the instanciating EOType(s)
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
|
||||
/// The following function merely call the templatized do_* functions above
|
||||
|
||||
|
|
@ -82,5 +82,3 @@ eoPop<eoEsFull<eoMinimizingFitness> >& make_pop(eoParser& _parser, eoState& _st
|
|||
{
|
||||
return do_make_pop(_parser, _state, _init);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_pop_real.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains ***INSTANCIATED DEFINITIONS*** of pop. init. fns
|
||||
* of the library for evolution of ***eoReal*** indis inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in src/es/real.h
|
||||
* while the TEMPLATIZED code is define in make_pop.h in the src/do dir
|
||||
*/
|
||||
|
|
@ -58,5 +58,3 @@ eoPop<eoReal<eoMinimizingFitness> >& make_pop(eoParser& _parser, eoState& _stat
|
|||
{
|
||||
return do_make_pop(_parser, _state, _init);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// real.h
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -24,20 +24,20 @@
|
|||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** This file contains all ***INSTANCIATED*** declarations of all components
|
||||
/** This file contains all ***INSTANCIATED*** declarations of all components
|
||||
* of the library for ***std::vector<RealValues>*** evolution inside EO.
|
||||
* It should be included in the file that calls any of the corresponding fns
|
||||
*
|
||||
* The corresponding ***INSTANCIATED*** definitions are contained in
|
||||
* the different .cpp files in the src/es dir,
|
||||
* The corresponding ***INSTANCIATED*** definitions are contained in
|
||||
* the different .cpp files in the src/es dir,
|
||||
* while the TEMPLATIZED code is define in the different make_XXX.h files
|
||||
* either in hte src/do dir for representation independant functions,
|
||||
* either in hte src/do dir for representation independant functions,
|
||||
* or in the src/es dir for representation dependent stuff.
|
||||
*
|
||||
* See also es.h for the similar declarations of ES-like genotypes
|
||||
* See also es.h for the similar declarations of ES-like genotypes
|
||||
* i.e. ***with*** mutation parameters attached to individuals
|
||||
*
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* just declarations
|
||||
*/
|
||||
|
||||
|
|
@ -64,7 +64,7 @@
|
|||
/** @addtogroup Builders
|
||||
* @{
|
||||
*/
|
||||
// the genotypes
|
||||
// the genotypes
|
||||
eoRealInitBounded<eoReal<double> > & make_genotype(eoParser& _parser, eoState& _state, eoReal<double> _eo);
|
||||
eoRealInitBounded<eoReal<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoReal<eoMinimizingFitness> _eo);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_run_es.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains ***INSTANCIATED DEFINITIONS*** of run funs
|
||||
* of the library for evolution of ***ES genotypes*** inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in src/es/es.h
|
||||
* while the TEMPLATIZED code is define in make_run.h in the src/do dir
|
||||
*/
|
||||
|
|
@ -43,9 +43,9 @@
|
|||
// The templatized code
|
||||
#include <do/make_run.h>
|
||||
// the instanciating EOType(s)
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
#include <es/eoEsSimple.h> // one Sigma per individual
|
||||
#include <es/eoEsStdev.h> // one sigmal per object variable
|
||||
#include <es/eoEsFull.h> // full correlation matrix per indi
|
||||
// the instanciating fitnesses
|
||||
#include <eoScalarFitness.h>
|
||||
|
||||
|
|
@ -84,4 +84,3 @@ void run_ea(eoAlgo<eoEsFull<eoMinimizingFitness> >& _ga, eoPop<eoEsFull<eoMinimi
|
|||
{
|
||||
do_run(_ga, _pop);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_run_real.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
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
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains ***INSTANCIATED DEFINITIONS*** of run funs
|
||||
* of the library for evolution of ***eoReal*** inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in src/es/real.h
|
||||
* while the TEMPLATIZED code is define in make_run.h in the src/do dir
|
||||
*/
|
||||
|
|
@ -60,4 +60,3 @@ void run_ea(eoAlgo<eoReal<eoMinimizingFitness> >& _ga, eoPop<eoReal<eoMinimizing
|
|||
{
|
||||
do_run(_ga, _pop);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@ class lower_triangular_matrix {
|
|||
public:
|
||||
|
||||
lower_triangular_matrix(unsigned n_ = 0) : n(n_), data(n * (n+1) / 2) {};
|
||||
|
||||
|
||||
void resize(unsigned n_) {
|
||||
n = n_;
|
||||
data.resize(n*(n+1)/2);
|
||||
n = n_;
|
||||
data.resize(n*(n+1)/2);
|
||||
}
|
||||
|
||||
|
||||
std::vector<double>::iterator operator[](unsigned i) { return data.begin() + i * (i+1) / 2; }
|
||||
std::vector<double>::const_iterator operator[](unsigned i) const { return data.begin() + i*(i+1)/2; }
|
||||
};
|
||||
|
|
@ -32,15 +32,14 @@ class square_matrix {
|
|||
public:
|
||||
|
||||
square_matrix(unsigned n_ = 0) : n(n_), data(n * n) {};
|
||||
|
||||
|
||||
void resize(unsigned n_) {
|
||||
n = n_;
|
||||
data.resize(n*n);
|
||||
n = n_;
|
||||
data.resize(n*n);
|
||||
}
|
||||
|
||||
|
||||
std::vector<double>::iterator operator[](unsigned i) { return data.begin() + i * n; }
|
||||
std::vector<double>::const_iterator operator[](unsigned i) const { return data.begin() + i*n; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue