Direct Graphical Models  v.1.5.2
DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator > Class Template Reference

Concatenated edge training class. More...

#include <TrainEdgeConcat.h>

Inheritance diagram for DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >:
Collaboration diagram for DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >:

Public Member Functions

 CTrainEdgeConcat (byte nStates, word nFeatures)
 Constructor. More...
 
template<class TrainerParams >
 CTrainEdgeConcat (byte nStates, word nFeatures, TrainerParams params)
 Constructor. More...
 
virtual ~CTrainEdgeConcat (void)
 
virtual void reset (void)
 Resets class variables. More...
 
void save (const std::string &path, const std::string &name=std::string(), short idx=-1) const
 Saves the training data. More...
 
void load (const std::string &path, const std::string &name=std::string(), short idx=-1)
 Loads the training data. More...
 
virtual void addFeatureVecs (const Mat &featureVector1, byte gt1, const Mat &featureVector2, byte gt2)
 Adds a pair of feature vectors. More...
 
virtual void train (bool doClean=false)
 Random model training. More...
 
- Public Member Functions inherited from DirectGraphicalModels::CTrainEdge
 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...
 
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)
 
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...
 
virtual Mat calculateEdgePotentials (const Mat &featureVector1, const Mat &featureVector2, float *params, size_t params_len) const
 Returns the data-dependent edge potentials. 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

CPriorNodem_pPrior
 Node prior poobability More...
 
CTrainNodem_pTrainer
 Node trainer More...
 
CFeaturesConcatenatorm_pConcatenator
 Feature concatenator. 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

template<class Trainer, class Concatenator>
class DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >

Concatenated edge training class.

This class in order to estimate edge potentials, uses an unary potential trainer, which is learned for \(nStates^2\) states (classes). Both edge feature vectors are concatenated in one feature vector, which in its turn, is used for the unary potential trainer. The feature concatenation is performed by the CFeaturesConcatenator class.

Template Parameters
TrainerThe nested node potential trainer, derived from the CTrainNode class
ConcatenatorThe feature concatenator, derived from the CFeaturesConcatenator class
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 TrainEdgeConcat.h.

Constructor & Destructor Documentation

◆ CTrainEdgeConcat() [1/2]

template<class Trainer, class Concatenator>
DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::CTrainEdgeConcat ( byte  nStates,
word  nFeatures 
)
inline

Constructor.

Parameters
nStatesNumber of states (classes)

Must be less then 16

nFeaturesNumber of features

Definition at line 33 of file TrainEdgeConcat.h.

Here is the call graph for this function:

◆ CTrainEdgeConcat() [2/2]

template<class Trainer, class Concatenator>
template<class TrainerParams >
DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::CTrainEdgeConcat ( byte  nStates,
word  nFeatures,
TrainerParams  params 
)
inline

Constructor.

Template Parameters
TrainerParamsType of the parameters to the nested node potential trainer
Parameters
nStatesNumber of states (classes)

Must be less then 16

nFeaturesNumber of features
paramsParameters of the nested node potential trainer

Definition at line 51 of file TrainEdgeConcat.h.

Here is the call graph for this function:

◆ ~CTrainEdgeConcat()

template<class Trainer, class Concatenator>
virtual DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::~CTrainEdgeConcat ( void  )
inlinevirtual

Definition at line 63 of file TrainEdgeConcat.h.

Member Function Documentation

◆ addFeatureVecs()

template<class Trainer, class Concatenator>
virtual void DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::addFeatureVecs ( const Mat &  featureVector1,
byte  gt1,
const Mat &  featureVector2,
byte  gt2 
)
inlinevirtual

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

Implements DirectGraphicalModels::CTrainEdge.

Definition at line 74 of file TrainEdgeConcat.h.

Here is the call graph for this function:

◆ calculateEdgePotentials()

template<class Trainer, class Concatenator>
virtual Mat DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::calculateEdgePotentials ( const Mat &  featureVector1,
const Mat &  featureVector2,
float *  params,
size_t  params_len 
) const
inlineprotectedvirtual

Returns the data-dependent edge potentials.

This function returns edge potential matrix, which elements are obrained from the unary potential vector:

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

The resulting edge potential matrix is normalized such that its largest element is equal to paramter \(\theta\), and then regularized as follows:

\[ edgePot_{s,s} = \left\{\begin{array}{ll} 1 &\mbox{ if $edgePot_{s,s}<1$} \\ edgePot_{s,s} &\mbox{ otherwise}\end{array} \right.\;\;\;\forall s\in\mathbb{S}.\]

Todo:
: Incorporate the node potential weight into the model parameters
Parameters
featureVector1Multi-dimensinal point \(\textbf{f}_1\): Mat(size: nFeatures x 1; type: CV_8UC1), corresponding to the first node of the edge
featureVector2Multi-dimensinal point \(\textbf{f}_2\): Mat(size: nFeatures x 1; type: CV_8UC1), corresponding to the second node of the edge
paramsArray of control parameters \(\vec{\theta}\), which must consist from one parameter, specifying the largest value in the resulting edge potential.
params_lenThe length of the params parameter. It must be equal to 1.
Returns
The edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

Implements DirectGraphicalModels::CTrainEdge.

Definition at line 101 of file TrainEdgeConcat.h.

Here is the call graph for this function:

◆ load()

template<class Trainer, class Concatenator>
void DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::load ( const std::string &  path,
const std::string &  name = std::string(),
short  idx = -1 
)
inlinevirtual

Loads the training data.

Allows to re-use the class. Loads data to the file: "<path><name>_<idx>.dat".

Parameters
pathPath to the folder, containing the data file.
nameName of data file. If empty, will be generated automatically from the class name.
idxIndex of the data file. Negative value means no index.

Reimplemented from DirectGraphicalModels::CBaseRandomModel.

Definition at line 72 of file TrainEdgeConcat.h.

Here is the call graph for this function:

◆ loadFile()

template<class Trainer, class Concatenator>
virtual void DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::loadFile ( FILE *  pFile)
inlineprotectedvirtual

Loads the random model from the file.

Allows to re-use the class.

Parameters
pFilePointer to the file, opened for reading.

Implements DirectGraphicalModels::CBaseRandomModel.

Definition at line 87 of file TrainEdgeConcat.h.

◆ reset()

template<class Trainer, class Concatenator>
virtual void DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::reset ( void  )
inlinevirtual

Resets class variables.

Allows to re-use the class.

Implements DirectGraphicalModels::CBaseRandomModel.

Definition at line 70 of file TrainEdgeConcat.h.

Here is the call graph for this function:

◆ save()

template<class Trainer, class Concatenator>
void DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::save ( const std::string &  path,
const std::string &  name = std::string(),
short  idx = -1 
) const
inlinevirtual

Saves the training data.

Allows to re-use the class. Stores data to the file: "<path><name>_<idx>.dat".

Parameters
pathPath to the destination folder.
nameName of data file. If empty, will be generated automatically from the class name.
idxIndex of the destination file. Negative value means no index.

Reimplemented from DirectGraphicalModels::CBaseRandomModel.

Definition at line 71 of file TrainEdgeConcat.h.

Here is the call graph for this function:

◆ saveFile()

template<class Trainer, class Concatenator>
virtual void DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::saveFile ( FILE *  pFile) const
inlineprotectedvirtual

Saves the random model into the file.

Allows to re-use the class.

Parameters
pFilePointer to the file, opened for writing.

Implements DirectGraphicalModels::CBaseRandomModel.

Definition at line 86 of file TrainEdgeConcat.h.

◆ train()

template<class Trainer, class Concatenator>
virtual void DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::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

Reimplemented from DirectGraphicalModels::CTrainEdge.

Definition at line 82 of file TrainEdgeConcat.h.

Here is the call graph for this function:

Member Data Documentation

◆ m_pConcatenator

template<class Trainer, class Concatenator>
CFeaturesConcatenator* DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::m_pConcatenator
protected

Feature concatenator.

Definition at line 128 of file TrainEdgeConcat.h.

◆ m_pPrior

template<class Trainer, class Concatenator>
CPriorNode* DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::m_pPrior
protected

Node prior poobability

Definition at line 126 of file TrainEdgeConcat.h.

◆ m_pTrainer

template<class Trainer, class Concatenator>
CTrainNode* DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::m_pTrainer
protected

Node trainer

Definition at line 127 of file TrainEdgeConcat.h.


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