Direct Graphical Models  v.1.7.0
DirectGraphicalModels::CGraphPairwise Class Reference

Pairwise graph class. More...

#include <GraphPairwise.h>

Inheritance diagram for DirectGraphicalModels::CGraphPairwise:
Collaboration diagram for DirectGraphicalModels::CGraphPairwise:

Public Member Functions

 CGraphPairwise (byte nStates)
 Constructor. More...
 
virtual ~CGraphPairwise (void)=default
 
void reset (void) override
 Resets the graph. More...
 
size_t addNode (const Mat &pot=EmptyMat) override
 Adds an additional node (with specified potentional) More...
 
void setNode (size_t node, const Mat &pot) override
 Sets or changes the potential of node. More...
 
void getNode (size_t node, Mat &pot) const override
 Returns the node potential. More...
 
void getChildNodes (size_t node, vec_size_t &vNodes) const override
 Returns the set of IDs of the child nodes of the argument node. More...
 
void getParentNodes (size_t node, vec_size_t &vNodes) const override
 Returns the set of IDs of the parent nodes of the argument node. More...
 
size_t getNumNodes (void) const override
 Returns the number of nodes in the graph. More...
 
size_t getNumEdges (void) const override
 Returns the number of edges in the graph. More...
 
void addEdge (size_t srcNode, size_t dstNode, byte group, const Mat &pot) override
 Adds an additional directed edge with specified potentional. More...
 
void setEdge (size_t srcNode, size_t dstNode, const Mat &pot) override
 Sets or changes the potentional of directed edge. More...
 
void setEdges (std::optional< byte > group, const Mat &pot) override
 Sets the potential pot to all edges belonging to group group. More...
 
void getEdge (size_t srcNode, size_t dstNode, Mat &pot) const override
 Returns the edge potential. More...
 
void setEdgeGroup (size_t srcNode, size_t dstNode, byte group) override
 Assigns a directed edge (srcNode) –> (dstNode) to the group group. More...
 
byte getEdgeGroup (size_t srcNode, size_t dstNode) const override
 Returns the group of the edge. More...
 
void removeEdge (size_t srcNode, size_t dstNode) override
 Removes the specified edge. More...
 
bool isEdgeExists (size_t srcNode, size_t dstNode) const override
 Checks whether the edge exists. More...
 
- Public Member Functions inherited from DirectGraphicalModels::IGraphPairwise
 IGraphPairwise (byte nStates)
 Constructor. More...
 
virtual ~IGraphPairwise (void)=default
 
void marginalize (const vec_size_t &nodes)
 Marginalizes a set of nodes. More...
 
void addEdge (size_t srcNode, size_t dstNode, const Mat &pot=EmptyMat)
 Adds an additional directed edge with specified potentional. More...
 
virtual bool isEdgeArc (size_t srcNode, size_t dstNode) const
 Checks whether the edge is a part of an arc. More...
 
void addArc (size_t Node1, size_t Node2, const Mat &pot=EmptyMat)
 Adds an additional udirected edge (arc) with specified potentional. More...
 
virtual void addArc (size_t Node1, size_t Node2, byte group, const Mat &pot)
 Adds an additional udirected edge (arc) with specified potentional. More...
 
virtual void setArc (size_t Node1, size_t Node2, const Mat &pot)
 Sets or changes the potentional of udirected edge (arc) More...
 
virtual void setArcGroup (size_t Node1, size_t Node2, byte group)
 Assigns an undirected edge (arc) (Node1) – (Node2) to the group group. More...
 
virtual void removeArc (size_t Node1, size_t Node2)
 Removes the specified arc. More...
 
virtual bool isArcExists (size_t Node1, size_t Node2) const
 Checks whether the arc exists. More...
 
- Public Member Functions inherited from DirectGraphicalModels::CGraph
 CGraph (byte nStates)
 Constructor. More...
 
 CGraph (const CGraph &)=delete
 
virtual ~CGraph (void)=default
 
const CGraphoperator= (const CGraph &)=delete
 
virtual void addNodes (const Mat &pots)
 Adds the graph nodes with potentials. More...
 
virtual void setNodes (size_t start_node, const Mat &pots)
 Fills the graph nodes with new potentials. More...
 
virtual void getNodes (size_t start_node, size_t num_nodes, Mat &pots) const
 Returns the node potentials. More...
 
byte getNumStates (void) const
 Returns number of states (classes) More...
 

Private Member Functions

void removeEdge (size_t edge)
 Removes the specified edge. More...
 

Private Attributes

size_t m_IDx
 
vec_node_t m_vNodes
 
vec_edge_t m_vEdges
 

Friends

class CMessagePassing
 
class CInferChain
 
class CInferTree
 
class CInferLBP
 
class CInferViterbi
 
class CInferTRW
 

Detailed Description

Pairwise graph class.

Author
Sergey G. Kosov, serge.nosp@m.y.ko.nosp@m.sov@p.nosp@m.roje.nosp@m.ct-10.nosp@m..de

Definition at line 64 of file GraphPairwise.h.

Constructor & Destructor Documentation

◆ CGraphPairwise()

DirectGraphicalModels::CGraphPairwise::CGraphPairwise ( byte  nStates)
inline

Constructor.

Parameters
nStatesthe number of States (classes)

Definition at line 79 of file GraphPairwise.h.

◆ ~CGraphPairwise()

virtual DirectGraphicalModels::CGraphPairwise::~CGraphPairwise ( void  )
virtualdefault

Member Function Documentation

◆ addEdge()

void DirectGraphicalModels::CGraphPairwise::addEdge ( size_t  srcNode,
size_t  dstNode,
byte  group,
const Mat &  pot 
)
overridevirtual

Adds an additional directed edge with specified potentional.

Parameters
srcNodeindex of the source node
dstNodeindex of the destination node
groupThe edge group ID
potEdge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

Implements DirectGraphicalModels::IGraphPairwise.

Definition at line 56 of file GraphPairwise.cpp.

◆ addNode()

size_t DirectGraphicalModels::CGraphPairwise::addNode ( const Mat &  pot = EmptyMat)
overridevirtual

Adds an additional node (with specified potentional)

Parameters
potnode potential vector: Mat(size: nStates x 1; type: CV_32FC1)
Returns
the node's ID

Implements DirectGraphicalModels::CGraph.

Definition at line 14 of file GraphPairwise.cpp.

◆ getChildNodes()

void DirectGraphicalModels::CGraphPairwise::getChildNodes ( size_t  node,
vec_size_t &  vNodes 
) const
overridevirtual

Returns the set of IDs of the child nodes of the argument node.

Parameters
[in]nodenode index
[out]vNodesvector with the child node's ID

Implements DirectGraphicalModels::CGraph.

Definition at line 39 of file GraphPairwise.cpp.

Here is the call graph for this function:

◆ getEdge()

void DirectGraphicalModels::CGraphPairwise::getEdge ( size_t  srcNode,
size_t  dstNode,
Mat &  pot 
) const
overridevirtual

Returns the edge potential.

Parameters
[in]srcNodeindex of the source node
[in]dstNodeindex of the destination node
[out]potedge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1) if exists, empty Mat otherwise

Implements DirectGraphicalModels::IGraphPairwise.

Definition at line 109 of file GraphPairwise.cpp.

◆ getEdgeGroup()

byte DirectGraphicalModels::CGraphPairwise::getEdgeGroup ( size_t  srcNode,
size_t  dstNode 
) const
overridevirtual

Returns the group of the edge.

Parameters
srcNodeindex of the source node
dstNodeindex of the destination node
Returns
The edge group ID

Implements DirectGraphicalModels::IGraphPairwise.

Definition at line 132 of file GraphPairwise.cpp.

◆ getNode()

void DirectGraphicalModels::CGraphPairwise::getNode ( size_t  node,
Mat &  pot 
) const
overridevirtual

Returns the node potential.

Parameters
[in]nodenode index
[out]potnode potential vector: Mat(size: nStates x 1; type: CV_32FC1)

Implements DirectGraphicalModels::CGraph.

Definition at line 31 of file GraphPairwise.cpp.

◆ getNumEdges()

size_t DirectGraphicalModels::CGraphPairwise::getNumEdges ( void  ) const
inlineoverridevirtual

Returns the number of edges in the graph.

Returns
number of edges

Implements DirectGraphicalModels::CGraph.

Definition at line 90 of file GraphPairwise.h.

◆ getNumNodes()

size_t DirectGraphicalModels::CGraphPairwise::getNumNodes ( void  ) const
inlineoverridevirtual

Returns the number of nodes in the graph.

Returns
number of nodes

Implements DirectGraphicalModels::CGraph.

Definition at line 89 of file GraphPairwise.h.

Here is the caller graph for this function:

◆ getParentNodes()

void DirectGraphicalModels::CGraphPairwise::getParentNodes ( size_t  node,
vec_size_t &  vNodes 
) const
overridevirtual

Returns the set of IDs of the parent nodes of the argument node.

Parameters
[in]nodenode index
[out]vNodesvector with the parent node's ID

Implements DirectGraphicalModels::CGraph.

Definition at line 47 of file GraphPairwise.cpp.

Here is the call graph for this function:

◆ isEdgeExists()

bool DirectGraphicalModels::CGraphPairwise::isEdgeExists ( size_t  srcNode,
size_t  dstNode 
) const
overridevirtual

Checks whether the edge exists.

Parameters
srcNodeindex of the source node
dstNodeindex of the destination node
Return values
trueif the edge exists
falseotherwise

Implements DirectGraphicalModels::IGraphPairwise.

Definition at line 155 of file GraphPairwise.cpp.

◆ removeEdge() [1/2]

void DirectGraphicalModels::CGraphPairwise::removeEdge ( size_t  srcNode,
size_t  dstNode 
)
overridevirtual

Removes the specified edge.

Parameters
srcNodeindex of the source node
dstNodeindex of the destination node

Implements DirectGraphicalModels::IGraphPairwise.

Definition at line 143 of file GraphPairwise.cpp.

◆ removeEdge() [2/2]

void DirectGraphicalModels::CGraphPairwise::removeEdge ( size_t  edge)
private

Removes the specified edge.

Parameters
edgeindex of the edge
Todo:
Optimize the edge removement

Definition at line 169 of file GraphPairwise.cpp.

◆ reset()

void DirectGraphicalModels::CGraphPairwise::reset ( void  )
overridevirtual

Resets the graph.

This function allows to re-use the graph or update node potential, while preserving the graph structure. It deletes all the nodes and edges and sets node index to zero.

Implements DirectGraphicalModels::CGraph.

Definition at line 6 of file GraphPairwise.cpp.

◆ setEdge()

void DirectGraphicalModels::CGraphPairwise::setEdge ( size_t  srcNode,
size_t  dstNode,
const Mat &  pot 
)
overridevirtual

Sets or changes the potentional of directed edge.

Parameters
srcNodeindex of the source node
dstNodeindex of the destination node
potEdge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

Implements DirectGraphicalModels::IGraphPairwise.

Definition at line 75 of file GraphPairwise.cpp.

◆ setEdgeGroup()

void DirectGraphicalModels::CGraphPairwise::setEdgeGroup ( size_t  srcNode,
size_t  dstNode,
byte  group 
)
overridevirtual

Assigns a directed edge (srcNode) –> (dstNode) to the group group.

Parameters
srcNodeindex of the source node
dstNodeindex of the destination node
groupThe edge group ID

Implements DirectGraphicalModels::IGraphPairwise.

Definition at line 122 of file GraphPairwise.cpp.

◆ setEdges()

void DirectGraphicalModels::CGraphPairwise::setEdges ( std::optional< byte >  group,
const Mat &  pot 
)
overridevirtual

Sets the potential pot to all edges belonging to group group.

This function assigns the same potential matrix to all the edges in graph with group property equal to group. By default all edges have group 0. This mightbe changes with functon setEdgeGroup()

Parameters
groupThe edge group ID. This argument is optional, and if it is not set, this function will set potential to all existing edges
potEdge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1)

Implements DirectGraphicalModels::IGraphPairwise.

Definition at line 86 of file GraphPairwise.cpp.

◆ setNode()

void DirectGraphicalModels::CGraphPairwise::setNode ( size_t  node,
const Mat &  pot 
)
overridevirtual

Sets or changes the potential of node.

Parameters
nodenode index
potnode potential vector: Mat(size: nStates x 1; type: CV_32FC1)

Implements DirectGraphicalModels::CGraph.

Definition at line 21 of file GraphPairwise.cpp.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ CInferChain

friend class CInferChain
friend

Definition at line 67 of file GraphPairwise.h.

◆ CInferLBP

friend class CInferLBP
friend

Definition at line 69 of file GraphPairwise.h.

◆ CInferTree

friend class CInferTree
friend

Definition at line 68 of file GraphPairwise.h.

◆ CInferTRW

friend class CInferTRW
friend

Definition at line 71 of file GraphPairwise.h.

◆ CInferViterbi

friend class CInferViterbi
friend

Definition at line 70 of file GraphPairwise.h.

◆ CMessagePassing

friend class CMessagePassing
friend

Definition at line 66 of file GraphPairwise.h.

Member Data Documentation

◆ m_IDx

size_t DirectGraphicalModels::CGraphPairwise::m_IDx
private

Definition at line 113 of file GraphPairwise.h.

◆ m_vEdges

vec_edge_t DirectGraphicalModels::CGraphPairwise::m_vEdges
private

Definition at line 115 of file GraphPairwise.h.

◆ m_vNodes

vec_node_t DirectGraphicalModels::CGraphPairwise::m_vNodes
private

Definition at line 114 of file GraphPairwise.h.


The documentation for this class was generated from the following files: