Direct Graphical Models  v.1.7.0
GraphLayeredExt.h
1 // Extended (pairwise) Layered Graph class interface;
2 // Written by Sergey Kosov in 2016 for Project X
3 #pragma once
4 
5 #include "GraphExt.h"
6 #include <optional>
7 
8 namespace DirectGraphicalModels
9 {
10  class IGraphPairwise;
11  class CTrainEdge;
12  class CTrainLink;
13 
23  };
24 
25  // ================================ Extended Graph Class ================================
33  class CGraphLayeredExt : public CGraphExt
34  {
35  public:
42  DllExport CGraphLayeredExt(IGraphPairwise& graph, word nLayers, byte gType = GRAPH_EDGES_GRID) : m_graph(graph), m_nLayers(nLayers), m_gType(gType), m_size(Size(0, 0)) {}
43  DllExport virtual ~CGraphLayeredExt(void) = default;
44 
45  // From CGraphExt
52  DllExport void buildGraph(Size graphSize) override;
53  DllExport void setGraph(const Mat& pots) override;
59  DllExport void addDefaultEdgesModel(float val, float weight = 1.0f) override;
66  DllExport void addDefaultEdgesModel(const Mat &featureVectors, float val, float weight = 1.0f) override;
73  DllExport void addDefaultEdgesModel(const vec_mat_t &featureVectors, float val, float weight = 1.0f) override;
74  DllExport Size getSize() const override { return m_size; }
75 
87  DllExport void setGraph(const Mat &potBase, const Mat &potOccl);
97  DllExport void addFeatureVecs(CTrainEdge &edgeTrainer, const Mat &featureVectors, const Mat &gt);
107  DllExport void addFeatureVecs(CTrainEdge &edgeTrainer, const vec_mat_t &featureVectors, const Mat &gt);
120  DllExport void fillEdges(const CTrainEdge &edgeTrainer, const CTrainLink* linkTrainer, const Mat &featureVectors, const vec_float_t &vParams, float edgeWeight = 1.0f, float linkWeight = 1.0f);
133  DllExport void fillEdges(const CTrainEdge &edgeTrainer, const CTrainLink* linkTrainer, const vec_mat_t &featureVectors, const vec_float_t &vParams, float edgeWeight = 1.0f, float linkWeight = 1.0f);
142  DllExport void defineEdgeGroup(float A, float B, float C, byte group);
148  DllExport void setEdges(std::optional<byte> group, const Mat &pot);
153  DllExport byte getType(void) const { return m_gType; }
158  IGraphPairwise& getGraph(void) const { return m_graph; }
159 
160 
161  private:
163  const word m_nLayers;
164  const byte m_gType;
165  Size m_size;
166  };
167 }
CGraphLayeredExt(IGraphPairwise &graph, word nLayers, byte gType=GRAPH_EDGES_GRID)
Constructor.
virtual ~CGraphLayeredExt(void)=default
byte getType(void) const
Returns the type of the graph.
Vertical and horizontal edges.
graphEdgesType
Graph edges types.
void addFeatureVecs(CTrainEdge &edgeTrainer, const Mat &featureVectors, const Mat &gt)
Adds a block of new feature vectors.
void defineEdgeGroup(float A, float B, float C, byte group)
Assign the edges, which cross the given line to the grop group.
const word m_nLayers
Number of layers.
Base abstract class for edge potentials training.
Definition: TrainEdge.h:24
Size getSize() const override
Returns the size of the graph.
void addDefaultEdgesModel(float val, float weight=1.0f) override
Adds default data-independet edge model.
Base abstract class for link (inter-layer edge) potentials training.
Definition: TrainLink.h:17
General graph extension abstract class for 2D image classifaction.
Definition: GraphExt.h:16
IGraphPairwise & getGraph(void) const
Returns the reference to the graph.
void buildGraph(Size graphSize) override
Builds a 2D graph of size corresponding to the image resolution.
void setGraph(const Mat &pots) override
Fills an existing 2D graph with potentials or builds a new 2D graph of size corresponding to pots...
Extended Pairwise Layered graph class.
IGraphPairwise & m_graph
The graph.
const byte m_gType
Graph type (Ref. graphEdgesType)
Interface class for graphical models.
void setEdges(std::optional< byte > group, const Mat &pot)
Sets potential pot to all edges in the group group.
void fillEdges(const CTrainEdge &edgeTrainer, const CTrainLink *linkTrainer, const Mat &featureVectors, const vec_float_t &vParams, float edgeWeight=1.0f, float linkWeight=1.0f)
Fills the graph edges with potentials.