Direct Graphical Models  v.1.7.0
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)=default
 
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)=default
 
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)
 
byte getNumStates (void) const
 Returns number of states (classes) 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, const vec_float_t &vParams) 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...
 

Private Attributes

std::unique_ptr< CPriorNodem_pPrior
 Node prior poobability More...
 
std::unique_ptr< CTrainNodem_pTrainer
 Node trainer More...
 
std::unique_ptr< CFeaturesConcatenatorm_pConcatenator
 Feature concatenator. More...
 
Mat m_featureVector
 Feature vector. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from DirectGraphicalModels::CTrainEdge
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 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 25 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 34 of file TrainEdgeConcat.h.

◆ 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 52 of file TrainEdgeConcat.h.

◆ ~CTrainEdgeConcat()

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

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 69 of file TrainEdgeConcat.h.

◆ calculateEdgePotentials()

template<class Trainer , class Concatenator >
virtual Mat DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::calculateEdgePotentials ( const Mat &  featureVector1,
const Mat &  featureVector2,
const vec_float_t &  vParams 
) 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
vParamsArray of control parameters \(\vec{\theta}\), which must consist from one parameter, specifying the largest value in the resulting edge potential.
Returns
The edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

Implements DirectGraphicalModels::CTrainEdge.

Definition at line 94 of file TrainEdgeConcat.h.

◆ 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 67 of file TrainEdgeConcat.h.

◆ 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 81 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 65 of file TrainEdgeConcat.h.

◆ 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 66 of file TrainEdgeConcat.h.

◆ 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 80 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 76 of file TrainEdgeConcat.h.

Member Data Documentation

◆ m_featureVector

template<class Trainer , class Concatenator >
Mat DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::m_featureVector
private

Feature vector.

Definition at line 121 of file TrainEdgeConcat.h.

◆ m_pConcatenator

template<class Trainer , class Concatenator >
std::unique_ptr<CFeaturesConcatenator> DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::m_pConcatenator
private

Feature concatenator.

Definition at line 120 of file TrainEdgeConcat.h.

◆ m_pPrior

template<class Trainer , class Concatenator >
std::unique_ptr<CPriorNode> DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::m_pPrior
private

Node prior poobability

Definition at line 118 of file TrainEdgeConcat.h.

◆ m_pTrainer

template<class Trainer , class Concatenator >
std::unique_ptr<CTrainNode> DirectGraphicalModels::CTrainEdgeConcat< Trainer, Concatenator >::m_pTrainer
private

Node trainer

Definition at line 119 of file TrainEdgeConcat.h.


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