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");
66 chordal->print(
"Eliminated");
73 cout <<
"\n10 samples:" << endl;
74 for (
size_t k = 0; k < 10; k++) {
80 cout <<
"\nComputing Node Marginals .." << endl;
82 for (
int k = 0; k < nrNodes; k++) {
85 ss <<
"marginal " << k;
86 print(margProbs, ss.str());
void print(const Matrix &A, const string &s, ostream &stream)
int main(int argc, char **argv)
Vector marginalProbabilities(const DiscreteKey &key) const
static enum @843 ordering
void add(const Signature &s)
std::pair< Key, size_t > DiscreteKey
A class for computing marginals in a DiscreteFactorGraph.
static std::stringstream ss
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)
void print(const std::string &s="BayesNet", const KeyFormatter &formatter=DefaultKeyFormatter) const override