3 #include "TrainEdgePotts.h" 4 #include "TrainEdgePottsCS.h" 5 #include "TrainEdgePrior.h" 6 #include "TrainEdgeConcat.h" 8 #include "TrainNodeNaiveBayes.h" 9 #include "FeaturesConcatenator.h" 16 std::shared_ptr<CTrainEdge>
CTrainEdge::create(byte edgeRandomModel, byte nStates, word nFeatures)
18 switch (edgeRandomModel)
20 case EdgeRandomModel::Potts:
return std::make_shared<CTrainEdgePotts>(nStates, nFeatures);
21 case EdgeRandomModel::PottsCS:
return std::make_shared<CTrainEdgePottsCS>(nStates, nFeatures);
22 case EdgeRandomModel::Prior:
return std::make_shared<CTrainEdgePrior>(nStates, nFeatures);
23 case EdgeRandomModel::Concat:
return std::make_shared<CTrainEdgeConcat<CTrainNodeBayes, CDiffFeaturesConcatenator>>(nStates, nFeatures);
25 DGM_ASSERT_MSG(
false,
"Unknown type of the edge random model");
32 if (weight != 1.0f) pow(res, weight, res);
36 float *pRes = res.ptr<
float>(y);
38 for (byte x = 0; x <
m_nStates; x++) Sum += pRes[x];
39 if (Sum == 0)
continue;
40 for (byte x = 0; x <
m_nStates; x++) pRes[x] *= 100 / Sum;
49 size_t nStates = values.size();
50 Mat res(static_cast<int>(nStates), static_cast<int>(nStates), CV_32FC1, Scalar(1.0f));
51 for (byte s = 0; s < nStates; s++) res.at<
float>(s, s) = values[s];
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.
virtual Mat calculateEdgePotentials(const Mat &featureVector1, const Mat &featureVector2, const vec_float_t &vParams) const =0
Calculates the edge potential, based on the feature vectors.
static std::shared_ptr< CTrainEdge > create(byte edgeRandomModel, byte nStates, word nFeatures)
Factory method returning edge trainer object.
static Mat getDefaultEdgePotentials(float val, byte nStates)
Returns the data-independent edge potentials.
byte m_nStates
The number of states (classes)