Direct Graphical Models  v.1.7.0
TrainNode.h
1 // Base abstract class for random model nodes training
2 // Written by Sergey G. Kosov in 2013 for Project X
3 #pragma once
4 
5 #include "ITrain.h"
6 
7 namespace DirectGraphicalModels
8 {
10  enum NodeRandomModel : byte {
11  Bayes = 0,
12  GMM,
14  KNN,
16  CvRF,
17  MsRF,
20 
21  GM,
22  CvGM,
23  };
24 
25  // ============================= Node Train Class =============================
47  class CTrainNode : public ITrain
48  {
49  public:
55  DllExport CTrainNode(byte nStates, word nFeatures)
56  : CBaseRandomModel(nStates)
57  , ITrain(nStates, nFeatures)
58  , m_mask(nStates, 1, CV_8UC1)
59  {}
60  DllExport virtual ~CTrainNode(void) = default;
61 
70  DllExport static std::shared_ptr<CTrainNode> create(byte nodeRandomModel, byte nStates, word nFeatures);
77  DllExport void addFeatureVecs(const Mat &featureVectors, const Mat &gt);
84  DllExport void addFeatureVecs(const vec_mat_t &featureVectors, const Mat &gt);
91  DllExport virtual void addFeatureVec(const Mat &featureVector, byte gt) = 0;
92  DllExport virtual void train(bool doClean = false) {}
101  DllExport Mat getNodePotentials(const Mat &featureVectors, const Mat &weights = Mat(), float Z = 0.0f) const;
110  DllExport Mat getNodePotentials(const vec_mat_t &featureVectors, const Mat &weights = Mat(), float Z = 0.0f) const;
122  DllExport Mat getNodePotentials(const Mat &featureVector, float weight, float Z = 0.0f) const;
123 
124 
125  protected:
135  DllExport virtual void calculateNodePotentials(const Mat &featureVector, Mat &potential, Mat &mask) const = 0;
136 
137 
138  private:
139  Mat m_mask;
140  };
141 }
142 
Gaussian Model.
Definition: TrainNode.h:21
MicroSoft Random Forest.
Definition: TrainNode.h:17
void addFeatureVecs(const Mat &featureVectors, const Mat &gt)
Adds a block of new feature vectors.
Definition: TrainNode.cpp:42
OpenCV Gaussian Model.
Definition: TrainNode.h:22
virtual void calculateNodePotentials(const Mat &featureVector, Mat &potential, Mat &mask) const =0
Calculates the node potential, based on the feature vector.
OpenCV Artificial Neural Network.
Definition: TrainNode.h:18
OpenCV Gaussian Mixture Model.
Definition: TrainNode.h:13
virtual ~CTrainNode(void)=default
Base abstract class for random model training.
Mat getNodePotentials(const Mat &featureVectors, const Mat &weights=Mat(), float Z=0.0f) const
Returns a block of node potentials, based on the block of feature vector.
Definition: TrainNode.cpp:54
NodeRandomModel
Types of the node potential finction.
Definition: TrainNode.h:10
OpenCV Support Vector Machines.
Definition: TrainNode.h:19
OpenCV Nearest Neighbor.
Definition: TrainNode.h:15
OpenCV Random Forest.
Definition: TrainNode.h:16
static std::shared_ptr< CTrainNode > create(byte nodeRandomModel, byte nStates, word nFeatures)
Factory method returning node trainer object.
Definition: TrainNode.cpp:20
Base abstract class for node potentials training.
Definition: TrainNode.h:47
virtual void addFeatureVec(const Mat &featureVector, byte gt)=0
Adds new feature vector.
Nearest Neighbor.
Definition: TrainNode.h:14
Gaussian Mixture Model.
Definition: TrainNode.h:12
CTrainNode(byte nStates, word nFeatures)
Constructor.
Definition: TrainNode.h:55
virtual void train(bool doClean=false)
Random model training.
Definition: TrainNode.h:92
Interface class for random model training.
Definition: ITrain.h:15