Direct Graphical Models  v.1.5.1
DirectGraphicalModels::CTrainEdgePotts Class Reference

Potts edge training class. More...

#include <TrainEdgePotts.h>

Inheritance diagram for DirectGraphicalModels::CTrainEdgePotts:
Collaboration diagram for DirectGraphicalModels::CTrainEdgePotts:

Public Member Functions

 CTrainEdgePotts (byte nStates, word nFeatures)
 Constructor. More...
 
virtual ~CTrainEdgePotts (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...
 
- 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...
 
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 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...
 

Static Public Member Functions

static Mat getEdgePotentials (float val, byte nStates)
 Returns the data-independent edge potentials. More...
 
static Mat getEdgePotentials (float *values, byte nStates)
 Returns the data-independent edge potentials. 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-independent 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...
 

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

Potts edge training class.

This class implements the Potts model for edge (pairwise) potentials, which is both training- and test-data-independent, and thus may be applied without edge training procedure, i.e. functions reset(), save(), load(), addFeatureVecs() are unnecessary here.

This class may be used in case when the training- and test-data for edges is not available.

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 19 of file TrainEdgePotts.h.

Constructor & Destructor Documentation

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

Constructor.

Parameters
nStatesNumber of states (classes)
nFeaturesNumber of features

Definition at line 27 of file TrainEdgePotts.h.

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

Definition at line 28 of file TrainEdgePotts.h.

Member Function Documentation

virtual void DirectGraphicalModels::CTrainEdgePotts::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.

Reimplemented in DirectGraphicalModels::CTrainEdgePrior.

Definition at line 32 of file TrainEdgePotts.h.

Mat DirectGraphicalModels::CTrainEdgePotts::calculateEdgePotentials ( const Mat &  featureVector1,
const Mat &  featureVector2,
float *  params,
size_t  params_len 
) const
protectedvirtual

Returns the data-independent edge potentials.

This function returns matrix with diagonal elements equal to parameter \(\vec{\theta}\) provided through argument params; all the other elements are 1's - this imitates the Potts model.

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

Parameters
featureVector1Multi-dimensinal point \(\textbf{f}_1\): Mat(size: nFeatures x 1; type: CV_{XX}C1), corresponding to the first node of the edge

It is not used in the Potts model, thus may be empty Mat()

featureVector2Multi-dimensinal point \(\textbf{f}_2\): Mat(size: nFeatures x 1; type: CV_{XX}C1), corresponding to the second node of the edge

It is not used in the Potts model, thus may be empty Mat()

paramsArray of control parameters \(\vec{\theta}\), which 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.
params_lenThe length of the params parameter. It must be equal to (1 || nStates).
Returns
The edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

Implements DirectGraphicalModels::CTrainEdge.

Reimplemented in DirectGraphicalModels::CTrainEdgePottsCS, and DirectGraphicalModels::CTrainEdgePrior.

Definition at line 23 of file TrainEdgePotts.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Mat DirectGraphicalModels::CTrainEdgePotts::getEdgePotentials ( float  val,
byte  nStates 
)
static

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 8 of file TrainEdgePotts.cpp.

Here is the caller graph for this function:

Mat DirectGraphicalModels::CTrainEdgePotts::getEdgePotentials ( float *  values,
byte  nStates 
)
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.
nStatesNumber of states (classes)
Returns
The edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

Definition at line 16 of file TrainEdgePotts.cpp.

virtual void DirectGraphicalModels::CTrainEdgePotts::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.

Reimplemented in DirectGraphicalModels::CTrainEdgePrior.

Definition at line 55 of file TrainEdgePotts.h.

virtual void DirectGraphicalModels::CTrainEdgePotts::reset ( void  )
inlinevirtual

Resets class variables.

Allows to re-use the class.

Implements DirectGraphicalModels::CBaseRandomModel.

Reimplemented in DirectGraphicalModels::CTrainEdgePrior.

Definition at line 30 of file TrainEdgePotts.h.

virtual void DirectGraphicalModels::CTrainEdgePotts::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.

Reimplemented in DirectGraphicalModels::CTrainEdgePrior.

Definition at line 54 of file TrainEdgePotts.h.


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