Direct Graphical Models  v.1.7.0
DirectGraphicalModels::CTrainEdgePrior Class Reference

Contrast-Sensitive Potts training with edge prior probability class. More...

#include <TrainEdgePrior.h>

Inheritance diagram for DirectGraphicalModels::CTrainEdgePrior:
Collaboration diagram for DirectGraphicalModels::CTrainEdgePrior:

Public Member Functions

 CTrainEdgePrior (byte nStates, word nFeatures, ePotPenalApproach penApproach=eP_APP_PEN_EXP, ePotNormApproach normApproach=eP_APP_NORM_SYMMETRIC)
 Constructor. More...
 
virtual ~CTrainEdgePrior (void)
 
virtual void reset (void)
 Resets class variables. 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::CTrainEdgePottsCS
 CTrainEdgePottsCS (byte nStates, word nFeatures, ePotPenalApproach penApproach=eP_APP_PEN_EXP)
 Constructor. More...
 
virtual ~CTrainEdgePottsCS (void)
 
- Public Member Functions inherited from DirectGraphicalModels::CTrainEdgePotts
 CTrainEdgePotts (byte nStates, word nFeatures)
 Constructor. More...
 
virtual ~CTrainEdgePotts (void)
 
- 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)
 
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...
 

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
 Calculates the edge potential, based on the feature vectors. 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 Member Functions

void loadPriorMatrix (void)
 
- Private Member Functions inherited from DirectGraphicalModels::CPriorEdge
 CPriorEdge (byte nStates, ePotNormApproach normApp=eP_APP_NORM_SYMMETRIC)
 Constructor. More...
 
 ~CPriorEdge (void)
 
void addEdgeGroundTruth (byte gt1, byte gt2)
 Adds the groud-truth value to the co-occurance histogram matrix. More...
 
Mat calculatePrior (void) const
 Returns the prior edge probability. More...
 
- Private Member Functions inherited from DirectGraphicalModels::CPrior
 CPrior (byte nStates, RandomModelType type)
 Constructor. More...
 
 ~CPrior (void)
 
Mat getPrior (float weight=1.0f) const
 Returns the prior probabilies. More...
 
- Private Member Functions inherited from DirectGraphicalModels::CBaseRandomModel
 CBaseRandomModel (byte nStates)
 Constructor. More...
 
virtual ~CBaseRandomModel (void)
 
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...
 
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_prior
 
- Private Attributes inherited from DirectGraphicalModels::CPrior
Mat m_histogramPrior
 The class cooccurance histogram. More...
 
- Private Attributes inherited from DirectGraphicalModels::CBaseRandomModel
byte m_nStates
 The number of states (classes) 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

Contrast-Sensitive Potts training with edge prior probability class.

This class improves the CTrainEdgePottsCS class by considering the prior probability of an edge to connect two nodes with concrete states (classes).

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 17 of file TrainEdgePrior.h.

Constructor & Destructor Documentation

◆ CTrainEdgePrior()

DirectGraphicalModels::CTrainEdgePrior::CTrainEdgePrior ( byte  nStates,
word  nFeatures,
ePotPenalApproach  penApproach = eP_APP_PEN_EXP,
ePotNormApproach  normApproach = eP_APP_NORM_SYMMETRIC 
)

Constructor.

Parameters
nStatesNumber of states (classes)
nFeaturesNumber of features
penApproachFlag specifying the penalization approach for the edge potential matrix (Ref. ePotPenalApproach)
normApproachFlag specifying the co-occurance histogram matrix normalization approach (Ref. ePotNormApproach)

Definition at line 7 of file TrainEdgePrior.cpp.

◆ ~CTrainEdgePrior()

DirectGraphicalModels::CTrainEdgePrior::~CTrainEdgePrior ( void  )
virtual

Definition at line 15 of file TrainEdgePrior.cpp.

Member Function Documentation

◆ addFeatureVecs()

void DirectGraphicalModels::CTrainEdgePrior::addFeatureVecs ( const Mat &  featureVector1,
byte  gt1,
const Mat &  featureVector2,
byte  gt2 
)
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

Reimplemented from DirectGraphicalModels::CTrainEdgePotts.

Definition at line 27 of file TrainEdgePrior.cpp.

Here is the call graph for this function:

◆ calculateEdgePotentials()

Mat DirectGraphicalModels::CTrainEdgePrior::calculateEdgePotentials ( const Mat &  featureVector1,
const Mat &  featureVector2,
const vec_float_t &  vParams 
) const
protectedvirtual

Calculates the edge potential, based on the feature vectors.

This function returns matrix with diagonal elements equal to parameter \(\vec{\theta}\) provided through argument params penalized with a penalization function \(\mathcal{P}\), which depends on the difference between arguments featureVector1 and featureVector2 and multiplied with the corresponding edge prior probability; all the other elements are the edge prior probability matrix values:

\[edgePot[nStates][nStates] = \begin{bmatrix} \theta_1\cdot\mathcal{P}\cdot p_{1,1} & p_{1,2} & \cdots & p_{1,n} \\ p_{2,1} & \theta_2\cdot\mathcal{P}\cdot p_{2,2} & \cdots & p_{2,n} \\ \vdots & \vdots & \ddots & \vdots \\ p_{n,1} & p_{n,2} & \cdots & \theta_n\cdot\mathcal{P}\cdot p_{n,n} \end{bmatrix}, \]

where \(p_{i,j}\) is the normalized according to ePotNormApproach prior probability of edge to connect nodes with states (classes) i and j, \(\mathcal{P}\equiv\mathcal{P}(d;\,\lambda)\) is the penalization function, where \(d = ||\textbf{f}_1 - \textbf{f}_2||_2\) is the Euclidean distance between feature vectors,
and \(\lambda\) is a parameter provided through argument params. For more details on penalization fuction, please refere to ePotPenalApproach.

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 \(\{\vec{\theta},\lambda\} \). \(\vec{\theta}\) may consist either from one parameter (in this case all the diagonal elemets will be the same), or from nStates parameters, specifying smoothness strength for each state (class) individually; \(\lambda\) consists from one parameter.
Returns
The edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

Reimplemented from DirectGraphicalModels::CTrainEdgePottsCS.

Definition at line 48 of file TrainEdgePrior.cpp.

Here is the call graph for this function:

◆ loadFile()

void DirectGraphicalModels::CTrainEdgePrior::loadFile ( FILE *  pFile)
protectedvirtual

Loads the random model from the file.

Allows to re-use the class.

Parameters
pFilePointer to the file, opened for reading.

Reimplemented from DirectGraphicalModels::CPrior.

Definition at line 42 of file TrainEdgePrior.cpp.

Here is the call graph for this function:

◆ loadPriorMatrix()

void DirectGraphicalModels::CTrainEdgePrior::loadPriorMatrix ( void  )
inlineprivate

Definition at line 55 of file TrainEdgePrior.cpp.

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

◆ reset()

void DirectGraphicalModels::CTrainEdgePrior::reset ( void  )
virtual

Resets class variables.

Allows to re-use the class.

Reimplemented from DirectGraphicalModels::CPrior.

Definition at line 21 of file TrainEdgePrior.cpp.

Here is the call graph for this function:

◆ saveFile()

void DirectGraphicalModels::CTrainEdgePrior::saveFile ( FILE *  pFile) const
protectedvirtual

Saves the random model into the file.

Allows to re-use the class.

Parameters
pFilePointer to the file, opened for writing.

Reimplemented from DirectGraphicalModels::CPrior.

Definition at line 37 of file TrainEdgePrior.cpp.

Here is the call graph for this function:

◆ train()

void DirectGraphicalModels::CTrainEdgePrior::train ( bool  doClean = false)
virtual

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 32 of file TrainEdgePrior.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ m_prior

Mat DirectGraphicalModels::CTrainEdgePrior::m_prior
private

Definition at line 63 of file TrainEdgePrior.h.


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