29 using namespace gtsam;
31 int main(
int argc,
char** argv) {
33 const int nrNodes = 60;
38 const size_t nrStates = 7;
41 vector<DiscreteKey>
nodes;
42 for (
int i = 0;
i < nrNodes;
i++) {
51 graph.
add(nodes[0],
".3 .6 .1 0 0 0 0");
52 for (
int i = 1;
i < nrNodes;
i++) graph.
add(nodes[
i],
"1 1 1 1 1 1 1");
54 const std::string edgePotential =
55 ".08 .9 .01 0 0 0 .01 " 56 ".03 .95 .01 0 0 0 .01 " 57 ".06 .06 .75 .05 .05 .02 .01 " 58 "0 0 0 .3 .6 .09 .01 " 59 "0 0 0 .02 .95 .02 .01 " 60 "0 0 0 .01 .01 .97 .01 " 64 for (
int i = 0; i < nrNodes - 1; i++)
65 graph.
add(nodes[i] & nodes[i + 1], edgePotential);
67 cout <<
"Created Factor Graph with " << nrNodes <<
" variable nodes and " 68 << graph.
size() <<
" factors (Unary+Edge).";
72 auto optimalDecoding = graph.
optimize();
73 optimalDecoding.print(
"\nMost Probable Explanation (optimalDecoding)\n");
80 cout <<
"\nComputing Node Marginals ..(BayesTree based)" << endl;
82 for (vector<DiscreteKey>::iterator it = nodes.begin(); it != nodes.end();
88 cout <<
"Node#" << setw(4) << it->first <<
" : ";
int main(int argc, char **argv)
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
NonlinearFactorGraph graph
DiscreteValues optimize(OptionalOrderingType orderingType={}) const
Find the maximum probable explanation (MPE) by doing max-product.
void add(Args &&... args)
Vector marginalProbabilities(const DiscreteKey &key) const
A class for computing marginals in a DiscreteFactorGraph.
std::pair< Key, size_t > DiscreteKey
Marginals marginals(graph, result)