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 
gtsam::markdown
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
Definition: DiscreteValues.cpp:130
gtsam::DiscreteBayesNet::sharedConditional
std::shared_ptr< ConditionalType > sharedConditional
Definition: DiscreteBayesNet.h:44
gtsam::BayesNet
Definition: BayesNet.h:35
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::DiscreteBayesNet::add
void add(Args &&... args)
Definition: DiscreteBayesNet.h:91
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
DiscreteConditional.h
equal_constants::conditionals
const std::vector< GaussianConditional::shared_ptr > conditionals
Definition: testHybridGaussianConditional.cpp:53
gtsam::DiscreteBayesNet::This
DiscreteBayesNet This
Definition: DiscreteBayesNet.h:41
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::FactorGraph
Definition: BayesTree.h:34
gtsam::DiscreteBayesNet
Definition: DiscreteBayesNet.h:38
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
add
graph add(PriorFactor< Pose2 >(1, priorMean, priorNoise))
BayesNet.h
Bayes network.
gtsam::equals
Definition: Testable.h:112
key
const gtsam::Symbol key('X', 0)
process_shonan_timing_results.names
dictionary names
Definition: process_shonan_timing_results.py:175
gtsam::DiscreteBayesNet::DiscreteBayesNet
DiscreteBayesNet(const FactorGraph< DERIVEDCONDITIONAL > &graph)
Definition: DiscreteBayesNet.h:65
gtsam::DiscreteConditional
Definition: DiscreteConditional.h:37
gtsam::DiscreteBayesNet::add
void add(const DiscreteKey &key, const std::string &spec)
Definition: DiscreteBayesNet.h:85
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::DiscreteBayesNet::DiscreteBayesNet
DiscreteBayesNet(ITERATOR firstConditional, ITERATOR lastConditional)
Definition: DiscreteBayesNet.h:54
error
static double error
Definition: testRot3.cpp:37
gtsam::traits
Definition: Group.h:36
gtsam::DiscreteFactor::Names
DiscreteValues::Names Names
Translation table from values to strings.
Definition: DiscreteFactor.h:139
FactorGraph.h
Factor Graph Base Class.
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
DiscreteDistribution.h
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
gtsam::DiscreteBayesNet::operator()
double operator()(const DiscreteValues &values) const
Definition: DiscreteBayesNet.h:99
args
Definition: pytypes.h:2210
gtsam::DiscreteBayesNet::Base
BayesNet< DiscreteConditional > Base
Definition: DiscreteBayesNet.h:40
This
#define This
Definition: ActiveSetSolver-inl.h:27
gtsam::DiscreteBayesNet::DiscreteBayesNet
DiscreteBayesNet(const CONTAINER &conditionals)
Definition: DiscreteBayesNet.h:59
gtsam::DiscreteBayesNet::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: DiscreteBayesNet.h:43
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::DiscreteBayesNet::DiscreteBayesNet
DiscreteBayesNet()
Construct empty Bayes net.
Definition: DiscreteBayesNet.h:50
gtsam::html
string html(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of html.
Definition: DiscreteValues.cpp:135
gtsam::DiscreteBayesNet::ConditionalType
DiscreteConditional ConditionalType
Definition: DiscreteBayesNet.h:42
Base
Definition: test_virtual_functions.cpp:156
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:28