HybridGaussianConditional.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 
21 #pragma once
22 
31 
32 namespace gtsam {
33 
34 class HybridValues;
35 
54 class GTSAM_EXPORT HybridGaussianConditional
55  : public HybridGaussianFactor,
56  public Conditional<HybridGaussianFactor, HybridGaussianConditional> {
57  public:
59  using shared_ptr = std::shared_ptr<This>;
62 
65 
66  private:
70 
72  bool pruned_ = false;
73 
74  public:
77 
79  HybridGaussianConditional() = default;
80 
89  const DiscreteKey &discreteParent,
90  const std::vector<GaussianConditional::shared_ptr> &conditionals);
91 
101  const DiscreteKey &discreteParent, Key key,
102  const std::vector<std::pair<Vector, double>> &parameters);
103 
115  const DiscreteKey &discreteParent, Key key, const Matrix &A, Key parent,
116  const std::vector<std::pair<Vector, double>> &parameters);
117 
131  const DiscreteKey &discreteParent, Key key, //
132  const Matrix &A1, Key parent1, const Matrix &A2, Key parent2,
133  const std::vector<std::pair<Vector, double>> &parameters);
134 
144  HybridGaussianConditional(const DiscreteKeys &discreteParents,
145  const Conditionals &conditionals);
146 
158  HybridGaussianConditional(const DiscreteKeys &discreteParents,
159  const FactorValuePairs &pairs, bool pruned = false);
160 
164 
166  bool equals(const HybridFactor &lf, double tol = 1e-9) const override;
167 
169  void print(
170  const std::string &s = "HybridGaussianConditional\n",
171  const KeyFormatter &formatter = DefaultKeyFormatter) const override;
172 
176 
179  const DiscreteValues &discreteValues) const;
180 
183  const DiscreteValues &discreteValues) const {
184  return choose(discreteValues);
185  }
186 
188  size_t nrComponents() const;
189 
191  KeyVector continuousParents() const;
192 
201  inline double negLogConstant() const override { return negLogConstant_; }
202 
207  std::shared_ptr<HybridGaussianFactor> likelihood(
208  const VectorValues &given) const;
209 
212  const Conditionals conditionals() const;
213 
220  double logProbability(const HybridValues &values) const override;
221 
223  double evaluate(const HybridValues &values) const override;
224 
226  double operator()(const HybridValues &values) const {
227  return evaluate(values);
228  }
229 
238  const DecisionTreeFactor &discreteProbs) const;
239 
241  bool pruned() const { return pruned_; }
242 
244 
245  private:
247  struct Helper;
248 
250  HybridGaussianConditional(const DiscreteKeys &discreteParents,
251  Helper &&helper, bool pruned = false);
252 
254  bool allFrontalsGiven(const VectorValues &given) const;
255 
256 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
257 
258  friend class boost::serialization::access;
259  template <class Archive>
260  void serialize(Archive &ar, const unsigned int /*version*/) {
261  ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseFactor);
262  ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseConditional);
263  }
264 #endif
265 };
266 
268 std::set<DiscreteKey> DiscreteKeysAsSet(const DiscreteKeys &discreteKeys);
269 
270 // traits
271 template <>
273  : public Testable<HybridGaussianConditional> {};
274 
275 } // namespace gtsam
gtsam::DecisionTreeFactor
Definition: DecisionTreeFactor.h:45
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
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
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::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41
HybridValues
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
HybridGaussianFactor.h
A set of GaussianFactors, indexed by a set of discrete keys.
equal_constants::conditionals
const std::vector< GaussianConditional::shared_ptr > conditionals
Definition: testHybridGaussianConditional.cpp:53
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:156
HybridFactor.h
A
Definition: test_numpy_dtypes.cpp:298
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
parameters
static ConjugateGradientParameters parameters
Definition: testIterative.cpp:33
DecisionTree.h
Decision Tree for use in DiscreteFactors.
A2
static const double A2[]
Definition: expn.h:7
gtsam::HybridGaussianConditional
A conditional of gaussian conditionals indexed by discrete variables, as part of a Bayes Network....
Definition: HybridGaussianConditional.h:54
gtsam::HybridGaussianConditional::operator()
double operator()(const HybridValues &values) const
Evaluate probability density, sugar.
Definition: HybridGaussianConditional.h:226
gtsam::Conditional
Definition: Conditional.h:63
gtsam::equals
Definition: Testable.h:112
DiscreteKey.h
specialized key for discrete variables
gtsam::HybridGaussianConditional::pruned
bool pruned() const
Return true if the conditional has already been pruned.
Definition: HybridGaussianConditional.h:241
key
const gtsam::Symbol key('X', 0)
gtsam::DecisionTree
a decision tree is a function from assignments to values.
Definition: DecisionTree.h:62
gtsam::DiscreteKeysAsSet
std::set< DiscreteKey > DiscreteKeysAsSet(const DiscreteKeys &discreteKeys)
Return the DiscreteKey vector as a set.
Definition: HybridGaussianConditional.cpp:300
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
DecisionTree-inl.h
gtsam::traits
Definition: Group.h:36
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::HybridGaussianConditional::operator()
GaussianConditional::shared_ptr operator()(const DiscreteValues &discreteValues) const
Syntactic sugar for choose.
Definition: HybridGaussianConditional.h:182
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
gtsam::HybridGaussianFactor
Implementation of a discrete-conditioned hybrid factor. Implements a joint discrete-continuous factor...
Definition: HybridGaussianFactor.h:60
A1
static const double A1[]
Definition: expn.h:6
gtsam::GaussianConditional::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianConditional.h:46
gtsam::HybridGaussianConditional::negLogConstant_
double negLogConstant_
Definition: HybridGaussianConditional.h:69
gtsam::HybridGaussianConditional::negLogConstant
double negLogConstant() const override
Return log normalization constant in negative log space.
Definition: HybridGaussianConditional.h:201
gtsam::tol
const G double tol
Definition: Group.h:79
Conditional.h
Base class for conditional densities.
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
DecisionTreeFactor.h
choose
static const T & choose(int layout, const T &col, const T &row)
Definition: cxx11_tensor_block_access.cpp:27


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