DiscreteBayesTree.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
25 
26 namespace gtsam {
27 
28  // Instantiate base class
29  template class BayesTreeCliqueBase<DiscreteBayesTreeClique, DiscreteFactorGraph>;
30  template class BayesTree<DiscreteBayesTreeClique>;
31 
32  /* ************************************************************************* */
34  const DiscreteValues& values) const {
35  // evaluate all conditionals and multiply
36  double result = (*conditional_)(values);
37  for (const auto& child : children) {
38  result *= child->evaluate(values);
39  }
40  return result;
41  }
42 
43  /* ************************************************************************* */
44  bool DiscreteBayesTree::equals(const This& other, double tol) const {
45  return Base::equals(other, tol);
46  }
47 
48  /* ************************************************************************* */
50  const DiscreteValues& values) const {
51  double result = 1.0;
52  for (const auto& root : roots_) {
53  result *= root->evaluate(values);
54  }
55  return result;
56  }
57 
58  /* **************************************************************************/
60  const KeyFormatter& keyFormatter,
61  const DiscreteFactor::Names& names) const {
62  using std::endl;
63  std::stringstream ss;
64  ss << "`DiscreteBayesTree` of size " << nodes_.size() << endl << endl;
65  auto visitor = [&](const DiscreteBayesTreeClique::shared_ptr& clique,
66  size_t& indent) {
67  ss << "\n" << clique->conditional()->markdown(keyFormatter, names);
68  return indent + 1;
69  };
70  size_t indent;
71  treeTraversal::DepthFirstForest(*this, indent, visitor);
72  return ss.str();
73  }
74 
75  /* **************************************************************************/
77  const KeyFormatter& keyFormatter,
78  const DiscreteFactor::Names& names) const {
79  using std::endl;
80  std::stringstream ss;
81  ss << "<div><p><tt>DiscreteBayesTree</tt> of size " << nodes_.size()
82  << "</p>";
83  auto visitor = [&](const DiscreteBayesTreeClique::shared_ptr& clique,
84  size_t& indent) {
85  ss << clique->conditional()->html(keyFormatter, names);
86  return indent + 1;
87  };
88  size_t indent;
89  treeTraversal::DepthFirstForest(*this, indent, visitor);
90  return ss.str();
91  }
92 
93  /* **************************************************************************/
94  } // namespace gtsam
std::shared_ptr< This > shared_ptr
A Bayes tree representing a Discrete distribution.
leaf::MyValues values
Base class for cliques of a BayesTree.
bool equals(const DiscreteBayesTreeClique &other, double tol=1e-9) const
void DepthFirstForest(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost)
Values result
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DiscreteFactor::Names &names={}) const
Render as html tables.
Discrete Bayes Tree, the result of eliminating a DiscreteJunctionTree.
Bayes Tree is a tree of cliques of a Bayes Chain.
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
bool equals(const This &other, double tol=1e-9) const
static std::stringstream ss
Definition: testBTree.cpp:31
double evaluate(const DiscreteValues &values) const
DiscreteValues::Names Names
Translation table from values to strings.
traits
Definition: chartTesting.h:28
const G double tol
Definition: Group.h:86
double evaluate(const DiscreteValues &values) const
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DiscreteFactor::Names &names={}) const
Render as markdown tables.


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:10