35 #ifndef SHARK_MODEL_NB_CLASSIFIER_H 36 #define SHARK_MODEL_NB_CLASSIFIER_H 42 #include <boost/noncopyable.hpp> 43 #include <boost/smart_ptr/shared_ptr.hpp> 55 template <
class InputType = RealVector,
class OutputType =
unsigned int>
58 private boost::noncopyable
88 for (std::size_t i = 0; i < classSize; ++i)
90 std::vector<AbstractDistPtr> featureDist;
91 for (std::size_t j = 0; j < featureSize; ++j)
108 {
return "NBClassifier"; }
135 return boost::shared_ptr<State>(
new EmptyState());
139 void eval(BatchInputType
const& patterns, BatchOutputType& outputs,
State& state)
const{
143 outputs.resize(patterns.size1());
145 for(std::size_t p = 0; p != patterns.size1(); ++p){
155 double currentLogProb =
safeLog(classDistribution);
156 std::size_t featureIndex = 0u;
158 currentLogProb += featureDistribution->logP(patterns(p,featureIndex++));
161 if (currentLogProb > maxLogProb)
163 maxLogProb = currentLogProb;
164 bestProbClass = classIndex;
168 outputs(p) = bestProbClass;
181 throw SHARKEXCEPTION(
"[NBClassifier] class probability must be added in ascending order.");
205 #endif // SHARK_MODEL_NB_CLASSIFIER_H