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 
174  return std::dynamic_pointer_cast<DiscreteConditional>(inner_);
175  }
176 
178  std::shared_ptr<Factor> inner() const { return inner_; }
179 
181  double error(const HybridValues& values) const override;
182 
190  AlgebraicDecisionTree<Key> errorTree(
191  const VectorValues& values) const override;
192 
194  double logProbability(const HybridValues& values) const override;
195 
202  double negLogConstant() const override;
203 
205  double evaluate(const HybridValues& values) const override;
206 
208  bool frontalsIn(const VectorValues& measurements) const {
209  for (Key key : frontals()) {
210  if (!measurements.exists(key)) {
211  return false;
212  }
213  }
214  return true;
215  }
216 
218 
219  private:
220 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
221 
222  friend class boost::serialization::access;
223  template <class Archive>
224  void serialize(Archive& ar, const unsigned int /*version*/) {
225  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseFactor);
226  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseConditional);
227  ar& BOOST_SERIALIZATION_NVP(inner_);
228 
229  // register the various casts based on the type of inner_
230  // https://www.boost.org/doc/libs/1_80_0/libs/serialization/doc/serialization.html#runtimecasting
231  if (isDiscrete()) {
232  boost::serialization::void_cast_register<DiscreteConditional, Factor>(
233  static_cast<DiscreteConditional*>(NULL), static_cast<Factor*>(NULL));
234  } else if (isContinuous()) {
235  boost::serialization::void_cast_register<GaussianConditional, Factor>(
236  static_cast<GaussianConditional*>(NULL), static_cast<Factor*>(NULL));
237  } else {
238  boost::serialization::void_cast_register<HybridGaussianConditional,
239  Factor>(
240  static_cast<HybridGaussianConditional*>(NULL),
241  static_cast<Factor*>(NULL));
242  }
243  }
244 #endif
245 
246 }; // HybridConditional
247 
248 // traits
249 template <>
250 struct traits<HybridConditional> : public Testable<HybridConditional> {};
251 
252 } // 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:59
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:245
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::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:156
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:178
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:208
key
const gtsam::Symbol key('X', 0)
gtsam::DiscreteConditional::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: DiscreteConditional.h:43
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:51
gtsam::GaussianConditional::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianConditional.h:46
gtsam::HybridConditional::asDiscrete
DiscreteConditional::shared_ptr asDiscrete() const
Return conditional as a DiscreteConditional.
Definition: HybridConditional.h:173
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 Thu Dec 19 2024 04:01:15