39 this->numOutputs=config.getintvalue(
"numberOfActions");
40 this->devBase=config.getDoubleValue(
"deviation");
41 this->monteCarlo=config.getintvalue(
"MonteCarlo");
43 statelessParameters.resize(numOutputs);
44 for(
int i=0;i<numOutputs;i++)
45 statelessParameters[i]=rand()*1.0/RAND_MAX;
50 AnnealEvoMember::~AnnealEvoMember()
54 void AnnealEvoMember::mutate(std::tr1::ranlux64_base_01 *eng,
double T){
57 std::tr1::uniform_real<double> unif(0, 1);
61 double dev = devBase * T / 100.0;
62 std::tr1::normal_distribution<double> normal(0, dev);
63 for(std::size_t i=0;i<statelessParameters.size();i++)
72 double mutAmount = normal(*eng);
74 newParam= statelessParameters[i] + mutAmount;
78 statelessParameters[i] = 0.0;
79 else if(newParam > 1.0)
80 statelessParameters[i] = 1.0;
82 statelessParameters[i] =newParam;
91 this->statelessParameters=otherMember->statelessParameters;
95 void AnnealEvoMember::saveToFile(
const char * outputFilename)
98 ofstream ss(outputFilename);
99 for(std::size_t i=0;i<statelessParameters.size();i++)
101 ss<<statelessParameters[i];
102 if(i!=statelessParameters.size()-1)
109 void AnnealEvoMember::loadFromFile(
const char * outputFilename)
112 ifstream ss(outputFilename);
125 if(getline ( ss, value,
',' )>0)
128 statelessParameters[i++]=atof(value.c_str());
135 cout <<
"File of name " << outputFilename <<
" does not exist" << std::endl;
136 cout <<
"Try turning learning on in config.ini to generate parameters" << std::endl;
137 throw std::invalid_argument(
"Parameter file does not exist");
Contains the definition of class AnnealEvoMember Adapting NeuroEvolution to do Simulated Annealing...