DiscreteFactorGraph.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/base/FastSet.h>
27 
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 namespace gtsam {
33 
34 // Forward declarations
35 class DiscreteFactorGraph;
36 class DiscreteConditional;
37 class DiscreteBayesNet;
38 class DiscreteEliminationTree;
39 class DiscreteBayesTree;
40 class DiscreteJunctionTree;
41 
50 GTSAM_EXPORT
51 std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr>
52 EliminateDiscrete(const DiscreteFactorGraph& factors,
53  const Ordering& frontalKeys);
54 
63 GTSAM_EXPORT
64 std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr>
65 EliminateForMPE(const DiscreteFactorGraph& factors,
66  const Ordering& frontalKeys);
67 
69 {
77 
79  static std::pair<std::shared_ptr<ConditionalType>,
80  std::shared_ptr<FactorType> >
83  }
84 
87  const FactorGraphType& graph,
88  std::optional<std::reference_wrapper<const VariableIndex>> variableIndex) {
89  return Ordering::Colamd((*variableIndex).get());
90  }
91 };
92 
98 class GTSAM_EXPORT DiscreteFactorGraph
99  : public FactorGraph<DiscreteFactor>,
100  public EliminateableFactorGraph<DiscreteFactorGraph> {
101  public:
104  using BaseEliminateable =
106  using shared_ptr = std::shared_ptr<This>;
107 
109 
110  using Indices = KeyVector;
111 
114 
116  template <typename ITERATOR>
117  DiscreteFactorGraph(ITERATOR firstFactor, ITERATOR lastFactor)
118  : Base(firstFactor, lastFactor) {}
119 
121  template <class CONTAINER>
122  explicit DiscreteFactorGraph(const CONTAINER& factors) : Base(factors) {}
123 
126  template <class DERIVED_FACTOR>
128 
131 
132  bool equals(const This& fg, double tol = 1e-9) const;
133 
135 
137  template <typename... Args>
138  void add(Args&&... args) {
139  emplace_shared<DecisionTreeFactor>(std::forward<Args>(args)...);
140  }
141 
143  KeySet keys() const;
144 
146  DiscreteKeys discreteKeys() const;
147 
149  DecisionTreeFactor product() const;
150 
155  double operator()(const DiscreteValues& values) const;
156 
158  void print(
159  const std::string& s = "DiscreteFactorGraph",
160  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
161 
168  DiscreteBayesNet sumProduct(
169  OptionalOrderingType orderingType = {}) const;
170 
177  DiscreteBayesNet sumProduct(const Ordering& ordering) const;
178 
185  DiscreteLookupDAG maxProduct(
186  OptionalOrderingType orderingType = {}) const;
187 
194  DiscreteLookupDAG maxProduct(const Ordering& ordering) const;
195 
203  OptionalOrderingType orderingType = {}) const;
204 
211  DiscreteValues optimize(const Ordering& ordering) const;
212 
215 
223  std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
224  const DiscreteFactor::Names& names = {}) const;
225 
233  std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
234  const DiscreteFactor::Names& names = {}) const;
235 
239 
240  using Base::error; // Expose error(const HybridValues&) method..
241 
243 }; // \ DiscreteFactorGraph
244 
246 template <>
247 struct traits<DiscreteFactorGraph> : public Testable<DiscreteFactorGraph> {};
248 
249 } // namespace gtsam
gtsam::markdown
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
Definition: DiscreteValues.cpp:130
gtsam::DecisionTreeFactor
Definition: DecisionTreeFactor.h:44
gtsam::DiscreteFactorGraph
Definition: DiscreteFactorGraph.h:98
gtsam::DiscreteFactorGraph::DiscreteFactorGraph
DiscreteFactorGraph()
map from keys to values
Definition: DiscreteFactorGraph.h:113
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
gtsam::EliminationTraits< DiscreteFactorGraph >::EliminationTreeType
DiscreteEliminationTree EliminationTreeType
Type of elimination tree.
Definition: DiscreteFactorGraph.h:74
gtsam::optimize
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Definition: triangulation.cpp:177
simple_graph::factors
const GaussianFactorGraph factors
Definition: testJacobianFactor.cpp:213
gtsam::EliminationTraits< DiscreteFactorGraph >::JunctionTreeType
DiscreteJunctionTree JunctionTreeType
Type of Junction tree.
Definition: DiscreteFactorGraph.h:76
DiscreteLookupDAG.h
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::EliminationTraits< DiscreteFactorGraph >::FactorType
DiscreteFactor FactorType
Type of factors in factor graph.
Definition: DiscreteFactorGraph.h:70
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
Ordering.h
Variable ordering for the elimination algorithm.
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41
gtsam::FastSet
Definition: FastSet.h:51
gtsam::EliminationTraits< DiscreteFactorGraph >::FactorGraphType
DiscreteFactorGraph FactorGraphType
Type of the factor graph (e.g. DiscreteFactorGraph)
Definition: DiscreteFactorGraph.h:71
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::FactorGraph
Definition: BayesTree.h:34
gtsam::DiscreteFactorGraph::DiscreteFactorGraph
DiscreteFactorGraph(const CONTAINER &factors)
Definition: DiscreteFactorGraph.h:122
gtsam::DiscreteJunctionTree
Definition: DiscreteJunctionTree.h:51
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
FastSet.h
A thin wrapper around std::set that uses boost's fast_pool_allocator.
gtsam::EliminationTraits< DiscreteFactorGraph >::DefaultOrderingFunc
static Ordering DefaultOrderingFunc(const FactorGraphType &graph, std::optional< std::reference_wrapper< const VariableIndex >> variableIndex)
The default ordering generation function.
Definition: DiscreteFactorGraph.h:86
gtsam::DiscreteBayesNet
Definition: DiscreteBayesNet.h:38
gtsam::DiscreteEliminationTree
Elimination tree for discrete factors.
Definition: DiscreteEliminationTree.h:31
operator()
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
Definition: IndexedViewMethods.h:73
gtsam::Ordering::Colamd
static Ordering Colamd(const FACTOR_GRAPH &graph)
Definition: inference/Ordering.h:93
gtsam::EliminateDiscrete
std::pair< DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr > EliminateDiscrete(const DiscreteFactorGraph &factors, const Ordering &frontalKeys)
Main elimination function for DiscreteFactorGraph.
Definition: DiscreteFactorGraph.cpp:205
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::DiscreteFactorGraph::DiscreteFactorGraph
DiscreteFactorGraph(ITERATOR firstFactor, ITERATOR lastFactor)
Definition: DiscreteFactorGraph.h:117
gtsam::EliminationTraits< DiscreteFactorGraph >::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: DiscreteFactorGraph.h:81
gtsam::EliminationTraits< DiscreteFactorGraph >::BayesTreeType
DiscreteBayesTree BayesTreeType
Type of Bayes tree.
Definition: DiscreteFactorGraph.h:75
DiscreteValues
EliminateableFactorGraph.h
Variable elimination algorithms for factor graphs.
gtsam::EliminationTraits
Definition: BayesTreeCliqueBase.h:33
gtsam::EliminateForMPE
std::pair< DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr > EliminateForMPE(const DiscreteFactorGraph &factors, const Ordering &frontalKeys)
Alternate elimination function for that creates non-normalized lookup tables.
Definition: DiscreteFactorGraph.cpp:116
ordering
static enum @1096 ordering
gtsam::EliminationTraits< DiscreteFactorGraph >::ConditionalType
DiscreteConditional ConditionalType
Type of conditionals from elimination.
Definition: DiscreteFactorGraph.h:72
gtsam::equals
Definition: Testable.h:112
process_shonan_timing_results.names
dictionary names
Definition: process_shonan_timing_results.py:175
gtsam::DiscreteConditional
Definition: DiscreteConditional.h:37
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
gtsam::DiscreteFactor::Names
DiscreteValues::Names Names
Translation table from values to strings.
Definition: DiscreteFactor.h:121
FactorGraph.h
Factor Graph Base Class.
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
args
Definition: pytypes.h:2210
This
#define This
Definition: ActiveSetSolver-inl.h:27
gtsam::DiscreteFactorGraph::add
void add(Args &&... args)
Definition: DiscreteFactorGraph.h:138
gtsam::DiscreteBayesTree
A Bayes tree representing a Discrete distribution.
Definition: DiscreteBayesTree.h:73
product
void product(const MatrixType &m)
Definition: product.h:20
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::html
string html(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of html.
Definition: DiscreteValues.cpp:135
gtsam::DiscreteFactorGraph::Indices
KeyVector Indices
Definition: DiscreteFactorGraph.h:110
gtsam::DiscreteFactor
Definition: DiscreteFactor.h:39
gtsam::EliminationTraits< DiscreteFactorGraph >::BayesNetType
DiscreteBayesNet BayesNetType
Type of Bayes net from sequential elimination.
Definition: DiscreteFactorGraph.h:73
gtsam::EliminateableFactorGraph
Definition: EliminateableFactorGraph.h:55
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
gtsam::Ordering
Definition: inference/Ordering.h:33
DecisionTreeFactor.h
gtsam::DiscreteFactorGraph::DiscreteFactorGraph
DiscreteFactorGraph(const FactorGraph< DERIVED_FACTOR > &graph)
Definition: DiscreteFactorGraph.h:127
gtsam::DiscreteFactorGraph::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to This
Definition: DiscreteFactorGraph.h:106


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:13