HybridBayesNet.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
3  * Atlanta, Georgia 30332-0415
4  * All Rights Reserved
5  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
6  * See LICENSE for the license information
7  * -------------------------------------------------------------------------- */
8 
18 #pragma once
19 
22 #include <gtsam/global_includes.h>
27 
28 namespace gtsam {
29 
37 class GTSAM_EXPORT HybridBayesNet : public BayesNet<HybridConditional> {
38  public:
42  using shared_ptr = std::shared_ptr<HybridBayesNet>;
43  using sharedConditional = std::shared_ptr<ConditionalType>;
44 
47 
49  HybridBayesNet() = default;
50 
53  std::initializer_list<HybridConditional::shared_ptr> conditionals)
54  : Base(conditionals) {}
55 
59 
61  void print(const std::string &s = "", const KeyFormatter &formatter =
62  DefaultKeyFormatter) const override;
63 
65  bool equals(const This &fg, double tol = 1e-9) const;
66 
70 
76  void push_back(std::shared_ptr<HybridConditional> conditional) {
77  factors_.push_back(conditional);
78  }
79 
87  void push_back(HybridConditional &&conditional) {
88  factors_.push_back(
89  std::make_shared<HybridConditional>(std::move(conditional)));
90  }
91 
102  template <class CONDITIONAL>
103  void push_back(const std::shared_ptr<CONDITIONAL> &conditional) {
104  factors_.push_back(std::make_shared<HybridConditional>(conditional));
105  }
106 
115  template <class CONDITIONAL, class... Args>
116  void emplace_shared(Args &&...args) {
117  auto cond = std::allocate_shared<CONDITIONAL>(
118  Eigen::aligned_allocator<CONDITIONAL>(), std::forward<Args>(args)...);
119  factors_.push_back(std::make_shared<HybridConditional>(std::move(cond)));
120  }
121 
129  DiscreteBayesNet discreteMarginal() const;
130 
139  GaussianBayesNet choose(const DiscreteValues &assignment) const;
140 
142  double evaluate(const HybridValues &values) const;
143 
145  double operator()(const HybridValues &values) const {
146  return evaluate(values);
147  }
148 
156  HybridValues optimize() const;
157 
165  VectorValues optimize(const DiscreteValues &assignment) const;
166 
179  HybridValues sample(const HybridValues &given, std::mt19937_64 *rng) const;
180 
191  HybridValues sample(std::mt19937_64 *rng) const;
192 
199  HybridValues sample(const HybridValues &given) const;
200 
206  HybridValues sample() const;
207 
214  HybridBayesNet prune(size_t maxNrLeaves) const;
215 
220  using Base::error;
221 
235  AlgebraicDecisionTree<Key> errorTree(
236  const VectorValues &continuousValues) const;
237 
238  using BayesNet::logProbability; // expose HybridValues version
239 
248  double negLogConstant(const std::optional<DiscreteValues> &discrete) const;
249 
259  AlgebraicDecisionTree<Key> discretePosterior(
260  const VectorValues &continuousValues) const;
261 
266  HybridGaussianFactorGraph toFactorGraph(
267  const VectorValues &measurements) const;
269 
270  private:
271 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
272 
273  friend class boost::serialization::access;
274  template <class ARCHIVE>
275  void serialize(ARCHIVE &ar, const unsigned int /*version*/) {
276  ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
277  }
278 #endif
279 };
280 
282 template <>
283 struct traits<HybridBayesNet> : public Testable<HybridBayesNet> {};
284 
285 } // namespace gtsam
DiscreteBayesNet.h
gtsam::HybridBayesNet::sharedConditional
std::shared_ptr< ConditionalType > sharedConditional
Definition: HybridBayesNet.h:43
gtsam::HybridValues
Definition: HybridValues.h:37
rng
static std::mt19937 rng
Definition: timeFactorOverhead.cpp:31
gtsam::HybridConditional
Definition: HybridConditional.h:60
global_includes.h
Included from all GTSAM files.
gtsam::BayesNet
Definition: BayesNet.h:35
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::HybridBayesNet
Definition: HybridBayesNet.h:37
gtsam::optimize
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Definition: triangulation.cpp:177
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
GaussianBayesNet.h
Chordal Bayes Net, the result of eliminating a factor graph.
equal_constants::conditionals
const std::vector< GaussianConditional::shared_ptr > conditionals
Definition: testHybridGaussianConditional.cpp:53
gtsam::HybridBayesNet::HybridBayesNet
HybridBayesNet(std::initializer_list< HybridConditional::shared_ptr > conditionals)
Constructor that takes an initializer list of shared pointers.
Definition: HybridBayesNet.h:52
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::AlgebraicDecisionTree< Key >
gtsam::HybridBayesNet::push_back
void push_back(const std::shared_ptr< CONDITIONAL > &conditional)
Add a conditional to the Bayes net. Implicitly convert to a HybridConditional.
Definition: HybridBayesNet.h:103
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:156
Eigen::aligned_allocator
STL compatible allocator to use with types requiring a non standrad alignment.
Definition: Memory.h:878
gtsam::DiscreteBayesNet
Definition: DiscreteBayesNet.h:38
gtsam::VectorValues
Definition: VectorValues.h:74
gtsam::HybridBayesNet::operator()
double operator()(const HybridValues &values) const
Evaluate hybrid probability density for given HybridValues, sugar.
Definition: HybridBayesNet.h:145
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::HybridBayesNet::push_back
void push_back(HybridConditional &&conditional)
Definition: HybridBayesNet.h:87
gtsam::HybridGaussianFactorGraph
Definition: HybridGaussianFactorGraph.h:106
BayesNet.h
Bayes network.
gtsam::equals
Definition: Testable.h:112
gtsam::HybridBayesNet::push_back
void push_back(std::shared_ptr< HybridConditional > conditional)
Add a hybrid conditional using a shared_ptr.
Definition: HybridBayesNet.h:76
gtsam
traits
Definition: SFMdata.h:40
gtsam::BayesNet::logProbability
double logProbability(const HybridValues &x) const
Definition: BayesNet-inst.h:94
gtsam::Testable
Definition: Testable.h:152
error
static double error
Definition: testRot3.cpp:37
gtsam::traits
Definition: Group.h:36
estimation_fixture::measurements
std::vector< double > measurements
Definition: testHybridEstimation.cpp:51
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
args
Definition: pytypes.h:2210
This
#define This
Definition: ActiveSetSolver-inl.h:27
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::HybridBayesNet::shared_ptr
std::shared_ptr< HybridBayesNet > shared_ptr
Definition: HybridBayesNet.h:42
Base
Definition: test_virtual_functions.cpp:156
HybridValues.h
DecisionTreeFactor.h
choose
static const T & choose(int layout, const T &col, const T &row)
Definition: cxx11_tensor_block_access.cpp:27
gtsam::GaussianBayesNet
Definition: GaussianBayesNet.h:35
gtsam::HybridBayesNet::emplace_shared
void emplace_shared(Args &&...args)
Definition: HybridBayesNet.h:116
HybridConditional.h


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