Commit 04a27cd6 authored by estellearrc's avatar estellearrc
Browse files

test RF

parent cf3b095b
......@@ -13,7 +13,7 @@ add_subdirectory(Extraction)
# Extraction/*.cpp
# )
add_subdirectory(CART)
#add_subdirectory(RF)
add_subdirectory(RF)
add_subdirectory(SVM)
add_subdirectory(ANN)
set(TBB_SHARED_OBJECT "/usr/local/lib/libtbb.so")
......
add_executable(RF main.cpp)
\ No newline at end of file
......@@ -229,7 +229,7 @@ def train_RF(saveAlgo=False):
with open(file, 'a') as f:
f.write("#ifndef RFTRAINED_H\n#define RFTRAINED_H\n#include <string>\n#include <numeric>\n#include <fstream>\n#include <map>\n#include \"../Helpers/globals.h\"\n#include <typeinfo>\n")
f.write("const int N_ESTIMATORS = "+str(model_best.n_estimators)+";\nconst int MAX_DEPTH = "+str(model_best.max_depth)+";\n")
f.write("float RFModel(int num_estimator, std::map < FTYPE, DataVector > &features){\n")
f.write("int RFModel(int num_estimator, std::map < FTYPE, DataVector > &features){\n")
f.write("DataVector featureVector = features[FTYPE::BINAVG];\nfeatureVector.insert(featureVector.end(), features[FTYPE::BINSTDEV].begin(), features[FTYPE::BINSTDEV].end());\n")
f.close()
for e in model_best.estimators_:
......@@ -290,39 +290,14 @@ def str_tree(text,decision_tree, max_depth, node, depth):
text += secondeLayerIF + secondeLayerELSE
print(text)
else: # leaf
text+= "return " + str(class_name)+";\n"
text+= "return " + str(int(class_name))+";\n"
else:
subtree_depth = compute_depth(tree_, node)
if subtree_depth == 1:
text+= "return " + str(class_name)+";\n"
text+= "return " + str(int(class_name))+";\n"
# print(text)
return text
def transformArrayToStr(array):
array = array.T
text = "{"
for i in range(np.shape(array)[0]):
text += "{"
for j in range(np.shape(array)[1]):
text += str(array[i, j]) + ",\n"
text += "},\n"
text += "}"
return text
def transformListToStr(list):
text = "{"
for i in range(len(list)):
text += str(list[i]) + ",\n"
text += "}"
return text
def save_file_as_csv(data, name_folder):
data.to_csv('/home/hugo/Documents/embedded-machine-learning/' +
name_folder+'/file_test.csv', index=False)
if __name__ == "__main__":
model, history = train_RF(saveAlgo=False)
......
This diff is collapsed.
// HEADER=all_headers.h
// echo "#ifndef __ALL_HEADERS__" > $HEADER
// echo "#define __ALL_HEADERS__" >> $HEADER
// for file in 'dir/*.h'
// do
// echo "#include <$file>" >> $HEADER
// done
// echo "#endif" >> $HEADER
#include "RFTrained.h"
#include "../Extraction/features_extraction.cpp"
#include <string>
#include <iostream>
#include <vector>
std::string majority_voting(std::vector<int> results){
std::vector<float> probas(CLASS_N,0.0);
for(int r : results){
probas[r] += 1/N_ESTIMATORS;
}
float max = *max_element(probas.begin(), probas.end());
for(int k = 0; k < CLASS_N; k++){
if(probas[k] == max)
return genres[k];
}
}
int main(int argc, char **argv)
{
......@@ -20,10 +25,15 @@ int main(int argc, char **argv)
}
else
{
file_path = "/home/hugo/Documents/embedded-machine-learning/DATASETS/genres/disco/disco.00010.au";
file_path = "/home/estellearrc/Documents/Cours/ENSTA_Bretagne_2020_2022/3A_2021_2022/S5/Embedded_machine_learning/embedded-machine-learning/DATASETS/genres/disco/disco.00010.au";
}
std::map<FTYPE, DataVector> features = compute_features_for(file_path);
std::string result = RFModel(features);
std::vector<int> results;
for(int k = 0; k < N_ESTIMATORS; k++)
{
results.push_back(RFModel(k, features));
}
std::string result = majority_voting(results);
std::cout << result << std::endl;
return 0;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment