forked from astromme/AdaBoost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeatureParser.cpp
58 lines (47 loc) · 1.42 KB
/
FeatureParser.cpp
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
#include <fstream>
#include "FeatureParser.h"
using namespace std;
/****************************************
* Function: parseFtrVectors
* ---------------------------
* Parse the data given from victim_parser.py into TrainingData
*
* td: TrainingData object to add to
* ftr_file: file produced by victim_parser.py
*
* Effects:
* adds feature vectors from ftr_file to td
*/
void FeatureParser::parseFtrVectors(TrainingData &td, string ftr_file){
int count = 0;
ifstream infile;
infile.open(ftr_file.c_str());
string pos_neg;
vector<float> ftrs;
float tmp_ftr;
while (! infile.eof()){
// clear the vector
ftrs.clear();
// is this a positive or negative training example?
infile >> pos_neg;
// grab all the features
for (int i=0; i<FTR_DIMENSION; i++){
infile >> tmp_ftr;
ftrs.push_back(tmp_ftr);
}
// set as a POSITIVE or NEGATIVE feature
if (pos_neg == "POS"){
FeatureVector fv(ftrs,POS);
if (! td.addFeature(fv))
printf("ERROR: feature vector incorrect size!\n");
}
else if (pos_neg == "NEG"){
FeatureVector fv(ftrs,NEG);
if (! td.addFeature(fv))
printf("ERROR: feature vector incorrect size!\n");
}
printf("Training Data Counted: %d\r", count);
count++;
}
infile.close();
}