ECF 1.5
GEPChromosomeMutGauss.cpp
1#include "GEPChromosomeMutGauss.h"
2
3namespace GEPChromosome{
5 {
6 myGenotype_->registerParameter(state, "mut.gauss", (voidP) new double(0), ECF::DOUBLE);
7 }
8
10 {
11 voidP sptr = myGenotype_->getParameterValue(state, "mut.gauss");
12 probability_ = *((double*)sptr.get());
13 engine_.seed((uint)time(NULL));
14 return true;
15 }
16
17 bool GEPChromosomeMutGauss::mutate(GenotypeP gene){
18 GEPChromosome* chr = (GEPChromosome*)(gene.get());
19 if (chr->dcLength > 0){
20 // mutate a single random point in the Dc domain by adding Gaussian noise to it
21 // Select a random gene
22 uint iGene = state_->getRandomizer()->getRandomInteger(0, chr->genes - 1);
23 uint geneOffset = iGene * chr->geneLength;
24 uint constOffset = geneOffset + chr->headLength + chr->tailLength; // this is where the Dc of the selected gene begins
25 // Select a random point in the Dc tail
26 uint iPoint = constOffset + state_->getRandomizer()->getRandomInteger(0, (uint)(chr->dcLength) - 1);
27
28 double oldValue;
29 Tree::PrimitiveP oldPrim = chr->at(iPoint)->primitive_;
30 chr->at(iPoint)->primitive_->getValue(&oldValue);
31 std::string oldName = chr->at(iPoint)->primitive_->getName();
32
33 // generate Gauss noise offset and add it
34 boost::normal_distribution<double> N(0, 1);
35 double offset = N.operator () < boost::lagged_fibonacci607 > (engine_);
36 double newValue = oldValue + offset;
37
38 // change double ERC value and name
39 std::stringstream ss;
40 ss << newValue;
41 std::string newName;
42 ss >> newName;
43 newName = DBL_PREFIX + newName;
44
45 oldPrim->setName(newName);
46 oldPrim->setValue(&newValue);
47 // print result
48 std::stringstream log;
49 log << "GEPMutGauss successful (oldNode = " << oldName << ", newNode = " << newName << ")";
50 ECF_LOG(state_, 5, log.str());
51 }
52 return true;
53 }
54}
GEPChromosome class - implements genotype as a Gene Expression Programming chromosome.
Definition: GEPChromosome.h:33
bool mutate(GenotypeP gene)
Performs mutation of a genotype object. The genotype object must be initialized!
bool initialize(StateP state)
Initialize mutation operator. Called before first mutation operation.
void registerParameters(StateP state)
Register parameters with the system. Called before MutationOp::initialize.
double probability_
probability of usage of this mutation operator
Definition: Mutation.h:40
GenotypeP myGenotype_
pointer to the Genotype that defines this MutationOp
Definition: Mutation.h:41