DiscreteBayesNet.h
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 
19 #pragma once
20 
25 
26 #include <memory>
27 #include <map>
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 namespace gtsam {
33 
38 class GTSAM_EXPORT DiscreteBayesNet: public BayesNet<DiscreteConditional> {
39  public:
43  typedef std::shared_ptr<This> shared_ptr;
44  typedef std::shared_ptr<ConditionalType> sharedConditional;
45 
48 
51 
53  template <typename ITERATOR>
54  DiscreteBayesNet(ITERATOR firstConditional, ITERATOR lastConditional)
55  : Base(firstConditional, lastConditional) {}
56 
58  template <class CONTAINER>
59  explicit DiscreteBayesNet(const CONTAINER& conditionals)
60  : Base(conditionals) {}
61 
64  template <class DERIVEDCONDITIONAL>
66  : Base(graph) {}
67 
69 
72 
74  bool equals(const This& bn, double tol = 1e-9) const;
75 
77 
80 
81  // Add inherited versions of add.
82  using Base::add;
83 
85  void add(const DiscreteKey& key, const std::string& spec) {
86  emplace_shared<DiscreteDistribution>(key, spec);
87  }
88 
90  template <typename... Args>
91  void add(Args&&... args) {
92  emplace_shared<DiscreteConditional>(std::forward<Args>(args)...);
93  }
94 
95  //** evaluate for given DiscreteValues */
96  double evaluate(const DiscreteValues & values) const;
97 
98  //** (Preferred) sugar for the above for given DiscreteValues */
99  double operator()(const DiscreteValues & values) const {
100  return evaluate(values);
101  }
102 
103  //** log(evaluate(values)) for given DiscreteValues */
104  double logProbability(const DiscreteValues & values) const;
105 
115  DiscreteValues sample() const;
116 
125  DiscreteValues sample(DiscreteValues given) const;
126 
130 
132  std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
133  const DiscreteFactor::Names& names = {}) const;
134 
136  std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
137  const DiscreteFactor::Names& names = {}) const;
138 
142 
143  using Base::error; // Expose error(const HybridValues&) method..
144  using Base::evaluate; // Expose evaluate(const HybridValues&) method..
145  using Base::logProbability; // Expose logProbability(const HybridValues&)
146 
148 
149  private:
150 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
151 
152  friend class boost::serialization::access;
153  template<class ARCHIVE>
154  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
155  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
156  }
157 #endif
158  };
159 
160 // traits
161 template<> struct traits<DiscreteBayesNet> : public Testable<DiscreteBayesNet> {};
162 
163 } // \ namespace gtsam
164 
const gtsam::Symbol key('X', 0)
BayesNet< DiscreteConditional > Base
std::string serialize(const T &input)
serializes to a string
Definition: pytypes.h:2012
std::shared_ptr< ConditionalType > sharedConditional
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
leaf::MyValues values
DiscreteConditional ConditionalType
NonlinearFactorGraph graph
Bayes network.
DiscreteBayesNet(const FactorGraph< DERIVEDCONDITIONAL > &graph)
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
double operator()(const DiscreteValues &values) const
DiscreteBayesNet(ITERATOR firstConditional, ITERATOR lastConditional)
string html(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of html.
DiscreteBayesNet()
Construct empty Bayes net.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
void add(Args &&... args)
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
DiscreteValues::Names Names
Translation table from values to strings.
traits
Definition: chartTesting.h:28
DiscreteBayesNet(const CONTAINER &conditionals)
std::shared_ptr< This > shared_ptr
Factor Graph Base Class.
void add(const DiscreteKey &key, const std::string &spec)
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
graph add(PriorFactor< Pose2 >(1, priorMean, priorNoise))
static double error
Definition: testRot3.cpp:37
const std::vector< GaussianConditional::shared_ptr > conditionals
const G double tol
Definition: Group.h:86


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