Direct Graphical Models  v.1.7.0
GraphPairwiseExt.cpp
1 #include "GraphPairwiseExt.h"
2 #include "IGraphPairwise.h"
3 #include "TrainEdge.h"
4 #include "TrainEdgePottsCS.h"
5 #include "macroses.h"
6 
7 namespace DirectGraphicalModels
8 {
9  void CGraphPairwiseExt::addDefaultEdgesModel(float val, float weight)
10  {
11  if (weight != 1.0f) val = powf(val, weight);
12  const byte nStates = m_pGraphLayeredExt->getGraph().getNumStates();
13  m_pGraphLayeredExt->getGraph().setEdges({}, CTrainEdge::getDefaultEdgePotentials(sqrtf(val), nStates));
14  }
15 
16  void CGraphPairwiseExt::addDefaultEdgesModel(const Mat &featureVectors, float val, float weight)
17  {
18  const byte nStates = m_pGraphLayeredExt->getGraph().getNumStates();
19  const word nFeatures = featureVectors.channels();
20  const CTrainEdgePottsCS edgeTrainer(nStates, nFeatures);
21  fillEdges(edgeTrainer, featureVectors, { val, 0.001f }, weight);
22  }
23 
24  void CGraphPairwiseExt::addDefaultEdgesModel(const vec_mat_t &featureVectors, float val, float weight)
25  {
26  const byte nStates = m_pGraphLayeredExt->getGraph().getNumStates();
27  const word nFeatures = static_cast<word>(featureVectors.size());
28  const CTrainEdgePottsCS edgeTrainer(nStates, nFeatures);
29  fillEdges(edgeTrainer, featureVectors, { val, 0.001f }, weight);
30  }
31 }
void fillEdges(const CTrainEdge &edgeTrainer, const Mat &featureVectors, const vec_float_t &vParams, float weight=1.0f)
Fills the graph edges with potentials.
Contrast-Sensitive Potts training class.
void addDefaultEdgesModel(float val, float weight=1.0f) override
Adds default data-independet edge model.
std::unique_ptr< CGraphLayeredExt > m_pGraphLayeredExt
static Mat getDefaultEdgePotentials(float val, byte nStates)
Returns the data-independent edge potentials.
Definition: TrainEdge.h:74