31 using namespace gtsam;
33 int main(
int argc,
char **argv) {
37 cout << boolalpha <<
"Cloudy = " <<
static_cast<bool>((*values)[
C])
38 <<
" Sprinkler = " << static_cast<bool>((*
values)[
S])
39 <<
" Rain = " << boolalpha << static_cast<bool>((*
values)[
R])
40 <<
" WetGrass = " << static_cast<bool>((*
values)[
W]) << endl;
45 const size_t nrStates = 2;
48 DiscreteKey Cloudy(
C, nrStates), Sprinkler(
S, nrStates), Rain(
R, nrStates),
49 WetGrass(W, nrStates);
55 graph.
add(Cloudy,
"0.5 0.5");
56 graph.
add(Cloudy & Sprinkler,
"0.5 0.5 0.9 0.1");
57 graph.
add(Cloudy & Rain,
"0.8 0.2 0.2 0.8");
58 graph.
add(Sprinkler & Rain & WetGrass,
59 "1 0 0.1 0.9 0.1 0.9 0.001 0.99");
67 cout <<
"Distribution of Example: " << endl;
68 cout << setw(11) <<
"Cloudy(C)" << setw(14) <<
"Sprinkler(S)" << setw(10)
69 <<
"Rain(R)" << setw(14) <<
"WetGrass(W)" << setw(15) <<
"P(C,S,R,W)" 71 for (
size_t a = 0;
a < nrStates;
a++)
72 for (
size_t m = 0;
m < nrStates;
m++)
73 for (
size_t h = 0;
h < nrStates;
h++)
74 for (
size_t c = 0;
c < nrStates;
c++) {
80 double prodPot =
graph(values);
81 cout << setw(8) << static_cast<bool>(
c) << setw(14)
82 <<
static_cast<bool>(
h) << setw(12) <<
static_cast<bool>(
m)
83 << setw(13) <<
static_cast<bool>(
a) << setw(16) << prodPot
89 cout <<
"\nMost Probable Explanation (MPE):" << endl;
96 graph.
add(Cloudy,
"1 0");
102 cout <<
"\nMPE given C=0:" << endl;
103 print(mpe_with_evidence);
114 cout <<
"\n10 samples:" << endl;
115 for (
size_t i = 0;
i < 10;
i++) {
void print(const Matrix &A, const string &s, ostream &stream)
void add(const DiscreteKey &j, SOURCE table)
int main(int argc, char **argv)
Vector marginalProbabilities(const DiscreteKey &key) const
Rot2 R(Rot2::fromAngle(0.1))
NonlinearFactorGraph graph
std::pair< Key, size_t > DiscreteKey
A class for computing marginals in a DiscreteFactorGraph.
Matrix< Scalar, Dynamic, Dynamic > C
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
std::uint64_t Key
Integer nonlinear key type.
Marginals marginals(graph, result)