ECF 1.5
ClassifierParams.h
1#ifndef ClassifierParams_h
2#define ClassifierParams_h
3
4#include "../Genotype.h"
5#include<sstream>
6
11class ClassifierParams : public Genotype {
12private:
13
14public:
15 double p_; //reward prediction
16 double eps_; //reward prediction error
17 double F_; //fitness
18
19 double as_; //action set size estimate
20 unsigned long long int ts_; //time stamp
21 double exp_; //experience
22 int num_; //numerosity
23
24 ClassifierParams(double p, double eps, double F) {
25 this->p_ = p;
26 this->eps_ = eps;
27 this->F_ = F;
28
29 this->as_ = 1;
30 this->num_ = 1;
31 this->exp_ = 0;
32 this->ts_ = 0;
33 name_ = "ClassifierParams";
34 }
35 virtual ~ClassifierParams()
36 { }
37
38 void registerParameters(StateP state)
39 {
40 registerParameter(state, "fitness", (voidP) new double(0), ECF::DOUBLE);
41 registerParameter(state, "error", (voidP) new double(0), ECF::DOUBLE);
42 registerParameter(state, "prediction", (voidP) new double(0), ECF::DOUBLE);
43
44 }
45
46 virtual bool initialize(StateP state) {
47
48 voidP vp = getParameterValue(state, "fitness");
49 F_ = *((double*) vp.get());
50 vp = getParameterValue(state, "prediction");
51 p_ = *((double*) vp.get());
52 vp = getParameterValue(state, "error");
53 eps_ = *((double*) vp.get());
54
55 return true;
56 }
57
58 virtual Genotype* copy() {
59
60 ClassifierParams *newObject = new ClassifierParams(*this);
61 return newObject;
62 }
63
64 virtual std::vector<CrossoverOpP> getCrossoverOp() {
65 std::vector<CrossoverOpP> vCrossOp;
66 return vCrossOp;
67 }
68
69 virtual std::vector<MutationOpP> getMutationOp() {
70 std::vector<MutationOpP> vMutOp;
71 return vMutOp;
72 }
73
74 virtual void read(XMLNode& node) {
75 std::stringstream ss;
76 ss << node.getAttribute("prediction");
77 ss >> p_;
78
79 ss.str("");
80 ss << node.getAttribute("fitness");
81 ss >> F_;
82
83 ss.str("");
84 ss << node.getAttribute("error");
85 ss >> eps_;
86
87 ss.str("");
88 ss << node.getAttribute("as");
89 ss >> as_;
90
91 ss.str("");
92 ss << node.getAttribute("num");
93 ss >> num_;
94
95 ss.str("");
96 ss << node.getAttribute("exp");
97 ss >> exp_;
98
99 ss.str("");
100 ss << node.getAttribute("ts");
101 ss >> ts_;
102 }
103
104 virtual void write(XMLNode& node) {
105 node = XMLNode::createXMLTopNode("ClassifierParams");
106
107 std::stringstream sValue;
108 sValue << p_;
109 node.addAttribute("prediction", sValue.str().c_str());
110
111 sValue.str("");
112 sValue << F_;
113 node.addAttribute("fitness", sValue.str().c_str());
114
115 sValue.str("");
116 sValue << eps_;
117 node.addAttribute("error", sValue.str().c_str());
118
119 sValue.str("");
120 sValue << num_;
121 node.addAttribute("num", sValue.str().c_str());
122
123 sValue.str("");
124 sValue << ts_;
125 node.addAttribute("ts", sValue.str().c_str());
126
127 sValue.str("");
128 sValue << as_;
129 node.addAttribute("as", sValue.str().c_str());
130
131 sValue.str("");
132 sValue << exp_;
133 node.addAttribute("exp", sValue.str().c_str());
134 }
135
136};
137typedef boost::shared_ptr<ClassifierParams> ClassifierParamsP;
138
139#endif
Classifier data structure in XCS algorithm.
void registerParameters(StateP state)
Register genotype's parameters (called before Genotype::initialize)
virtual std::vector< MutationOpP > getMutationOp()
Create and return a vector of mutation operators.
virtual Genotype * copy()
Create an identical copy of the genotype object.
virtual void write(XMLNode &node)
Write genotype data to XMLNode.
virtual void read(XMLNode &node)
Read genotype data from XMLNode.
virtual std::vector< CrossoverOpP > getCrossoverOp()
Create and return a vector of crossover operators.
virtual bool initialize(StateP state)
Initialize a genotype object (read parameters, perform sanity check, build data)
Genotype base class.
Definition: Genotype.h:36
voidP getParameterValue(StateP state, std::string name)
Read single parameter value from Registry.
Definition: Genotype.cpp:10
bool registerParameter(StateP state, std::string name, voidP value, enum ECF::type T, std::string description="")
Register a single parameter.
Definition: Genotype.cpp:4
std::string name_
genotype's name
Definition: Genotype.h:109
Definition: nodes.h:92