27 using namespace gtsam;
29 int main(
int argc,
char **argv) {
30 const int nrNodes = 4;
31 const size_t nrStates = 3;
35 vector<DiscreteKey>
keys;
36 for (
int k = 0; k < nrNodes; k++) {
38 keys.push_back(key_i);
39 ordering.emplace_back(k);
46 const string transition =
"8/1/1 1/8/1 1/1/8";
47 for (
int k = 1; k < nrNodes; k++) {
48 hmm.
add(keys[k] | keys[k - 1] = transition);
52 hmm.
add(keys[0] %
"7/2/1");
53 hmm.
add(keys[1] %
"1/9/0");
54 hmm.
add(keys.back() %
"5/4/1");
70 chordal->print(
"Eliminated");
73 cout <<
"\n10 samples:" << endl;
74 for (
size_t k = 0; k < 10; k++) {
75 auto sample = chordal->sample();
80 cout <<
"\nComputing Node Marginals .." << endl;
82 for (
int k = 0; k < nrNodes; k++) {
85 ss <<
"marginal " << k;
86 print(margProbs, ss.str());
int main(int argc, char **argv)
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
DiscreteValues optimize(OptionalOrderingType orderingType={}) const
Find the maximum probable explanation (MPE) by doing max-product.
static enum @1107 ordering
Vector marginalProbabilities(const DiscreteKey &key) const
std::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
A class for computing marginals in a DiscreteFactorGraph.
static std::stringstream ss
std::shared_ptr< This > shared_ptr
void add(const DiscreteKey &key, const std::string &spec)
std::pair< Key, size_t > DiscreteKey
Marginals marginals(graph, result)
void print(const std::string &s="BayesNet", const KeyFormatter &formatter=DefaultKeyFormatter) const override