HybridFactor.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 
21 #include <gtsam/base/Testable.h>
25 #include <gtsam/inference/Factor.h>
27 #include <gtsam/nonlinear/Values.h>
28 
29 #include <cstddef>
30 #include <string>
31 namespace gtsam {
32 
33 class HybridValues;
34 
35 KeyVector CollectKeys(const KeyVector &continuousKeys,
36  const DiscreteKeys &discreteKeys);
37 KeyVector CollectKeys(const KeyVector &keys1, const KeyVector &keys2);
38 DiscreteKeys CollectDiscreteKeys(const DiscreteKeys &key1,
39  const DiscreteKeys &key2);
40 
51 class GTSAM_EXPORT HybridFactor : public Factor {
52  public:
54  enum class Category { None, Discrete, Continuous, Hybrid };
55 
56  private:
58  Category category_ = Category::None;
59 
60  protected:
61  // Set of DiscreteKeys for this factor.
65 
66  public:
67  // typedefs needed to play nice with gtsam
68  typedef HybridFactor This;
69  typedef std::shared_ptr<HybridFactor>
71  typedef Factor Base;
72 
75 
77  HybridFactor() = default;
78 
84  explicit HybridFactor(const KeyVector &keys);
85 
91  explicit HybridFactor(const DiscreteKeys &discreteKeys);
92 
99  HybridFactor(const KeyVector &continuousKeys,
100  const DiscreteKeys &discreteKeys);
101 
105 
107  virtual bool equals(const HybridFactor &lf, double tol = 1e-9) const;
108 
110  void print(
111  const std::string &s = "HybridFactor\n",
112  const KeyFormatter &formatter = DefaultKeyFormatter) const override;
113 
117 
119  bool isDiscrete() const { return category_ == Category::Discrete; }
120 
122  bool isContinuous() const { return category_ == Category::Continuous; }
123 
125  bool isHybrid() const { return category_ == Category::Hybrid; }
126 
128  size_t nrContinuous() const { return continuousKeys_.size(); }
129 
131  const DiscreteKeys &discreteKeys() const { return discreteKeys_; }
132 
134  const KeyVector &continuousKeys() const { return continuousKeys_; }
135 
137  virtual AlgebraicDecisionTree<Key> errorTree(
138  const VectorValues &values) const = 0;
139 
141 
142  private:
143 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
144 
145  friend class boost::serialization::access;
146  template <class ARCHIVE>
147  void serialize(ARCHIVE &ar, const unsigned int /*version*/) {
148  ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
149  ar &BOOST_SERIALIZATION_NVP(category_);
150  ar &BOOST_SERIALIZATION_NVP(discreteKeys_);
151  ar &BOOST_SERIALIZATION_NVP(continuousKeys_);
152  }
153 #endif
154 };
155 // HybridFactor
156 
157 // traits
158 template <>
159 struct traits<HybridFactor> : public Testable<HybridFactor> {};
160 
161 } // namespace gtsam
key1
const Symbol key1('v', 1)
GaussianFactorGraph.h
Linear Factor Graph where all factors are Gaussians.
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Testable.h
Concept check for values that can be used in unit tests.
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
gtsam::HybridFactor::isDiscrete
bool isDiscrete() const
True if this is a factor of discrete variables only.
Definition: HybridFactor.h:119
gtsam::HybridFactor
Definition: HybridFactor.h:51
gtsam::HybridFactor::shared_ptr
std::shared_ptr< HybridFactor > shared_ptr
shared_ptr to this class
Definition: HybridFactor.h:70
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::HybridFactor::continuousKeys_
KeyVector continuousKeys_
Record continuous keys for book-keeping.
Definition: HybridFactor.h:64
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
HybridValues
gtsam::HybridFactor::isHybrid
bool isHybrid() const
True is this is a Discrete-Continuous factor.
Definition: HybridFactor.h:125
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
Factor.h
The base class for all factors.
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::AlgebraicDecisionTree< Key >
gtsam::HybridFactor::nrContinuous
size_t nrContinuous() const
Return the number of continuous variables in this factor.
Definition: HybridFactor.h:128
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
gtsam::HybridFactor::Category
Category
Enum to help with categorizing hybrid factors.
Definition: HybridFactor.h:54
key2
const Symbol key2('v', 2)
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
DecisionTree.h
Decision Tree for use in DiscreteFactors.
gtsam::CollectKeys
KeyVector CollectKeys(const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys)
Definition: HybridFactor.cpp:23
gtsam::HybridFactor::discreteKeys_
DiscreteKeys discreteKeys_
Definition: HybridFactor.h:62
gtsam::HybridFactor::isContinuous
bool isContinuous() const
True if this is a factor of continuous variables only.
Definition: HybridFactor.h:122
TableFactor.h
gtsam::equals
Definition: Testable.h:112
gtsam::HybridFactor::This
HybridFactor This
This class.
Definition: HybridFactor.h:68
DiscreteKey.h
specialized key for discrete variables
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::traits
Definition: Group.h:36
gtsam::HybridFactor::Base
Factor Base
Our base class.
Definition: HybridFactor.h:71
gtsam::HybridFactor::continuousKeys
const KeyVector & continuousKeys() const
Return only the continuous keys for this factor.
Definition: HybridFactor.h:134
gtsam::tol
const G double tol
Definition: Group.h:79
Base
Definition: test_virtual_functions.cpp:156
gtsam::HybridFactor::discreteKeys
const DiscreteKeys & discreteKeys() const
Return the discrete keys for this factor.
Definition: HybridFactor.h:131
Values.h
A non-templated config holding any types of Manifold-group elements.
gtsam::CollectDiscreteKeys
DiscreteKeys CollectDiscreteKeys(const DiscreteKeys &key1, const DiscreteKeys &key2)
Definition: HybridFactor.cpp:43


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:43