25 using namespace gtsam;
27 int main(
int argc,
char** argv) {
34 DiscreteKey Cathy(1, nrStates), Heather(2, nrStates), Mark(3, nrStates),
41 graph.
add(Cathy,
"1 3");
42 graph.
add(Heather,
"9 1");
43 graph.
add(Mark,
"1 3");
44 graph.
add(Allison,
"9 1");
47 graph.
add(Cathy & Heather,
"2 1 1 2");
48 graph.
add(Heather & Mark,
"2 1 1 2");
49 graph.
add(Mark & Allison,
"2 1 1 2");
52 cout <<
"\nUGM distribution:" << endl;
54 DiscreteValues::CartesianProduct(Cathy & Heather & Mark & Allison);
55 for (
size_t i = 0;
i < allPosbValues.size(); ++
i) {
57 double prodPot =
graph(values);
58 cout << values[Cathy.first] <<
" " << values[Heather.first] <<
" " 59 << values[Mark.first] <<
" " << values[Allison.first] <<
" :\t" 60 << prodPot <<
"\t" << prodPot / 3790 << endl;
65 auto optimalDecoding = graph.
optimize();
69 cout <<
"\nComputing Node Marginals .." << endl;
73 print(margProbs,
"Cathy's Node Marginal:");
76 print(margProbs,
"Heather's Node Marginal");
79 print(margProbs,
"Mark's Node Marginal");
82 print(margProbs,
"Allison's Node Marginal");
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)
int main(int argc, char **argv)
Vector marginalProbabilities(const DiscreteKey &key) const
A class for computing marginals in a DiscreteFactorGraph.
typedef and functions to augment Eigen's VectorXd
std::vector< float > Values
std::pair< Key, size_t > DiscreteKey
Marginals marginals(graph, result)