-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm1.cpp
More file actions
48 lines (42 loc) · 1.43 KB
/
Copy pathalgorithm1.cpp
File metadata and controls
48 lines (42 loc) · 1.43 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
#include "algorithm1.hpp"
//Default constructor
Algorithm1::Algorithm1(){
_nbSample2Use = 70;
_name = "Mean of absolutes differences between each samples";
_id = 01;
_percentage = 0;
}
//Constructor with a value for _nbSample2Use
Algorithm1::Algorithm1(int nbSample2Use){
_nbSample2Use = nbSample2Use;
_name = "Mean of absolutes differences between each samples";
_id = 01;
_percentage = 0;
}
//Apply the specific method of the algorithm to the data
float Algorithm1::applyMethod(vector<float> vecTesting,vector<float> vecTraining){
vector<float> diffPerSample;
for(int i=0;i<_nbSample2Use;i++){
float difference = abs(vecTesting[i]-vecTraining[i]);
diffPerSample.push_back(difference);
}
float sum = 0;
for(int i=0;i<diffPerSample.size();i++){
sum += diffPerSample[i];
}
float mean = sum/diffPerSample.size();
return mean;
}
//Add the result predicted to a vector
void Algorithm1::add2PredictedResult(multimap<int, vector<float>> training,vector<float> firstResult) {
multimap<int,vector<float>>::iterator itTraining;
int indMin = min_element(firstResult.begin(),firstResult.end()) - firstResult.begin();
int j=0;
for(itTraining=training.begin();itTraining!=training.end();itTraining++) {
if (j == indMin) {
_predictedResult.push_back((*itTraining).first);
itTraining = training.end();
}
j++;
}
}