Direct Graphical Models  v.1.7.0
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)=default
 
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, const vec_float_t &vParams, 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)=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< CTrainEdgecreate (byte edgeRandomModel, byte nStates, word nFeatures)
 Factory method returning edge trainer object. More...
 
static Mat getDefaultEdgePotentials (float val, byte nStates)
 Returns the data-independent edge potentials. More...
 
static Mat getDefaultEdgePotentials (const vec_float_t &values)
 Returns the data-independent edge potentials. More...
 

Protected Member Functions

virtual Mat calculateEdgePotentials (const Mat &featureVector1, const Mat &featureVector2, const vec_float_t &vParams) 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::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 24 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 32 of file TrainEdge.h.

◆ ~CTrainEdge()

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

Member Function Documentation

◆ addFeatureVecs()

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.

Here is the caller graph for this function:

◆ calculateEdgePotentials()

virtual Mat DirectGraphicalModels::CTrainEdge::calculateEdgePotentials ( const Mat &  featureVector1,
const Mat &  featureVector2,
const vec_float_t &  vParams 
) 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
vParamsArray of control parameters. Please refere to the concrete model implementation of the calculateEdgePotentials() function for more details
Returns
The edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

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

Here is the caller graph for this function:

◆ create()

std::shared_ptr< CTrainEdge > DirectGraphicalModels::CTrainEdge::create ( byte  edgeRandomModel,
byte  nStates,
word  nFeatures 
)
static

Factory method returning edge trainer object.

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

Definition at line 16 of file TrainEdge.cpp.

◆ getDefaultEdgePotentials() [1/2]

static Mat DirectGraphicalModels::CTrainEdge::getDefaultEdgePotentials ( float  val,
byte  nStates 
)
inlinestatic

Returns the data-independent edge potentials.

This function returns matrix with diagonal elements equal to the argument val, all the other elements are 1's, what imitates the Potts model.

\[edgePot[nStates][nStates] = \begin{bmatrix} val & 1 & \cdots & 1 \\ 1 & val & \cdots & 1 \\ \vdots & \vdots & \ddots & \vdots \\ 1 & 1 & \cdots & val \end{bmatrix} \]

Parameters
valThe diagonal element of the matrix
nStatesNumber of states (classes)
Returns
The edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

Definition at line 74 of file TrainEdge.h.

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

◆ getDefaultEdgePotentials() [2/2]

Mat DirectGraphicalModels::CTrainEdge::getDefaultEdgePotentials ( const vec_float_t &  values)
static

Returns the data-independent edge potentials.

This function returns matrix with diagonal elements specified by argument array values, all the other elements are 1's, what imitates the Potts model.

\[edgePot[nStates][nStates] = \begin{bmatrix} values_1 & 1 & \cdots & 1 \\ 1 & values_2 & \cdots & 1 \\ \vdots & \vdots & \ddots & \vdots \\ 1 & 1 & \cdots & values_{nStates} \end{bmatrix} \]

Parameters
valuesThe array of diagonal elements of the matrix. In must include nStates values, specifying smoothness strength for each state (class) individually.
Returns
The edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

Definition at line 47 of file TrainEdge.cpp.

◆ getEdgePotentials()

Mat DirectGraphicalModels::CTrainEdge::getEdgePotentials ( const Mat &  featureVector1,
const Mat &  featureVector2,
const vec_float_t &  vParams,
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
vParamsArray of control parameters. Please refer to the concrete model implementation of the calculateEdgePotentials() function for more details
weightThe weighting parameter
Returns
Edge potentials on success: Mat(size: nStates x nStates; type: CV_32FC1)

Definition at line 29 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 54 of file TrainEdge.h.


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