-
Notifications
You must be signed in to change notification settings - Fork 0
/
naivebayesclassifier.cpp
52 lines (45 loc) · 1.67 KB
/
naivebayesclassifier.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
#include "naivebayesclassifier.h"
NaiveBayesClassifier::NaiveBayesClassifier()
{
_gnb.TrainingFinish = std::bind(&NaiveBayesClassifier::BinderForFinished,this,std::placeholders::_1);
ADD_SIGNAL(MethodInfo("TrainingFinished", PropertyInfo(Variant::BOOL, "TEST TEXT")));
}
void NaiveBayesClassifier::_bind_methods()
{
ClassDB::bind_method(D_METHOD("TestFunc"), &NaiveBayesClassifier::TestFunc);
ClassDB::bind_method(D_METHOD("InsertMultipleInput","InputArray"), &NaiveBayesClassifier::InsertMultipleInput);
ClassDB::bind_method(D_METHOD("SetOutputs","OutputArray"), &NaiveBayesClassifier::SetOutputs);
ClassDB::bind_method(D_METHOD("StartTraining"), &NaiveBayesClassifier::StartTraining);
ClassDB::bind_method(D_METHOD("CalculateForMultipleInput","InputValue"), &NaiveBayesClassifier::CalculateForMultipleInput);
}
String NaiveBayesClassifier::TestFunc()
{
//Just a simple "is this Working ?" lines..
std::string testReturn{"Naive Bayes Classifier Test Ok"};
String tryThis(testReturn.c_str());
return tryThis;
}
void NaiveBayesClassifier::StartTraining()
{
for(const auto& eachVector : GetMultipleInput())
{
_gnb.InsertMultipleInput(eachVector);
}
_gnb.SetOutputs(GetOutputVector());
_gnb.Train();
}
real_t NaiveBayesClassifier::CalculateForMultipleInput(PoolRealArray calculateForthis)
{
std::vector<double> inputVector = {};
inputVector.resize(calculateForthis.size());
for(int counter = 0; counter < calculateForthis.size(); ++ counter)
{
inputVector[counter] = calculateForthis.get(counter);
}
return(_gnb.Predict(inputVector)[0]);
}
void NaiveBayesClassifier::BinderForFinished(bool input)
{
std::cout<<"Training Finished"<<std::endl;
emit_signal("TrainingFinished", true);
}