-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeature.hpp
More file actions
70 lines (54 loc) · 1.7 KB
/
Feature.hpp
File metadata and controls
70 lines (54 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef Feature_hpp
#define Feature_hpp
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
class Feature {
private:
int index;
string name;
string type;
int range;
protected:
Feature(int index, const string& name, const string& type, int range) : index(index), name(name), type(type), range(range) {}
public:
int getIndex() const {
return index;
}
const string& getName() const {
return name;
}
const string& getType() const {
return type;
}
int getRange() const {
return range;
}
virtual ~Feature() {}
virtual string toString() const = 0;
virtual double convertValueToInternal(const string& str) const = 0;
virtual string convertInternalToValue(double val) const = 0;
};
class NumericFeature : public Feature {
private:
public:
NumericFeature(int index, const string& name) : Feature(index, name, "numeric", 2) {}
virtual string toString() const;
virtual double convertValueToInternal(const string& str) const;
virtual string convertInternalToValue(double val) const;
};
class NominalFeature : public Feature {
private:
vector<string> idxToName;
unordered_map<string, int> nameToIdx;
public:
NominalFeature(int index, const string& name, const vector<string>& values) : Feature(index, name, "nominal", (int)values.size()), idxToName(values) {
for (int i = 0; i < getRange(); ++i)
nameToIdx[idxToName[i]] = i;
}
virtual string toString() const;
virtual double convertValueToInternal(const string& str) const;
virtual string convertInternalToValue(double val) const;
};
#endif /* Feature_hpp */