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).";
74 optimalDecoding->print(
"\nMost Probable Explanation (optimalDecoding)\n");
81 cout <<
"\nComputing Node Marginals ..(BayesTree based)" << endl;
83 for (vector<DiscreteKey>::iterator it = nodes.begin(); it != nodes.end();
89 cout <<
"Node#" << setw(4) << it->first <<
" : ";
void print(const Matrix &A, const string &s, ostream &stream)
int main(int argc, char **argv)
void add(const DiscreteKey &j, SOURCE table)
Vector marginalProbabilities(const DiscreteKey &key) const
NonlinearFactorGraph graph
std::pair< Key, size_t > DiscreteKey
A class for computing marginals in a DiscreteFactorGraph.
boost::shared_ptr< Values > sharedValues
boost::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType=boost::none, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
boost::shared_ptr< This > shared_ptr
Marginals marginals(graph, result)