Direct Graphical Models  v.1.5.3
DirectGraphicalModels::CTrainNode Class Referenceabstract

Base abstract class for node potentials training. More...

#include <TrainNode.h>

Inheritance diagram for DirectGraphicalModels::CTrainNode:
Collaboration diagram for DirectGraphicalModels::CTrainNode:

Public Member Functions

 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...
 
virtual void addFeatureVec (const Mat &featureVector, byte gt)=0
 Adds new feature vector. More...
 
virtual void train (bool doClean=false)
 Random model training. More...
 
Mat getNodePotentials (const Mat &featureVectors, const Mat &weights=Mat(), float Z=0.0f) const
 Returns a block of node potentials, based on the block of feature vector. More...
 
Mat getNodePotentials (const vec_mat_t &featureVectors, const Mat &weights=Mat(), float Z=0.0f) const
 Returns a block of node potentials, based on the block of feature vector. More...
 
Mat getNodePotentials (const Mat &featureVector, float weight, float Z=0.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 reset (void)=0
 Resets class variables. More...
 
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 calculateNodePotentials (const Mat &featureVector, Mat &potential, Mat &mask) const =0
 Calculates the node potential, based on the feature vector. More...
 
- Protected Member Functions inherited from DirectGraphicalModels::CBaseRandomModel
virtual void saveFile (FILE *pFile) const =0
 Saves the random model into the file. More...
 
virtual void loadFile (FILE *pFile)=0
 Loads the random model from the file. More...
 
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...
 

Additional Inherited Members

- 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

Base abstract class for node potentials training.

The common usage for node potentials training is as follow:

CTrainNode *t = new CTrainNodeXXX(nStates, nFeatures);
// "adding data" phase
for (int i = 0; i < NUMBER_OF_TRAINING_DATA; i++) t->addFeatureVec(train_featurVector[i], groundtruth_class[i]);
// training
t->train();
// "getting data" phase
for (int i = 0; i < NUMBER_OF_TEST_DATA; i++) predicted_class[i] = t->getNodePotentials(test_featurVector[i]);
delete t;

See Demo Train for more details

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 31 of file TrainNode.h.

Constructor & Destructor Documentation

◆ CTrainNode()

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

Constructor.

Parameters
nStatesNumber of states (classes)
nFeaturesNumber of features

Definition at line 7 of file TrainNode.cpp.

◆ ~CTrainNode()

DirectGraphicalModels::CTrainNode::~CTrainNode ( void  )
virtual

Definition at line 14 of file TrainNode.cpp.

Member Function Documentation

◆ addFeatureVec() [1/3]

void DirectGraphicalModels::CTrainNode::addFeatureVec ( const Mat &  featureVectors,
const Mat &  gt 
)

Adds a block of new feature vectors.

Used to add multiple featureVectors, corresponding to the ground-truth states (classes) gt for training

Parameters
featureVectorsMulti-channel matrix, each element of which is a multi-dimensinal point: Mat(type: CV_8UC(nFeatures))
gtMatrix, each element of which is a ground-truth state (class)

Definition at line 17 of file TrainNode.cpp.

Here is the caller graph for this function:

◆ addFeatureVec() [2/3]

void DirectGraphicalModels::CTrainNode::addFeatureVec ( const vec_mat_t &  featureVectors,
const Mat &  gt 
)

Adds a block of new feature vectors.

Used to add multiple featureVectors, corresponding to the ground-truth states (classes) gt for training

Parameters
featureVectorsVector of size nFeatures, each element of which is a single feature - image: Mat(type: CV_8UC1)
gtMatrix, each element of which is a ground-truth state (class)

Definition at line 23 of file TrainNode.cpp.

◆ addFeatureVec() [3/3]

virtual void DirectGraphicalModels::CTrainNode::addFeatureVec ( const Mat &  featureVector,
byte  gt 
)
pure 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)

Implemented in DirectGraphicalModels::CTrainNodeMsRF, DirectGraphicalModels::CTrainNodeCvRF, DirectGraphicalModels::CTrainNodeCvANN, DirectGraphicalModels::CTrainNodeCvGMM, DirectGraphicalModels::CTrainNodeCvSVM, DirectGraphicalModels::CTrainNodeKNN, DirectGraphicalModels::CTrainNodeGMM, DirectGraphicalModels::CTrainNodeCvKNN, and DirectGraphicalModels::CTrainNodeNaiveBayes.

◆ calculateNodePotentials()

virtual void DirectGraphicalModels::CTrainNode::calculateNodePotentials ( const Mat &  featureVector,
Mat &  potential,
Mat &  mask 
) const
protectedpure virtual

Calculates the node potential, based on the feature vector.

This function calculates the potentials of the node, described with the sample featureVector, being in each state (belonging to each class). These potentials are united in the node potential vector:

\[nodePot[nStates] = f(\textbf{f}[nFeatures]).\]

Functions \( f \) must be implemented in derived classes.

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).

Implemented in DirectGraphicalModels::CTrainNodeMsRF, DirectGraphicalModels::CTrainNodeCvRF, DirectGraphicalModels::CTrainNodeGMM, DirectGraphicalModels::CTrainNodeCvANN, DirectGraphicalModels::CTrainNodeCvGMM, DirectGraphicalModels::CTrainNodeCvSVM, DirectGraphicalModels::CTrainNodeNaiveBayes, DirectGraphicalModels::CTrainNodeKNN, and DirectGraphicalModels::CTrainNodeCvKNN.

Here is the caller graph for this function:

◆ getNodePotentials() [1/3]

Mat DirectGraphicalModels::CTrainNode::getNodePotentials ( const Mat &  featureVectors,
const Mat &  weights = Mat(),
float  Z = 0.0f 
) const

Returns a block of node potentials, based on the block of feature vector.

Parameters
featureVectorsMulti-channel matrix, each element of which is a multi-dimensinal point: Mat(type: CV_8UC(nFeatures))
weightsThe block of weighting parameters Mat(type: CV_32FC1). If empty, values 1 are used.
ZThe value of partition function. In order to convert potential to the probability, it is multiplied by \(1/Z\). If \(Z\leq0\), the resulting node potentials are normalized to 100, independently for each potential.

Definition at line 29 of file TrainNode.cpp.

Here is the caller graph for this function:

◆ getNodePotentials() [2/3]

Mat DirectGraphicalModels::CTrainNode::getNodePotentials ( const vec_mat_t &  featureVectors,
const Mat &  weights = Mat(),
float  Z = 0.0f 
) const

Returns a block of node potentials, based on the block of feature vector.

Parameters
featureVectorsVector of size nFeatures, each element of which is a single feature - image: Mat(type: CV_8UC1)
weightsThe block of weighting parameter Mat(type: CV_32FC1)
ZThe value of partition function. In order to convert potential to the probability, it is multiplied by \(1/Z\). If \(Z\leq0\), the resulting node potentials are normalized to 100, independently for each potential.

Definition at line 66 of file TrainNode.cpp.

◆ getNodePotentials() [3/3]

Mat DirectGraphicalModels::CTrainNode::getNodePotentials ( const Mat &  featureVector,
float  weight,
float  Z = 0.0f 
) const

Returns the node potential, based on the feature vector.

This function calls calculateNodePotentials() function, which should be implemented in derived classes. After that, the resulting node potential is powered by parameter weight.

Parameters
featureVectorMulti-dimensinal point \(\textbf{f}\): Mat(size: nFeatures x 1; type: CV_{XX}C1)
weightThe weighting parameter (default value is 1)
ZThe value of partition function. In order to convert potential to the probability, it is multiplied by \(1/Z\). If \(Z\leq0\), the resulting node potentials are normalized to 100, independently for every function call.
Returns
Normalized node potentials on success: Mat(size: nStates x 1; type: CV_32FC1);

Definition at line 104 of file TrainNode.cpp.

Here is the call graph for this function:

◆ train()

virtual void DirectGraphicalModels::CTrainNode::train ( bool  doClean = false)
inlinevirtual

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

Implements DirectGraphicalModels::ITrain.

Reimplemented in DirectGraphicalModels::CTrainNodeMsRF, DirectGraphicalModels::CTrainNodeCvRF, DirectGraphicalModels::CTrainNodeCvANN, DirectGraphicalModels::CTrainNodeCvGMM, DirectGraphicalModels::CTrainNodeCvSVM, DirectGraphicalModels::CTrainNodeKNN, DirectGraphicalModels::CTrainNodeCvKNN, DirectGraphicalModels::CTrainNodeGMM, and DirectGraphicalModels::CTrainNodeNaiveBayes.

Definition at line 63 of file TrainNode.h.

Here is the caller graph for this function:

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