Direct Graphical Models  v.1.7.0
Infer.cpp
1 #include "Infer.h"
2 #include "Decode.h"
3 #include "Graph.h"
4 
5 namespace DirectGraphicalModels
6 {
7  vec_byte_t CInfer::decode(unsigned int nIt, Mat &lossMatrix)
8  {
9  if (nIt) infer(nIt);
10  return CDecode::decode(getGraph(), lossMatrix);
11  }
12 
13  vec_float_t CInfer::getConfidence(void) const
14  {
15  size_t nNodes = getGraph().getNumNodes();
16  vec_float_t res(nNodes);
17  Mat pot, srt;
18 
19  for (size_t n = 0; n < nNodes; n++) { // all nodes
20  getGraph().getNode(n, pot);
21 
22  sort(pot, srt, cv::SortFlags::SORT_EVERY_COLUMN | cv::SortFlags::SORT_DESCENDING);
23 
24  float max = srt.at<float>(0, 0);
25  float second_max = srt.at<float>(1, 0);
26 
27  res[n] = (max == 0) ? 0.0f : 1.0f - second_max / max;
28  } // n
29 
30  return res;
31  }
32 
33  vec_float_t CInfer::getPotentials(byte state) const
34  {
35  size_t nNodes = getGraph().getNumNodes();
36  vec_float_t res(nNodes);
37  Mat pot;
38 
39  for (size_t n = 0; n < nNodes; n++) { // all nodes
40  getGraph().getNode(n, pot);
41  res[n] = pot.at<float>(state, 0);
42  } // n
43 
44  return res;
45  }
46 }
virtual void infer(unsigned int nIt=1)=0
Inference.
virtual vec_byte_t decode(Mat &lossMatrix=EmptyMat) const
Approximate decoding.
Definition: Decode.h:38
virtual size_t getNumNodes(void) const =0
Returns the number of nodes in the graph.
vec_float_t getPotentials(byte state) const
Returns the potnetials for the selected state (class)
Definition: Infer.cpp:33
virtual void getNode(size_t node, Mat &pot) const =0
Returns the node potential.
vec_byte_t decode(unsigned int nIt=0, Mat &lossMatrix=EmptyMat)
Approximate decoding.
Definition: Infer.cpp:7
CGraph & getGraph(void) const
Returns the reference to the graph.
Definition: Infer.h:82
vec_float_t getConfidence(void) const
Returns the confidence of the perdiction.
Definition: Infer.cpp:13