Direct Graphical Models
v.1.7.0
|
Interface class for graphical models. More...
#include <IGraphPairwise.h>
Public Member Functions | |
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 void | addEdge (size_t srcNode, size_t dstNode, byte group, const Mat &pot)=0 |
Adds an additional directed edge with specified potentional. More... | |
virtual void | setEdge (size_t srcNode, size_t dstNode, const Mat &pot)=0 |
Sets or changes the potentional of directed edge. More... | |
virtual void | setEdges (std::optional< byte > group, const Mat &pot)=0 |
Sets the potential pot to all edges belonging to group group. More... | |
virtual void | getEdge (size_t srcNode, size_t dstNode, Mat &pot) const =0 |
Returns the edge potential. More... | |
virtual void | setEdgeGroup (size_t srcNode, size_t dstNode, byte group)=0 |
Assigns a directed edge (srcNode) –> (dstNode) to the group group. More... | |
virtual byte | getEdgeGroup (size_t srcNode, size_t dstNode) const =0 |
Returns the group of the edge. More... | |
virtual void | removeEdge (size_t srcNode, size_t dstNode)=0 |
Removes the specified edge. More... | |
virtual bool | isEdgeExists (size_t srcNode, size_t dstNode) const =0 |
Checks whether the edge exists. 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 CGraph & | operator= (const CGraph &)=delete |
virtual void | reset (void)=0 |
Resets the graph. More... | |
virtual size_t | addNode (const Mat &pot=EmptyMat)=0 |
Adds an additional node (with specified potentional) More... | |
virtual void | addNodes (const Mat &pots) |
Adds the graph nodes with potentials. More... | |
virtual void | setNode (size_t node, const Mat &pot)=0 |
Sets or changes the potential of node. More... | |
virtual void | setNodes (size_t start_node, const Mat &pots) |
Fills the graph nodes with new potentials. More... | |
virtual void | getNode (size_t node, Mat &pot) const =0 |
Returns the node potential. More... | |
virtual void | getNodes (size_t start_node, size_t num_nodes, Mat &pots) const |
Returns the node potentials. More... | |
virtual void | getChildNodes (size_t node, vec_size_t &vNodes) const =0 |
Returns the set of IDs of the child nodes of the argument node. More... | |
virtual void | getParentNodes (size_t node, vec_size_t &vNodes) const =0 |
Returns the set of IDs of the parent nodes of the argument node. More... | |
virtual size_t | getNumNodes (void) const =0 |
Returns the number of nodes in the graph. More... | |
virtual size_t | getNumEdges (void) const =0 |
Returns the number of edges in the graph. More... | |
byte | getNumStates (void) const |
Returns number of states (classes) More... | |
Interface class for graphical models.
Definition at line 15 of file IGraphPairwise.h.
|
inline |
Constructor.
nStates | the number of States (classes) |
Definition at line 22 of file IGraphPairwise.h.
|
virtualdefault |
void DirectGraphicalModels::IGraphPairwise::addArc | ( | size_t | Node1, |
size_t | Node2, | ||
const Mat & | pot = EmptyMat |
||
) |
Adds an additional udirected edge (arc) with specified potentional.
The arc is emulated by adding two directed edges. For sake of consistency the pot matrix here is squarerooted:
Node1 | index of the first node |
Node2 | index of the second node |
pot | edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1) |
Definition at line 16 of file IGraphPairwise.cpp.
|
virtual |
Adds an additional udirected edge (arc) with specified potentional.
The arc is emulated by adding two directed edges. For sake of consistency the pot matrix here is squarerooted:
Node1 | index of the first node |
Node2 | index of the second node |
group | The edge group ID |
pot | edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1) |
Definition at line 22 of file IGraphPairwise.cpp.
void DirectGraphicalModels::IGraphPairwise::addEdge | ( | size_t | srcNode, |
size_t | dstNode, | ||
const Mat & | pot = EmptyMat |
||
) |
Adds an additional directed edge with specified potentional.
srcNode | index of the source node |
dstNode | index of the destination node |
pot | Edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1) |
Definition at line 5 of file IGraphPairwise.cpp.
|
pure virtual |
Adds an additional directed edge with specified potentional.
srcNode | index of the source node |
dstNode | index of the destination node |
group | The edge group ID |
pot | Edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1) |
Implemented in DirectGraphicalModels::CGraphWeiss, and DirectGraphicalModels::CGraphPairwise.
|
pure virtual |
Returns the edge potential.
[in] | srcNode | index of the source node |
[in] | dstNode | index of the destination node |
[out] | pot | edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1) if exists, empty Mat otherwise |
Implemented in DirectGraphicalModels::CGraphWeiss, and DirectGraphicalModels::CGraphPairwise.
|
pure virtual |
Returns the group of the edge.
srcNode | index of the source node |
dstNode | index of the destination node |
Implemented in DirectGraphicalModels::CGraphWeiss, and DirectGraphicalModels::CGraphPairwise.
|
virtual |
Checks whether the arc exists.
Node1 | index of the first node |
Node2 | index of the second node |
true | if the arc exists |
false | otherwise |
Definition at line 57 of file IGraphPairwise.cpp.
|
virtual |
Checks whether the edge is a part of an arc.
In contrast to the isArcExists() function, this function does not checks whether the input edge exists, and thus faster
srcNode | index of the source node |
dstNode | index of the destination node |
true | if the edge is a part of an arc |
false | otherwise |
Definition at line 10 of file IGraphPairwise.cpp.
|
pure virtual |
Checks whether the edge exists.
srcNode | index of the source node |
dstNode | index of the destination node |
true | if the edge exists |
false | otherwise |
Implemented in DirectGraphicalModels::CGraphWeiss, and DirectGraphicalModels::CGraphPairwise.
void DirectGraphicalModels::IGraphPairwise::marginalize | ( | const vec_size_t & | nodes | ) |
Marginalizes a set of nodes.
This function separates the marginalized graph nodes by removing all the edges connecting them with the remaining nodes. New edges are added if they correspond to the inducing pathes. The potentials of new esges are calculated as the sum of edge potentials from the corresponding inducing path.
This functions operates with inducing pathes with maximal length of 3 nodes.
nodes | Set of nodes to be marginalized out from the graph |
Definition at line 62 of file IGraphPairwise.cpp.
|
virtual |
Removes the specified arc.
Node1 | index of the first node |
Node2 | index of the second node |
Definition at line 51 of file IGraphPairwise.cpp.
|
pure virtual |
Removes the specified edge.
srcNode | index of the source node |
dstNode | index of the destination node |
Implemented in DirectGraphicalModels::CGraphWeiss, and DirectGraphicalModels::CGraphPairwise.
|
virtual |
Sets or changes the potentional of udirected edge (arc)
The arc is emulated by adding two directed edges. For sake of consistency the pot matrix here is squarerooted:
Node1 | index of the first node |
Node2 | index of the second node |
pot | edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1) |
Definition at line 37 of file IGraphPairwise.cpp.
|
virtual |
Assigns an undirected edge (arc) (Node1) – (Node2) to the group group.
Node1 | index of the source node |
Node2 | index of the destination node |
group | The edge group ID |
Definition at line 45 of file IGraphPairwise.cpp.
|
pure virtual |
Sets or changes the potentional of directed edge.
srcNode | index of the source node |
dstNode | index of the destination node |
pot | Edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1) |
Implemented in DirectGraphicalModels::CGraphWeiss, and DirectGraphicalModels::CGraphPairwise.
|
pure virtual |
Assigns a directed edge (srcNode) –> (dstNode) to the group group.
srcNode | index of the source node |
dstNode | index of the destination node |
group | The edge group ID |
Implemented in DirectGraphicalModels::CGraphWeiss, and DirectGraphicalModels::CGraphPairwise.
|
pure virtual |
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()
group | The edge group ID. This argument is optional, and if it is not set, this function will set potential to all existing edges |
pot | Edge potential matrix: Mat(size: nStates x nStates; type: CV_32FC1) |
Implemented in DirectGraphicalModels::CGraphWeiss, and DirectGraphicalModels::CGraphPairwise.