1#include "SymbRegEvalOp.h"
2#include "./cartesian/Cartesian.h"
4void SymbRegEvalOp::addConstants(uint nConstants)
6 for(uint i = 0; i < inputs.size(); i++) {
7 for(uint j = 0; j < nConstants; j++) {
8 inputs[i].push_back(cartesian::Cartesian::static_random_double(-10.0,10.0));
16 stateP->getRegistry()->registerEntry(
"training.infile", (voidP)
new (std::string), ECF::STRING);
17 stateP->getRegistry()->registerEntry(
"expression.infile", (voidP)
new(std::string), ECF::STRING);
18 stateP->getRegistry()->registerEntry(
"softtarget", (voidP)
new(std::string), ECF::STRING);
19 stateP->getRegistry()->registerEntry(
"softtarget.gamma", (voidP)
new(std::string), ECF::STRING);
20 stateP->getRegistry()->registerEntry(
"softtarget.beta", (voidP)
new(std::string), ECF::STRING);
25 if(!stateP->getRegistry()->isModified(
"expression.infile")) {
26 ECF_LOG_ERROR(stateP,
"Expression is not registered as a parameter. Register a path to a expression in parameters.txt file.");
29 voidP vp1 = stateP->getRegistry()->getEntry(
"expression.infile");
30 std::string path1 = *((std::string*)vp1.get());
31 std::ifstream in_file(path1.c_str());
33 std::cerr <<
"Parser could not load a expression file: " << path1 <<
'\n';
37 getline(in_file,line);
39 this->equation = line;
40 if(!stateP->getRegistry()->isModified(
"training.infile")) {
41 ECF_LOG_ERROR(stateP,
"Error: no input file defined for arguments and function values.");
44 vp1 = stateP->getRegistry()->getEntry(
"training.infile");
45 path1 = *((std::string*)vp1.get());
46 std::ifstream in_file2(path1.c_str());
48 std::cerr <<
"Could not load a file which defines arguments / function values for given function.\n";
51 for(std::string line2; getline(in_file2,line2);) {
52 std::pair<std::vector<double>,
double> result = utility::parseArgumentsAndFunctionValues(line2);
53 this->inputs.push_back(result.first);
54 this->output.push_back(result.second);
56 if(stateP->getRegistry()->isModified(
"softtarget")) {
57 voidP vpS = stateP->getRegistry()->getEntry(
"softtarget");
58 std::string sa = *((std::string*)vpS.get());
59 if(sa ==
"1" || sa ==
"yes" || sa ==
"Yes" || sa ==
"true") {
61 ECF_LOG(stateP,0,
"Soft target regularization is used.");
62 if(!stateP->getRegistry()->isModified(
"softtarget.beta")) {
63 ECF_LOG_ERROR(stateP,
"Could not find beta factor for softtarget. Define softtarget.beta entry in registry.\n");
67 voidP vpSBeta = stateP->getRegistry()->getEntry(
"softtarget.beta");
68 std::string vbeta = *((std::string*)vpSBeta.get());
70 softTargetBeta = str2dbl(vbeta);
71 }
catch(std::exception& ex) {
72 ECF_LOG_ERROR(stateP,
"Soft target beta is not a number convertible to double.\n");
76 if(!stateP->getRegistry()->isModified(
"softtarget.gamma")) {
77 ECF_LOG_ERROR(stateP,
"Could not find gamma factor for softtarget. Define softtarget.gamma entry in registry.\n");
81 voidP vpSGamma = stateP->getRegistry()->getEntry(
"softtarget.gamma");
82 std::string vgamma = *((std::string*)vpSGamma.get());
84 softTargetGamma = str2dbl(vgamma);
85 }
catch(std::exception& ex) {
86 ECF_LOG_ERROR(stateP,
"Soft target gamma is not a number convertible to double.\n");
100 std::vector<double> calculatedOutputs;
101 for(uint i = 0; i < inputs.size(); i++) {
102 std::vector<double> results;
103 cartesian->
evaluate(inputs[i], results);
104 calculatedOutputs.push_back(results[0]);
108 MSE = utility::rootMeanSquareError(output, calculatedOutputs);
110 if (cartesian->
state_->getGenerationNo() > 0) {
111 if (kappaOutput.size() != calculatedOutputs.size()) {
112 std::cout <<
"Theta output i calculated output nemaju jednake dimenzije.\n";
114 for (uint j = 0; j < kappaOutput.size(); j++) {
115 kappaOutput[j] = softTargetBeta * kappaOutput[j] + (1 - softTargetBeta) * calculatedOutputs[j];
117 if (kappaOutput.size() != thetaOutput.size()) {
118 std::cout <<
"Kappa output i Theta output nemaju jednake dimenzije.\n";
120 for (uint j = 0; j < thetaOutput.size(); j++) {
121 thetaOutput[j] = softTargetGamma * kappaOutput[j] + (1 - softTargetGamma) * output[j];
124 kappaOutput = calculatedOutputs;
125 thetaOutput = output;
127 MSE = utility::rootMeanSquareError(thetaOutput, calculatedOutputs);
129 fitness->setValue(MSE);
Fitness for minimization problems.
FitnessP evaluate(IndividualP individual)
Evaluate a single individual. Method must create and return a Fitness object.
void registerParameters(StateP stateP)
Register evaluator parameters. Called before EvaluateOp::initialize method.
bool initialize(StateP)
Initialize the evaluator. Called before first evaluation occurs.
void evaluate(const vector< double > &inputData, vector< double > &results)
StateP state_
local copy of state
uint nConstants
number of input constants