HybridGaussianFactorGraph.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 
31 
32 #include <functional>
33 #include <optional>
34 
35 namespace gtsam {
36 
37 // Forward declarations
38 class HybridGaussianFactorGraph;
39 class HybridConditional;
40 class HybridBayesNet;
41 class HybridEliminationTree;
42 class HybridBayesTree;
43 class HybridJunctionTree;
44 class DecisionTreeFactor;
45 class TableFactor;
46 class JacobianFactor;
47 class HybridValues;
48 
57 GTSAM_EXPORT
58 std::pair<std::shared_ptr<HybridConditional>, std::shared_ptr<Factor>>
59 EliminateHybrid(const HybridGaussianFactorGraph& factors, const Ordering& keys);
60 
67 GTSAM_EXPORT const Ordering
68 HybridOrdering(const HybridGaussianFactorGraph& graph);
69 
70 /* ************************************************************************* */
71 template <>
73  typedef Factor FactorType;
76  typedef HybridConditional
79  typedef HybridBayesNet
81  typedef HybridEliminationTree
85  static std::pair<std::shared_ptr<ConditionalType>,
87  std::shared_ptr<FactorType>>
89  return EliminateHybrid(factors, keys);
90  }
93  const FactorGraphType& graph,
94  std::optional<std::reference_wrapper<const VariableIndex>>) {
95  return HybridOrdering(graph);
96  }
97 };
98 
106 class GTSAM_EXPORT HybridGaussianFactorGraph
107  : public HybridFactorGraph,
108  public EliminateableFactorGraph<HybridGaussianFactorGraph> {
109  protected:
111  template <typename FACTOR>
112  using IsGaussian = typename std::enable_if<
114 
115  public:
120  using shared_ptr = std::shared_ptr<This>;
121 
123  using Indices = KeyVector;
124 
127 
129  HybridGaussianFactorGraph() = default;
130 
132  template <class CONTAINER>
133  explicit HybridGaussianFactorGraph(const CONTAINER& factors)
134  : Base(factors) {}
135 
141  HybridGaussianFactorGraph(std::initializer_list<sharedFactor> factors)
142  : Base(factors) {}
143 
149  template <class DERIVEDFACTOR>
151  : Base(graph) {}
152 
156 
157  void print(
158  const std::string& s = "HybridGaussianFactorGraph",
159  const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override;
160 
169  void printErrors(
170  const HybridValues& values,
171  const std::string& str = "HybridGaussianFactorGraph: ",
172  const KeyFormatter& keyFormatter = DefaultKeyFormatter,
173  const std::function<bool(const Factor* /*factor*/,
174  double /*whitenedError*/, size_t /*index*/)>&
175  printCondition =
176  [](const Factor*, double, size_t) { return true; }) const;
177 
178  // bool equals(const This& fg, double tol = 1e-9) const override;
179 
183 
185  using Base::error;
186 
196  AlgebraicDecisionTree<Key> errorTree(
197  const VectorValues& continuousValues) const;
198 
205  double probPrime(const HybridValues& values) const;
206 
217  AlgebraicDecisionTree<Key> discretePosterior(
218  const VectorValues& continuousValues) const;
219 
229  HybridGaussianProductFactor collectProductFactor() const;
230 
237  std::pair<std::shared_ptr<HybridConditional>, std::shared_ptr<Factor>>
238  eliminate(const Ordering& keys) const;
240 
252  GaussianFactorGraph choose(const DiscreteValues& assignment) const;
253 
255  GaussianFactorGraph operator()(const DiscreteValues& assignment) const {
256  return choose(assignment);
257  }
258 
265  DiscreteFactorGraph discreteFactors() const;
266 };
267 
268 // traits
269 template <>
271  : public Testable<HybridGaussianFactorGraph> {};
272 
273 } // namespace gtsam
gtsam::HybridGaussianFactorGraph::operator()
GaussianFactorGraph operator()(const DiscreteValues &assignment) const
Syntactic sugar for choose.
Definition: HybridGaussianFactorGraph.h:255
VectorValues
gtsam::HybridFactorGraph
Definition: HybridFactorGraph.h:38
gtsam::HybridValues
Definition: HybridValues.h:37
gtsam::EliminationTraits< HybridGaussianFactorGraph >::BayesTreeType
HybridBayesTree BayesTreeType
Type of Bayes tree.
Definition: HybridGaussianFactorGraph.h:83
gtsam::DiscreteFactorGraph
Definition: DiscreteFactorGraph.h:99
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
gtsam::HybridConditional
Definition: HybridConditional.h:60
s
RealScalar s
Definition: level1_cplx_impl.h:126
gtsam::HybridBayesNet
Definition: HybridBayesNet.h:37
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
DiscreteFactorGraph.h
simple_graph::factors
const GaussianFactorGraph factors
Definition: testJacobianFactor.cpp:213
gtsam::HybridBayesTree
Definition: HybridBayesTree.h:62
gtsam::EliminationTraits< HybridGaussianFactorGraph >::EliminationTreeType
HybridEliminationTree EliminationTreeType
Type of elimination tree.
Definition: HybridGaussianFactorGraph.h:82
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
Ordering.h
Variable ordering for the elimination algorithm.
gtsam::Factor
Definition: Factor.h:70
HybridValues
gtsam::HybridGaussianFactorGraph::HybridGaussianFactorGraph
HybridGaussianFactorGraph(std::initializer_list< sharedFactor > factors)
Definition: HybridGaussianFactorGraph.h:141
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.
gtsam::EliminationTraits< HybridGaussianFactorGraph >::DefaultEliminate
static std::pair< std::shared_ptr< ConditionalType >, std::shared_ptr< FactorType > > DefaultEliminate(const FactorGraphType &factors, const Ordering &keys)
The default dense elimination function.
Definition: HybridGaussianFactorGraph.h:88
gtsam::HybridGaussianFactorGraph::HybridGaussianFactorGraph
HybridGaussianFactorGraph(const FactorGraph< DERIVEDFACTOR > &graph)
Definition: HybridGaussianFactorGraph.h:150
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::FactorGraph< Factor >
gtsam::EliminationTraits< HybridGaussianFactorGraph >::FactorType
Factor FactorType
Type of factors in factor graph.
Definition: HybridGaussianFactorGraph.h:73
gtsam::GaussianFactorGraph
Definition: GaussianFactorGraph.h:73
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:156
HybridFactor.h
gtsam::HybridGaussianFactorGraph::HybridGaussianFactorGraph
HybridGaussianFactorGraph(const CONTAINER &factors)
Definition: HybridGaussianFactorGraph.h:133
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::EliminationTraits< HybridGaussianFactorGraph >::JunctionTreeType
HybridJunctionTree JunctionTreeType
Definition: HybridGaussianFactorGraph.h:84
gtsam::HybridGaussianFactorGraph
Definition: HybridGaussianFactorGraph.h:106
gtsam::HybridGaussianFactorGraph::IsGaussian
typename std::enable_if< std::is_base_of< GaussianFactor, FACTOR >::value >::type IsGaussian
Check if FACTOR type is derived from GaussianFactor.
Definition: HybridGaussianFactorGraph.h:113
DiscreteValues
VectorValues.h
Factor Graph Values.
gtsam::EliminateHybrid
std::pair< HybridConditional::shared_ptr, std::shared_ptr< Factor > > EliminateHybrid(const HybridGaussianFactorGraph &factors, const Ordering &keys)
Main elimination function for HybridGaussianFactorGraph.
Definition: HybridGaussianFactorGraph.cpp:433
EliminateableFactorGraph.h
Variable elimination algorithms for factor graphs.
gtsam::EliminationTraits
Definition: BayesTreeCliqueBase.h:33
gtsam::HybridEliminationTree
Definition: HybridEliminationTree.h:31
DiscreteKey.h
specialized key for discrete variables
str
Definition: pytypes.h:1558
HybridFactorGraph.h
Factor graph with utilities for hybrid factors.
gtsam::EliminationTraits< HybridGaussianFactorGraph >::ConditionalType
HybridConditional ConditionalType
Type of conditionals from elimination.
Definition: HybridGaussianFactorGraph.h:78
Values
std::vector< float > Values
Definition: sparse_setter.cpp:45
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
FactorGraph.h
Factor Graph Base Class.
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::Values
Definition: Values.h:65
gtsam::HybridFactorGraph::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to This
Definition: HybridFactorGraph.h:42
JacobianFactor
gtsam::HybridOrdering
const Ordering HybridOrdering(const HybridGaussianFactorGraph &graph)
Return a Colamd constrained ordering where the discrete keys are eliminated after the continuous keys...
Definition: HybridGaussianFactorGraph.cpp:87
gtsam::EliminationTraits< HybridGaussianFactorGraph >::FactorGraphType
HybridGaussianFactorGraph FactorGraphType
Definition: HybridGaussianFactorGraph.h:75
gtsam::EliminationTraits< HybridGaussianFactorGraph >::DefaultOrderingFunc
static Ordering DefaultOrderingFunc(const FactorGraphType &graph, std::optional< std::reference_wrapper< const VariableIndex >>)
The default ordering generation function.
Definition: HybridGaussianFactorGraph.h:92
GaussianFactor.h
A factor with a quadratic error function - a Gaussian.
gtsam::EliminateableFactorGraph
Definition: EliminateableFactorGraph.h:55
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
gtsam::HybridJunctionTree
Definition: HybridJunctionTree.h:52
gtsam::EliminationTraits< HybridGaussianFactorGraph >::BayesNetType
HybridBayesNet BayesNetType
Type of Bayes net from sequential elimination.
Definition: HybridGaussianFactorGraph.h:80
gtsam::Ordering
Definition: inference/Ordering.h:33
choose
static const T & choose(int layout, const T &col, const T &row)
Definition: cxx11_tensor_block_access.cpp:27
gtsam::HybridFactorGraph::Indices
KeyVector Indices
Definition: HybridFactorGraph.h:45
test_callbacks.value
value
Definition: test_callbacks.py:160


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