Direct Graphical Models  v.1.5.1
DirectGraphicalModels::CTrainNodeNaiveBayes Class Reference

Naive Bayes training class. More...

#include <TrainNodeNaiveBayes.h>

Inheritance diagram for DirectGraphicalModels::CTrainNodeNaiveBayes:
Collaboration diagram for DirectGraphicalModels::CTrainNodeNaiveBayes:

Public Member Functions

 CTrainNodeNaiveBayes (byte nStates, word nFeatures)
 Constructor. More...
 
 ~CTrainNodeNaiveBayes (void)
 
virtual void reset (void)
 Resets class variables. More...
 
virtual void addFeatureVec (const Mat &featureVector, byte gt)
 Adds new feature vector. More...
 
virtual void train (bool doClean=false)
 Random model training. More...
 
IPDFgetPDF (byte state, word feature) const
 Returns the normalized probability density function for specific state (class) and feature. More...
 
void smooth (int nIt=1)
 
- Public Member Functions inherited from DirectGraphicalModels::CTrainNode
 CTrainNode (byte nStates, word nFeatures)
 Constructor. More...
 
virtual ~CTrainNode (void)
 
void addFeatureVec (const Mat &featureVectors, const Mat &gt)
 Adds a block of new feature vectors. More...
 
void addFeatureVec (const vec_mat_t &featureVectors, const Mat &gt)
 Adds a block of new feature vectors. More...
 
Mat getNodePotentials (const Mat &featureVector, float weight=1.0f) const
 Returns the node potential, based on the feature vector. More...
 
- Public Member Functions inherited from DirectGraphicalModels::ITrain
 ITrain (byte nStates, word nFeatures)
 Constructor. More...
 
virtual ~ITrain (void)
 
word getNumFeatures (void) const
 Returns number of features. More...
 
- Public Member Functions inherited from DirectGraphicalModels::CBaseRandomModel
 CBaseRandomModel (byte nStates)
 Constructor. More...
 
virtual ~CBaseRandomModel (void)
 
virtual void save (const std::string &path, const std::string &name=std::string(), short idx=-1) const
 Saves the training data. More...
 
virtual void load (const std::string &path, const std::string &name=std::string(), short idx=-1)
 Loads the training data. More...
 
byte getNumStates (void) const
 Returns number of features. More...
 

Protected Member Functions

virtual void saveFile (FILE *pFile) const
 Saves the random model into the file. More...
 
virtual void loadFile (FILE *pFile)
 Loads the random model from the file. More...
 
void calculateNodePotentials (const Mat &featureVector, Mat &potential, Mat &mask) const
 Calculates the node potential, based on the feature vector. More...
 
- Protected Member Functions inherited from DirectGraphicalModels::CBaseRandomModel
std::string generateFileName (const std::string &path, const std::string &name, short idx) const
 Generates name of the data file for storing random model parameters. More...
 

Protected Attributes

IPDF *** m_pPDF
 The 1D PDF for node potentials. More...
 
- Protected Attributes inherited from DirectGraphicalModels::ITrain
word m_nFeatures
 The number of features (length of the feature vector) More...
 
- Protected Attributes inherited from DirectGraphicalModels::CBaseRandomModel
byte m_nStates
 The number of states (classes) More...
 

Detailed Description

Naive Bayes training class.

This class implements the naive Bayes classifier, which is based on strong (naive) independence assumptions between the features.

Author
Sergey G. Kosov, serge.nosp@m.y.ko.nosp@m.sov@p.nosp@m.roje.nosp@m.ct-10.nosp@m..de

Definition at line 29 of file TrainNodeNaiveBayes.h.

Constructor & Destructor Documentation

DirectGraphicalModels::CTrainNodeNaiveBayes::CTrainNodeNaiveBayes ( byte  nStates,
word  nFeatures 
)

Constructor.

Parameters
nStatesNumber of states (classes)
nFeaturesNumber of features

Definition at line 9 of file TrainNodeNaiveBayes.cpp.

DirectGraphicalModels::CTrainNodeNaiveBayes::~CTrainNodeNaiveBayes ( void  )

Definition at line 35 of file TrainNodeNaiveBayes.cpp.

Member Function Documentation

void DirectGraphicalModels::CTrainNodeNaiveBayes::addFeatureVec ( const Mat &  featureVector,
byte  gt 
)
virtual

Adds new feature vector.

Used to add a featureVector, corresponding to the ground-truth state (class) gt for training

Parameters
featureVectorMulti-dimensinal point: Mat(size: nFeatures x 1; type: CV_8UC1)
gtCorresponding ground-truth state (class)

Implements DirectGraphicalModels::CTrainNode.

Definition at line 68 of file TrainNodeNaiveBayes.cpp.

Here is the call graph for this function:

void DirectGraphicalModels::CTrainNodeNaiveBayes::calculateNodePotentials ( const Mat &  featureVector,
Mat &  potential,
Mat &  mask 
) const
protectedvirtual

Calculates the node potential, based on the feature vector.

This function calculates the potentials of the node, described with the sample featureVector ( \( \textbf{f} \)):

\[ nodePot_s = prior_s\cdot\prod_{f\in\mathbb{F}} (H_{s,f}.data[\textbf{f}_f] / H_{s,f}.n); \forall s\in\mathbb{S}, \]

where \(\mathbb{S}\) and \(\mathbb{F}\) are sets of all states (classes) and features correspondently. In other words, the indexes: \( s \in [0; nStates) \) and \( f \in [0; nFeatures) \). Here \( H.data[256] \) is a 1D histogram, \( H.n \) is the number of entries in histogram, i.e. \( H.n = \sum^{255}_{i = 0} H.data[i] \). And \( \textbf{f}_f \in [0; 255], \forall f \in [0; nFeatures) \), i.e. has (type: CV_8UC1).

Parameters
[in]featureVectorMulti-dimensinal point \(\textbf{f}\): Mat(size: nFeatures x 1; type: CV_{XX}C1)
[in,out]potentialNode potentials: Mat(size: nStates x 1; type: CV_32FC1). This parameter should be preinitialized and set to value 0.
[in,out]maskRelevant Node potentials: Mat(size: nStates x 1; type: CV_8UC1). This parameter should be preinitialized and set to value 1 (all potentials are relevant).

Implements DirectGraphicalModels::CTrainNode.

Definition at line 124 of file TrainNodeNaiveBayes.cpp.

IPDF* DirectGraphicalModels::CTrainNodeNaiveBayes::getPDF ( byte  state,
word  feature 
) const
inline

Returns the normalized probability density function for specific state (class) and feature.

Parameters
stateThe state (class)
featureThe feature
Returns
The probability density function

Definition at line 51 of file TrainNodeNaiveBayes.h.

void DirectGraphicalModels::CTrainNodeNaiveBayes::loadFile ( FILE *  pFile)
protectedvirtual

Loads the random model from the file.

Allows to re-use the class.

Parameters
pFilePointer to the file, opened for reading.

Reimplemented from DirectGraphicalModels::CPrior.

Definition at line 114 of file TrainNodeNaiveBayes.cpp.

Here is the call graph for this function:

void DirectGraphicalModels::CTrainNodeNaiveBayes::reset ( void  )
virtual

Resets class variables.

Allows to re-use the class.

Reimplemented from DirectGraphicalModels::CPrior.

Definition at line 50 of file TrainNodeNaiveBayes.cpp.

Here is the call graph for this function:

void DirectGraphicalModels::CTrainNodeNaiveBayes::saveFile ( FILE *  pFile) const
protectedvirtual

Saves the random model into the file.

Allows to re-use the class.

Parameters
pFilePointer to the file, opened for writing.

Reimplemented from DirectGraphicalModels::CPrior.

Definition at line 104 of file TrainNodeNaiveBayes.cpp.

Here is the call graph for this function:

void DirectGraphicalModels::CTrainNodeNaiveBayes::smooth ( int  nIt = 1)

Definition at line 96 of file TrainNodeNaiveBayes.cpp.

void DirectGraphicalModels::CTrainNodeNaiveBayes::train ( bool  doClean = false)
virtual

Random model training.

Auxilary function for training - some derived classes may use this function inbetween training and classification phases

Note
This function must be called inbetween the training and classification phases
Parameters
doCleanFlag indicating if the memory, keeping the trining data should be released after training

Reimplemented from DirectGraphicalModels::CTrainNode.

Definition at line 91 of file TrainNodeNaiveBayes.cpp.

Member Data Documentation

IPDF*** DirectGraphicalModels::CTrainNodeNaiveBayes::m_pPDF
protected

The 1D PDF for node potentials.

Definition at line 76 of file TrainNodeNaiveBayes.h.


The documentation for this class was generated from the following files: