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
DiscreteBayesNet.h
treeTraversal-inst.h
gtsam::BayesTree< DiscreteBayesTreeClique >::roots_
Roots roots_
Definition: BayesTree.h:103
result
Values result
Definition: OdometryOptimize.cpp:8
ss
static std::stringstream ss
Definition: testBTree.cpp:31
gtsam::DiscreteBayesTreeClique::evaluate
double evaluate(const DiscreteValues &values) const
Definition: DiscreteBayesTree.cpp:33
gtsam::BayesTree< DiscreteBayesTreeClique >::nodes_
Nodes nodes_
Definition: BayesTree.h:100
gtsam::DiscreteBayesTree::equals
bool equals(const This &other, double tol=1e-9) const
Definition: DiscreteBayesTree.cpp:44
gtsam::KeyFormatter
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
gtsam::BayesTree< DiscreteBayesTreeClique >::clique
const sharedClique & clique(Key j) const
Definition: BayesTree.h:155
gtsam::treeTraversal::DepthFirstForest
void DepthFirstForest(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost)
Definition: treeTraversal-inst.h:77
gtsam::BayesTreeCliqueBase< DiscreteBayesTreeClique, DiscreteFactorGraph >::children
FastVector< derived_ptr > children
Definition: BayesTreeCliqueBase.h:115
DiscreteBayesTree.h
Discrete Bayes Tree, the result of eliminating a DiscreteJunctionTree.
process_shonan_timing_results.names
dictionary names
Definition: process_shonan_timing_results.py:175
gtsam
traits
Definition: chartTesting.h:28
gtsam::DiscreteFactor::Names
DiscreteValues::Names Names
Translation table from values to strings.
Definition: DiscreteFactor.h:121
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
leaf::values
leaf::MyValues values
gtsam::DiscreteBayesTree::html
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DiscreteFactor::Names &names={}) const
Render as html tables.
Definition: DiscreteBayesTree.cpp:76
gtsam::DiscreteBayesTree
A Bayes tree representing a Discrete distribution.
Definition: DiscreteBayesTree.h:73
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::BayesTree< DiscreteBayesTreeClique >::equals
bool equals(const This &other, double tol=1e-9) const
Definition: BayesTree-inst.h:269
BayesTreeCliqueBase-inst.h
Base class for cliques of a BayesTree.
BayesTree-inst.h
Bayes Tree is a tree of cliques of a Bayes Chain.
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gtsam::DiscreteBayesTreeClique::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: DiscreteBayesTree.h:45
gtsam::DiscreteBayesTree::markdown
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DiscreteFactor::Names &names={}) const
Render as markdown tables.
Definition: DiscreteBayesTree.cpp:59
gtsam::DiscreteBayesTree::evaluate
double evaluate(const DiscreteValues &values) const
Definition: DiscreteBayesTree.cpp:49


gtsam
Author(s):
autogenerated on Tue Jun 25 2024 03:00:48