Direct Graphical Models  v.1.7.0
TrainEdgePrior.cpp
1 #include "TrainEdgePrior.h"
2 #include "macroses.h"
3 
4 namespace DirectGraphicalModels
5 {
6 // Constructor
7 CTrainEdgePrior::CTrainEdgePrior(byte nStates, word nFeatures, ePotPenalApproach penApproach, ePotNormApproach normApproach)
8  : CBaseRandomModel(nStates)
9  , CTrainEdgePottsCS(nStates, nFeatures, penApproach)
10  , CPriorEdge(nStates, normApproach)
11  , m_prior(Mat())
12 {}
13 
14 // Destructor
16 {
17  if (!m_prior.empty()) m_prior.release();
18 }
19 
20 // Resets <Prior> matrix
22 {
23  CPriorEdge::reset(); // resetting the prior histogram matrix
24  if (!m_prior.empty()) m_prior.release(); // resetting the prior
25 }
26 
27 void CTrainEdgePrior::addFeatureVecs(const Mat &, byte gt1, const Mat &, byte gt2)
28 {
30 }
31 
33 {
35 }
36 
37 void CTrainEdgePrior::saveFile(FILE *pFile) const
38 {
39  CPriorEdge::saveFile(pFile);
40 }
41 
42 void CTrainEdgePrior::loadFile(FILE *pFile)
43 {
44  CPriorEdge::loadFile(pFile);
45  loadPriorMatrix();
46 }
47 
48 Mat CTrainEdgePrior::calculateEdgePotentials(const Mat &featureVector1, const Mat &featureVector2, const vec_float_t &vParams) const
49 {
50  Mat res = CTrainEdgePottsCS::calculateEdgePotentials(featureVector1, featureVector2, vParams);
51  multiply(res, m_prior, res);
52  return res;
53 }
54 
56 {
57  if (!m_prior.empty()) m_prior.release();
58  m_prior = getPrior();
59 }
60 
61 }
virtual void loadFile(FILE *pFile)
Loads the random model from the file.
Definition: Prior.cpp:55
Contrast-Sensitive Potts training class.
void addEdgeGroundTruth(byte gt1, byte gt2)
Adds the groud-truth value to the co-occurance histogram matrix.
Definition: PriorEdge.cpp:6
Base abstract class for random model training.
virtual void reset(void)
Resets class variables.
void reset(void)
Resets class variables.
Definition: Prior.cpp:19
virtual void saveFile(FILE *pFile) const
Saves the random model into the file.
Definition: Prior.cpp:34
Mat getPrior(float weight=1.0f) const
Returns the prior probabilies.
Definition: Prior.cpp:24
CTrainEdgePrior(byte nStates, word nFeatures, ePotPenalApproach penApproach=eP_APP_PEN_EXP, ePotNormApproach normApproach=eP_APP_NORM_SYMMETRIC)
Constructor.
Edge prior probability estimation class.
Definition: PriorEdge.h:38
virtual void loadFile(FILE *pFile)
Loads the random model from the file.
virtual Mat calculateEdgePotentials(const Mat &featureVector1, const Mat &featureVector2, const vec_float_t &vParams) const
Calculates the edge potential, based on the feature vectors.
ePotPenalApproach
Penalization approach flag.
virtual void addFeatureVecs(const Mat &featureVector1, byte gt1, const Mat &featureVector2, byte gt2)
Adds a pair of feature vectors.
virtual void train(bool doClean=false)
Random model training.
virtual void saveFile(FILE *pFile) const
Saves the random model into the file.
ePotNormApproach
Normalization approach flag.
Definition: PriorEdge.h:27
virtual Mat calculateEdgePotentials(const Mat &featureVector1, const Mat &featureVector2, const vec_float_t &vParams) const
Returns the contrast-sensitive edge potentials.