1#include "MultipleClassEvalOp.h"
2#include "./cartesian/Cartesian.h"
3#include "utility/fileparser.h"
4#include "./utility/measures.h"
5#include "./utility/utility.h"
6#include <boost/algorithm/string.hpp>
10 stateP->getRegistry()->registerEntry(
"training.infile", (voidP)
new (std::string), ECF::STRING);
11 stateP->getRegistry()->registerEntry(
"testing.infile", (voidP)
new (std::string), ECF::STRING);
12 stateP->getRegistry()->registerEntry(
"measure", (voidP)
new (std::string), ECF::STRING);
13 stateP->getRegistry()->registerEntry(
"hasID", (voidP)
new (std::string), ECF::STRING);
18 if(!stateP->getRegistry()->isModified(
"training.infile")) {
19 ECF_LOG_ERROR(stateP,
"Error: no input file defined for training");
22 if(!stateP->getRegistry()->isModified(
"testing.infile")) {
23 ECF_LOG_ERROR(stateP,
"Error: no input file defined for testing");
26 if(!stateP->getRegistry()->isModified(
"measure")) {
27 ECF_LOG(stateP,0,
"Default measure of accuracy is used.");
28 measureUsed =
"accuracy";
31 voidP vpM = stateP->getRegistry()->getEntry(
"measure");
32 measureUsed = *((std::string*)vpM.get());
33 boost::algorithm::to_lower(measureUsed);
35 if(!stateP->getRegistry()->isModified(
"hasID")) {
39 voidP vp1 = stateP->getRegistry()->getEntry(
"training.infile");
40 std::string path1 = *((std::string*)vp1.get());
41 std::vector<std::string> parsedTrainingCSV = utility::parseCSVFromFile(path1);
42 PairAllFeaturesAllLabels ioTrainingPair = utility::parseStringIntoFeaturesAndLabels(parsedTrainingCSV, leadsWithId);
43 trainingInput = ioTrainingPair.first;
44 trainingOutputs = ioTrainingPair.second;
47 voidP vp2 = stateP->getRegistry()->getEntry(
"testing.infile");
48 std::string path2 = *((std::string*)vp2.get());
49 std::vector<std::string> parsedTestCSV = utility::parseCSVFromFile(path2);
50 PairAllFeaturesAllLabels ioTestPair = utility::parseStringIntoFeaturesAndLabels(parsedTestCSV, leadsWithId);
51 testingInput = ioTestPair.first;
52 testingOutputs = ioTestPair.second;
54 std::set<uint> distinct;
55 for(uint i = 0; i < trainingOutputs.size(); i++) {
56 distinct.insert(trainingOutputs[i]);
58 numberOfDifferentClasses = distinct.size();
60 if(stateP->getRegistry()->isModified(
"softtarget")) {
61 voidP vpS = stateP->getRegistry()->getEntry(
"softtarget");
62 std::string sa = *((std::string*)vpS.get());
63 if(sa ==
"1" || sa ==
"yes" || sa ==
"Yes" || sa ==
"true") {
65 ECF_LOG(stateP,0,
"Soft target regularization is used.");
66 if(!stateP->getRegistry()->isModified(
"softtarget.beta")) {
67 ECF_LOG_ERROR(stateP,
"Could not find beta factor for softtarget. Define softtarget.beta entry in registry.\n");
71 voidP vpSBeta = stateP->getRegistry()->getEntry(
"softtarget.beta");
72 std::string vbeta = *((std::string*)vpSBeta.get());
74 softTargetBeta = str2dbl(vbeta);
75 }
catch(std::exception& ex) {
76 ECF_LOG_ERROR(stateP,
"Soft target beta is not a number convertible to double.\n");
80 if(!stateP->getRegistry()->isModified(
"softtarget.gamma")) {
81 ECF_LOG_ERROR(stateP,
"Could not find gamma factor for softtarget. Define softtarget.gamma entry in registry.\n");
85 voidP vpSGamma = stateP->getRegistry()->getEntry(
"softtarget.gamma");
86 std::string vgamma = *((std::string*)vpSGamma.get());
88 softTargetGamma = str2dbl(vgamma);
89 }
catch(std::exception& ex) {
90 ECF_LOG_ERROR(stateP,
"Soft target gamma is not a number convertible to double.\n");
104 std::vector<std::vector<uint> > confusionMatrix(numberOfDifferentClasses, std::vector<uint>(numberOfDifferentClasses,0));
106 for(uint i = 0; i < trainingInput.size(); i++) {
107 std::vector<double> results;
108 cartesian->
evaluate(trainingInput[i], results);
109 confusionMatrix[utility::vectorArgmax(results)][trainingOutputs[i]]++;
111 double valueOfFitness = utility::returnConfusionMatrixResult(confusionMatrix,trainingInput.size(),measureUsed);
112 fitness->setValue(valueOfFitness);
Fitness for maximization problems.
bool initialize(StateP stateP)
Initialize the evaluator. Called before first evaluation occurs.
void registerParameters(StateP stateP)
Register evaluator parameters. Called before EvaluateOp::initialize method.
FitnessP evaluate(IndividualP individual)
Evaluate a single individual. Method must create and return a Fitness object.
void evaluate(const vector< double > &inputData, vector< double > &results)