74 lines
1.6 KiB
Text
74 lines
1.6 KiB
Text
#include <map>
|
|
#include <math.hpp>
|
|
#include <stdexcept>
|
|
|
|
|
|
int img_dict() {
|
|
map< math::csignal, std::string > dico;
|
|
return 0
|
|
};
|
|
|
|
double distance(math::csignal v1, math::csignal v2, int n){
|
|
|
|
if (v1.size() != v2.size()) {
|
|
throw std::runtime_error("les deux vecteurs doivent être de même longueur");
|
|
};
|
|
|
|
int m = v1.size();
|
|
double d;
|
|
double di;
|
|
for (int i = 0 ; i<m ; ++m){
|
|
di = std::abs(v1[i] - v2[i]);
|
|
di = std::pow(di, n);
|
|
d = d + di;
|
|
};
|
|
d = std::pow(d, 1/n);
|
|
return d;
|
|
};
|
|
|
|
|
|
|
|
int main(math::csignal new_vect, map< math::csignal, std::string > dico, int k){
|
|
double d;
|
|
vector< std::pair<double , math::csignal> > k_min;
|
|
int avance = 0;
|
|
int arret = 0;
|
|
int droite = 0;
|
|
int gauche = 0;
|
|
int rejet = 0;
|
|
vector<int> choix;
|
|
for(auto& ref_vect : dico){
|
|
d = distance(new_vect, ref_vect.first );
|
|
if (k_min.size() < k ){
|
|
k_min.push_back({d, ref_vect.first});
|
|
sort(k_min.begin(), k_min.end());
|
|
} else if (d < k_min[k-1].first){
|
|
k_min.push_back({d, ref_vect.first});
|
|
sort(k_min.begin(), k_min.end());
|
|
k_min.pop_back();
|
|
};
|
|
|
|
} ;
|
|
for(auto i = k_min.begin(); i != k_min.end(); i++) {
|
|
if (dico[k_min[i].second].second == "avance"){
|
|
avance = avance + 1
|
|
} else if (dico[k_min[i].second] == "arret"){
|
|
arret = arret + 1
|
|
} else if (dico[k_min[i].second] == "droite"){
|
|
arret = droite + 1
|
|
} else if (dico[k_min[i].second] == "gauche"){
|
|
arret = gauche + 1
|
|
} else if (dico[k_min[i].second] == "rejet"){
|
|
arret = rejet + 1
|
|
} ;
|
|
|
|
choix.push_back(avance);
|
|
choix.push_back(arret);
|
|
choix.push_back(droite);
|
|
choix.push_back(gauche);
|
|
choix.push_back(rejet);
|
|
|
|
|
|
|
|
};
|
|
};
|