-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm.cpp
More file actions
58 lines (49 loc) · 1.96 KB
/
Copy pathalgorithm.cpp
File metadata and controls
58 lines (49 loc) · 1.96 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
#include "algorithm.hpp"
//print algorithm
//print name, the number of sample to use
//the predicted results and the percentage of good results
void const Algorithm::print(){
cout << "-------------PRINT ALGO-------------" << endl;
cout << "Name = " << _name << endl;
cout << "Number of sample to use = " << _nbSample2Use << endl;
cout << "Predicted results : " << endl;
for(int i : _predictedResult){
cout << i << " ";
}
cout << endl;
cout << "Percentage of good results = " << _percentage << endl;
cout << "-----------------------------------" << endl;
}
//process data from two differrent data : one for training and one for testing
void Algorithm::process(Data data4Training, Data data4Testing){
multimap<int,vector<float>>::iterator itTraining;
multimap<int, vector<float>> training;
training = data4Training.getData();
multimap<int,vector<float>>::iterator itTesting;
multimap<int, vector<float>> testing;
testing = data4Testing.getData();
for(itTesting = testing.begin(); itTesting != testing.end(); itTesting++){
vector<float> firstResult;
for(itTraining = training.begin(); itTraining != training.end(); itTraining++){
vector<float> vecTesting = (*itTesting).second;
vector<float> vecTraining = (*itTraining).second;
float f = applyMethod(vecTesting,vecTraining);
firstResult.push_back(f);
}
add2PredictedResult(training,firstResult);
}
computePercentage(testing);
}
//Compute percentage of good results among predicted results
void Algorithm::computePercentage(multimap<int,vector<float>> testing) {
int nbGoodResult = 0;
int i = 0;
multimap<int,vector<float>>::iterator itData;
for(itData = testing.begin();itData!=testing.end();itData++){
if(this->getPredictedResult()[i] == (*itData).first){
nbGoodResult++;
}
i++;
}
_percentage = 100 * nbGoodResult / testing.size();
}