Direct Graphical Models
v.1.7.0
|
Contrast-Sensitive Potts training with edge prior probability class. More...
#include <TrainEdgePrior.h>
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< CTrainEdge > | create (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... | |
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).
Definition at line 17 of file TrainEdgePrior.h.
DirectGraphicalModels::CTrainEdgePrior::CTrainEdgePrior | ( | byte | nStates, |
word | nFeatures, | ||
ePotPenalApproach | penApproach = eP_APP_PEN_EXP , |
||
ePotNormApproach | normApproach = eP_APP_NORM_SYMMETRIC |
||
) |
Constructor.
nStates | Number of states (classes) |
nFeatures | Number of features |
penApproach | Flag specifying the penalization approach for the edge potential matrix (Ref. ePotPenalApproach) |
normApproach | Flag specifying the co-occurance histogram matrix normalization approach (Ref. ePotNormApproach) |
Definition at line 7 of file TrainEdgePrior.cpp.
|
virtual |
Definition at line 15 of file TrainEdgePrior.cpp.
|
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.
featureVector1 | Multi-dimensinal point: Mat(size: nFeatures x 1; type: CV_8UC1), corresponding to the first node of the edge. |
gt1 | The ground-truth state (class) of the first node of the edge, given by featureVector1 |
featureVector2 | Multi-dimensinal point: Mat(size: nFeatures x 1; type: CV_8UC1), corresponding to the second node of the edge. |
gt2 | The 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.
|
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.
featureVector1 | Multi-dimensinal point \(\textbf{f}_1\): Mat(size: nFeatures x 1; type: CV_{XX}C1), corresponding to the first node of the edge |
featureVector2 | Multi-dimensinal point \(\textbf{f}_2\): Mat(size: nFeatures x 1; type: CV_{XX}C1), corresponding to the second node of the edge |
vParams | Array 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. |
Reimplemented from DirectGraphicalModels::CTrainEdgePottsCS.
Definition at line 48 of file TrainEdgePrior.cpp.
|
protectedvirtual |
Loads the random model from the file.
Allows to re-use the class.
pFile | Pointer to the file, opened for reading. |
Reimplemented from DirectGraphicalModels::CPrior.
Definition at line 42 of file TrainEdgePrior.cpp.
|
inlineprivate |
Definition at line 55 of file TrainEdgePrior.cpp.
|
virtual |
Resets class variables.
Allows to re-use the class.
Reimplemented from DirectGraphicalModels::CPrior.
Definition at line 21 of file TrainEdgePrior.cpp.
|
protectedvirtual |
Saves the random model into the file.
Allows to re-use the class.
pFile | Pointer to the file, opened for writing. |
Reimplemented from DirectGraphicalModels::CPrior.
Definition at line 37 of file TrainEdgePrior.cpp.
|
virtual |
Random model training.
Auxilary function for training - some derived classes may use this function inbetween training and classification phases
doClean | Flag 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.
|
private |
Definition at line 63 of file TrainEdgePrior.h.