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

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

#include <TrainEdge.h>

Inheritance diagram for DirectGraphicalModels::CTrainEdge:
Collaboration diagram for DirectGraphicalModels::CTrainEdge:

Public Member Functions

 CTrainEdge (byte nStates, word nFeatures)
 Constructor. More...
 
virtual ~CTrainEdge (void)
 
void addFeatureVecs (const Mat &featureVectors, const Mat &gt, const CGraphExt *pGraph)
 Adds a block of new feature vectors. More...
 
void addFeatureVecs (const vec_mat_t &featureVectors, const Mat &gt, const CGraphExt *pGraph)
 Adds a block of new feature vectors. More...
 
virtual void addFeatureVecs (const Mat &featureVector1, byte gt1, const Mat &featureVector2, byte gt2)=0
 Adds a pair of feature vectors. More...
 
virtual void train (bool doClean=false)
 Random model training. More...
 
Mat getEdgePotentials (const Mat &featureVector1, const Mat &featureVector2, float *params, size_t params_len, float weight=1.0f) const
 Returns the edge potential, based on the feature vectors. 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 Mat calculateEdgePotentials (const Mat &featureVector1, const Mat &featureVector2, float *params, size_t params_len) const =0
 Calculates the edge potential, based on the feature vectors. 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 edge potentials training.

Refer to the Demo Train for the application and common usage example

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 18 of file TrainEdge.h.

Constructor & Destructor Documentation

◆ CTrainEdge()

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

Constructor.

Parameters
nStatesNumber of states (classes)
nFeaturesNumber of features

Definition at line 26 of file TrainEdge.h.

◆ ~CTrainEdge()

virtual DirectGraphicalModels::CTrainEdge::~CTrainEdge ( void  )
inlinevirtual

Definition at line 27 of file TrainEdge.h.

Member Function Documentation

◆ addFeatureVecs() [1/3]

void DirectGraphicalModels::CTrainEdge::addFeatureVecs ( const Mat &  featureVectors,
const Mat &  gt,
const CGraphExt pGraph 
)

Adds a block of new feature vectors.

This function may be used only for basic graphical models, built with the CGraphExt::build() method. It extracts pairs of feature vectors with corresponding ground-truth values from blocks featureVectors and gt, according to the graph structure, provided via pGraph

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)
pGraphPointer to the extended graph, which defines the structure of the graph

Definition at line 7 of file TrainEdge.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addFeatureVecs() [2/3]

void DirectGraphicalModels::CTrainEdge::addFeatureVecs ( const vec_mat_t &  featureVectors,
const Mat &  gt,
const CGraphExt pGraph 
)

Adds a block of new feature vectors.

This function may be used only for basic graphical models, built with the CGraphExt::build() method. It extracts pairs of feature vectors with corresponding ground-truth values from blocks featureVectors and gt, according to the graph structure, provided via pGraph

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)
pGraphPointer to the extended graph, which defines the structure of the graph

Definition at line 57 of file TrainEdge.cpp.

Here is the call graph for this function:

◆ addFeatureVecs() [3/3]

virtual void DirectGraphicalModels::CTrainEdge::addFeatureVecs ( const Mat &  featureVector1,
byte  gt1,
const Mat &  featureVector2,
byte  gt2 
)
pure virtual

Adds a pair of feature vectors.

Used to add featureVector1 and featureVector2, corresponding to the ground-truth states (classes) gt1 and gt2 for training. Here the couple {featureVector1, gt1} corresponds to the first node of the edge, and the couple {featureVector2, gt2} - to the second node.

Parameters
featureVector1Multi-dimensinal point: Mat(size: nFeatures x 1; type: CV_8UC1), corresponding to the first node of the edge.
gt1The ground-truth state (class) of the first node of the edge, given by featureVector1
featureVector2Multi-dimensinal point: Mat(size: nFeatures x 1; type: CV_8UC1), corresponding to the second node of the edge.
gt2The ground-truth state (class) of the second node of the edge, given by featureVector2

Implemented in DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >, DirectGraphicalModels::CTrainEdgePotts, and DirectGraphicalModels::CTrainEdgePrior.

◆ calculateEdgePotentials()

virtual Mat DirectGraphicalModels::CTrainEdge::calculateEdgePotentials ( const Mat &  featureVector1,
const Mat &  featureVector2,
float *  params,
size_t  params_len 
) const
protectedpure virtual

Calculates the edge potential, based on the feature vectors.

This function calculates the potentials of an edge, described with two samples featureVector1 and featureVector2, correspondig to the both nodes defining that edge. The resulting potentials of the two nodes being in each possible state (belonging to each possible class) at the same time, are united in the edge potential matrix:

\[edgePot[nStates][nStates] = f(\textbf{f}_1[nFeatures],\textbf{f}_2[nFeatures]).\]

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

Parameters
featureVector1Multi-dimensinal point \(\textbf{f}_1\): Mat(size: nFeatures x 1; type: CV_{XX}C1), corresponding to the first node of the edge
featureVector2Multi-dimensinal point \(\textbf{f}_2\): Mat(size: nFeatures x 1; type: CV_{XX}C1), corresponding to the second node of the edge
paramsArray of control parameters. Please refere to the concrete model implementation of the calculateEdgePotentials() function for more details
params_lenThe length of the params parameter
Returns
The edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

Implemented in DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >, DirectGraphicalModels::CTrainEdgePotts, DirectGraphicalModels::CTrainEdgePottsCS, and DirectGraphicalModels::CTrainEdgePrior.

Here is the caller graph for this function:

◆ getEdgePotentials()

Mat DirectGraphicalModels::CTrainEdge::getEdgePotentials ( const Mat &  featureVector1,
const Mat &  featureVector2,
float *  params,
size_t  params_len,
float  weight = 1.0f 
) const

Returns the edge potential, based on the feature vectors.

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

Parameters
featureVector1Multi-dimensinal point \(\textbf{f}_1\): Mat(size: nFeatures x 1; type: CV_{XX}C1), corresponding to the first node of the edge
featureVector2Multi-dimensinal point \(\textbf{f}_2\): Mat(size: nFeatures x 1; type: CV_{XX}C1), corresponding to the second node of the edge
paramsArray of control parameters. Please refer to the concrete model implementation of the calculateEdgePotentials() function for more details
params_lenThe length of the params parameter
weightThe weighting parameter
Returns
Edge potentials on success: Mat(size: nStates x nStates; type: CV_32FC1)

Definition at line 111 of file TrainEdge.cpp.

Here is the call graph for this function:

◆ train()

virtual void DirectGraphicalModels::CTrainEdge::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::CTrainEdgeConcat< Trainer, Concatenator >, and DirectGraphicalModels::CTrainEdgePrior.

Definition at line 59 of file TrainEdge.h.


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