HybridConditional.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 
26 #include <gtsam/inference/Key.h>
28 
29 #include <memory>
30 #include <stdexcept>
31 #include <string>
32 #include <typeinfo>
33 #include <vector>
34 
35 namespace gtsam {
36 
60 class GTSAM_EXPORT HybridConditional
61  : public HybridFactor,
62  public Conditional<HybridFactor, HybridConditional> {
63  public:
64  // typedefs needed to play nice with gtsam
66  typedef std::shared_ptr<This> shared_ptr;
70 
71  protected:
73  std::shared_ptr<Factor> inner_;
74 
75  public:
78 
80  HybridConditional() = default;
81 
89  HybridConditional(const KeyVector& continuousKeys,
90  const DiscreteKeys& discreteKeys, size_t nFrontals)
91  : BaseFactor(continuousKeys, discreteKeys), BaseConditional(nFrontals) {}
92 
102  HybridConditional(const KeyVector& continuousFrontals,
103  const DiscreteKeys& discreteFrontals,
104  const KeyVector& continuousParents,
105  const DiscreteKeys& discreteParents);
106 
114  const std::shared_ptr<GaussianConditional>& continuousConditional);
115 
123  const std::shared_ptr<DiscreteConditional>& discreteConditional);
124 
132  const std::shared_ptr<HybridGaussianConditional>& hybridGaussianCond);
133 
137 
139  void print(
140  const std::string& s = "Hybrid Conditional: ",
141  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
142 
144  bool equals(const HybridFactor& other, double tol = 1e-9) const override;
145 
149 
156  return std::dynamic_pointer_cast<HybridGaussianConditional>(inner_);
157  }
158 
165  return std::dynamic_pointer_cast<GaussianConditional>(inner_);
166  }
167 
173  template <typename T = DiscreteConditional>
174  typename T::shared_ptr asDiscrete() const {
175  return std::dynamic_pointer_cast<T>(inner_);
176  }
177 
179  std::shared_ptr<Factor> inner() const { return inner_; }
180 
182  double error(const HybridValues& values) const override;
183 
191  AlgebraicDecisionTree<Key> errorTree(
192  const VectorValues& values) const override;
193 
195  double logProbability(const HybridValues& values) const override;
196 
203  double negLogConstant() const override;
204 
206  double evaluate(const HybridValues& values) const override;
207 
209  bool frontalsIn(const VectorValues& measurements) const {
210  for (Key key : frontals()) {
211  if (!measurements.exists(key)) {
212  return false;
213  }
214  }
215  return true;
216  }
217 
219 
220  private:
221 #if GTSAM_ENABLE_BOOST_SERIALIZATION
222 
223  friend class boost::serialization::access;
224  template <class Archive>
225  void serialize(Archive& ar, const unsigned int /*version*/) {
226  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseFactor);
227  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseConditional);
228  ar& BOOST_SERIALIZATION_NVP(inner_);
229 
230  // register the various casts based on the type of inner_
231  // https://www.boost.org/doc/libs/1_80_0/libs/serialization/doc/serialization.html#runtimecasting
232  if (isDiscrete()) {
233  boost::serialization::void_cast_register<DiscreteConditional, Factor>(
234  static_cast<DiscreteConditional*>(NULL), static_cast<Factor*>(NULL));
235  } else if (isContinuous()) {
236  boost::serialization::void_cast_register<GaussianConditional, Factor>(
237  static_cast<GaussianConditional*>(NULL), static_cast<Factor*>(NULL));
238  } else {
239  boost::serialization::void_cast_register<HybridGaussianConditional,
240  Factor>(
241  static_cast<HybridGaussianConditional*>(NULL),
242  static_cast<Factor*>(NULL));
243  }
244  }
245 #endif
246 
247 }; // HybridConditional
248 
249 // traits
250 template <>
251 struct traits<HybridConditional> : public Testable<HybridConditional> {};
252 
253 } // namespace gtsam
gtsam::HybridConditional::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: HybridConditional.h:66
gtsam::HybridConditional::asHybrid
HybridGaussianConditional::shared_ptr asHybrid() const
Return HybridConditional as a HybridGaussianConditional.
Definition: HybridConditional.h:155
gtsam::HybridValues
Definition: HybridValues.h:37
GaussianConditional.h
Conditional Gaussian Base class.
gtsam::HybridGaussianConditional::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: HybridGaussianConditional.h:60
gtsam::HybridConditional
Definition: HybridConditional.h:60
HybridGaussianConditional.h
A hybrid conditional in the Conditional Linear Gaussian scheme.
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::HybridFactor
Definition: HybridFactor.h:51
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:247
gtsam::Factor
Definition: Factor.h:70
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41
DiscreteConditional.h
gtsam::HybridConditional::This
HybridConditional This
Typedef to this class.
Definition: HybridConditional.h:65
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::AlgebraicDecisionTree< Key >
gtsam::HybridConditional::asDiscrete
T::shared_ptr asDiscrete() const
Return conditional as a DiscreteConditional or specified type T.
Definition: HybridConditional.h:174
gtsam::HybridConditional::BaseFactor
HybridFactor BaseFactor
Typedef to our factor base class.
Definition: HybridConditional.h:67
Key.h
gtsam::HybridConditional::HybridConditional
HybridConditional(const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys, size_t nFrontals)
Construct a new Hybrid Conditional object.
Definition: HybridConditional.h:89
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:145
HybridFactor.h
GaussianConditional
gtsam::VectorValues
Definition: VectorValues.h:74
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::HybridConditional::BaseConditional
Conditional< BaseFactor, This > BaseConditional
Typedef to our conditional base class.
Definition: HybridConditional.h:69
gtsam::HybridConditional::inner
std::shared_ptr< Factor > inner() const
Get the type-erased pointer to the inner type.
Definition: HybridConditional.h:179
gtsam::Conditional
Definition: Conditional.h:63
gtsam::HybridConditional::inner_
std::shared_ptr< Factor > inner_
Type-erased pointer to the inner type.
Definition: HybridConditional.h:73
gtsam::equals
Definition: Testable.h:112
gtsam::HybridConditional::frontalsIn
bool frontalsIn(const VectorValues &measurements) const
Check if VectorValues measurements contains all frontal keys.
Definition: HybridConditional.h:209
key
const gtsam::Symbol key('X', 0)
gtsam::DiscreteConditional
Definition: DiscreteConditional.h:37
HybridGaussianFactorGraph.h
Linearized Hybrid factor graph that uses type erasure.
gtsam
traits
Definition: SFMdata.h:40
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:52
gtsam::GaussianConditional::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianConditional.h:46
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::HybridConditional::asGaussian
GaussianConditional::shared_ptr asGaussian() const
Return HybridConditional as a GaussianConditional.
Definition: HybridConditional.h:164
NULL
#define NULL
Definition: ccolamd.c:609
Conditional.h
Base class for conditional densities.
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42


gtsam
Author(s):
autogenerated on Wed Jan 22 2025 04:01:36