Direct Graphical Models  v.1.7.0
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)=default
 
void addFeatureVecs (const Mat &featureVectors, const Mat &gt)
 Adds a block of new feature vectors. More...
 
void addFeatureVecs (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)=default
 
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 states (classes) More...
 

Static Public Member Functions

static std::shared_ptr< CTrainNodecreate (byte nodeRandomModel, byte nStates, word nFeatures)
 Factory method returning node trainer object. 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...
 

Private Attributes

Mat m_mask
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ CTrainNode()

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

Constructor.

Parameters
nStatesNumber of states (classes)
nFeaturesNumber of features

Definition at line 55 of file TrainNode.h.

◆ ~CTrainNode()

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

Member Function Documentation

◆ addFeatureVec()

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::CTrainNodeBayes.

Here is the caller graph for this function:

◆ addFeatureVecs() [1/2]

void DirectGraphicalModels::CTrainNode::addFeatureVecs ( 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 42 of file TrainNode.cpp.

Here is the call graph for this function:

◆ addFeatureVecs() [2/2]

void DirectGraphicalModels::CTrainNode::addFeatureVecs ( 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 48 of file TrainNode.cpp.

Here is the call graph for this function:

◆ 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::CTrainNodeBayes, DirectGraphicalModels::CTrainNodeKNN, and DirectGraphicalModels::CTrainNodeCvKNN.

Here is the caller graph for this function:

◆ create()

std::shared_ptr< CTrainNode > DirectGraphicalModels::CTrainNode::create ( byte  nodeRandomModel,
byte  nStates,
word  nFeatures 
)
static

Factory method returning node trainer object.

Note
The resulting node trainer object is created with default parameters
Parameters
nodeRandomModelType of desired random model (Ref. NodeRandomModel)
nStatesNumber of states (classes)
nFeaturesNumber of features
Returns
Tne pointer to the concrete implementation of the node trainer class

Definition at line 20 of file TrainNode.cpp.

◆ 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 54 of file TrainNode.cpp.

Here is the call graph for this function:
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 91 of file TrainNode.cpp.

Here is the call graph for this function:

◆ 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 129 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::CTrainNodeBayes.

Definition at line 92 of file TrainNode.h.

Here is the caller graph for this function:

Member Data Documentation

◆ m_mask

Mat DirectGraphicalModels::CTrainNode::m_mask
private

Definition at line 139 of file TrainNode.h.


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