1 #include "DecodeExact.h" 9 DGM_IF_WARNING(!lossMatrix.empty(),
"The Loss Matrix is not supported by the algorithm.");
12 vec_byte_t state(nNodes);
17 #ifdef DEBUG_PRINT_INFO 19 printf(
"nConfigurations = %zd\n", P.size());
22 float Z = std::accumulate(P.cbegin(), P.cend(), 0.0f);
26 for (
size_t n = 0; n < nNodes; n++) printf(
"%d ", state[n]);
27 printf(
":-> %2.1f\t| %2.1f %% \n", p, p * 100 / Z);
33 qword c = std::max_element(P.cbegin(), P.cend()) - P.begin();
42 for (
size_t n = 0; n < nNodes; n++) {
52 for (
size_t n = 0; n < nNodes; n++)
53 if (++state[n] >=
getGraph().getNumStates()) state[n] = 0;
61 size_t nConfigurations =
static_cast<size_t> (powl(
getGraph().getNumStates(), static_cast<long double>(nNodes)));
62 vec_byte_t state(nNodes);
65 DGM_ASSERT_MSG(nConfigurations < res.max_size(),
"The number of configurations %d^%zu exceeds the maximal possible size of container.",
getGraph().
getNumStates(), nNodes);
66 res.resize(nConfigurations, 1.0f);
70 vec_size_t vChildNodes;
72 for (
size_t n = 0; n < nNodes; n++) {
74 p *= nPot.at<
float>(state[n], 0);
77 for (
size_t c: vChilds) {
79 p *= ePot.at<
float>(state[n], state[c]);
virtual vec_byte_t decode(Mat &lossMatrix=EmptyMat) const
Exact decoding.
byte getNumStates(void) const
Returns number of states (classes)
CGraph & getGraph(void) const
Returns the reference to the graph.
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.
vec_float_t calculatePotentials(void) const
Calculates potentials for all possible configurations.
virtual size_t getNumNodes(void) const =0
Returns the number of nodes in the graph.
void incState(vec_byte_t &state) const
Increases the state by one, i.e. switches the state array to the consequent configuration.
virtual void getNode(size_t node, Mat &pot) const =0
Returns the node potential.
void setState(vec_byte_t &state, qword configuration) const
Sets the state according to the configuration index configuration.
virtual void getEdge(size_t srcNode, size_t dstNode, Mat &pot) const =0
Returns the edge potential.
IGraphPairwise & getGraphPairwise(void) const
Returns the graph.