Direct Graphical Models  v.1.7.0
InferLBP.cpp
1 #include "InferLBP.h"
2 #include "GraphPairwise.h"
3 
4 namespace DirectGraphicalModels
5 {
6 void CInferLBP::calculateMessages(unsigned int nIt)
7 {
8  const byte nStates = getGraph().getNumStates(); // number of states
9 
10  // ======================== Main loop (iterative messages calculation) ========================
11 #ifndef ENABLE_PPL
12  float *temp = new float[nStates];
13 #endif
14  for (unsigned int i = 0; i < nIt; i++) { // iterations
15 #ifdef DEBUG_PRINT_INFO
16  if (i == 0) printf("\n");
17  if (i % 5 == 0) printf("--- It: %d ---\n", i);
18 #endif
19 #ifdef ENABLE_PPL
20  concurrency::parallel_for_each(getGraphPairwise().m_vNodes.begin(), getGraphPairwise().m_vNodes.end(), [&, nStates](ptr_node_t &node) { // all nodes
21  float *temp = new float[nStates];
22 #else
23  std::for_each(getGraphPairwise().m_vNodes.begin(), getGraphPairwise().m_vNodes.end(), [&](ptr_node_t &node) {
24 #endif
25  // Calculate a message to each neighbor
26  size_t nToEdges = node->to.size();
27  for (size_t e_t = 0; e_t < nToEdges; e_t++) { // outgoing edges
28  Edge *edge_to = getGraphPairwise().m_vEdges[node->to[e_t]].get(); // current outgoing edge
29  calculateMessage(edge_to, temp, edge_to->msg_temp, m_maxSum);
30  } // e_t;
31 #ifdef ENABLE_PPL
32  delete[] temp;
33 #endif
34  }); // nodes
35  swapMessages(); // Coping data from msg_temp to msg
36  } // iterations
37 #ifndef ENABLE_PPL
38  delete[] temp;
39 #endif
40 }
41 }
byte getNumStates(void) const
Returns number of states (classes)
Definition: Graph.h:99
void swapMessages(void)
Swaps Edge::msg and Edge::msg_temp for all edges in the graph.
float * msg_temp
Temp Message (used in message-passing algorithms): Mat(size: nStates x 1; type: CV_32FC1) ...
Definition: GraphPairwise.h:37
CGraph & getGraph(void) const
Returns the reference to the graph.
Definition: Infer.h:82
virtual void calculateMessages(unsigned int nIt)
Calculates messages, associated with the edges of corresponding graphical model.
Definition: InferLBP.cpp:6
std::unique_ptr< Node > ptr_node_t
Definition: GraphPairwise.h:24
bool m_maxSum
Flag indicating weather the max-sum LBP (Viterbi algorithm) should be applied.
Definition: InferLBP.h:34
CGraphPairwise & getGraphPairwise(void) const
Returns the graph.
void calculateMessage(Edge *edge, float *temp, float *&dst, bool maxSum=false)
Calculates one message for the specified edge edge.