gtsam 4.2.0
gtsam
Loading...
Searching...
No Matches
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 <boost/make_shared.hpp>
29#include <string>
30#include <utility>
31#include <vector>
32
33namespace gtsam {
34
35// Forward declarations
36class DiscreteFactorGraph;
37class DiscreteConditional;
38class DiscreteBayesNet;
39class DiscreteEliminationTree;
40class DiscreteBayesTree;
41class DiscreteJunctionTree;
42
51GTSAM_EXPORT std::pair<boost::shared_ptr<DiscreteConditional>, DecisionTreeFactor::shared_ptr>
52EliminateDiscrete(const DiscreteFactorGraph& factors, const Ordering& keys);
53
54/* ************************************************************************* */
56{
65 static std::pair<boost::shared_ptr<ConditionalType>,
66 boost::shared_ptr<FactorType> >
67 DefaultEliminate(const FactorGraphType& factors, const Ordering& keys) {
68 return EliminateDiscrete(factors, keys);
69 }
72 const FactorGraphType& graph,
73 boost::optional<const VariableIndex&> variableIndex) {
74 return Ordering::Colamd(*variableIndex);
75 }
76};
77
78/* ************************************************************************* */
84class GTSAM_EXPORT DiscreteFactorGraph
85 : public FactorGraph<DiscreteFactor>,
86 public EliminateableFactorGraph<DiscreteFactorGraph> {
87 public:
92 using shared_ptr = boost::shared_ptr<This>;
93
95
96 using Indices = KeyVector;
97
100
102 template <typename ITERATOR>
103 DiscreteFactorGraph(ITERATOR firstFactor, ITERATOR lastFactor)
104 : Base(firstFactor, lastFactor) {}
105
107 template <class CONTAINER>
108 explicit DiscreteFactorGraph(const CONTAINER& factors) : Base(factors) {}
109
112 template <class DERIVEDFACTOR>
114
117
120
121 bool equals(const This& fg, double tol = 1e-9) const;
122
124
126 template <typename... Args>
127 void add(Args&&... args) {
128 emplace_shared<DecisionTreeFactor>(std::forward<Args>(args)...);
129 }
130
132 KeySet keys() const;
133
135 DiscreteKeys discreteKeys() const;
136
138 DecisionTreeFactor product() const;
139
144 double operator()(const DiscreteValues& values) const;
145
147 void print(
148 const std::string& s = "DiscreteFactorGraph",
149 const KeyFormatter& formatter = DefaultKeyFormatter) const override;
150
157 DiscreteBayesNet sumProduct(
158 OptionalOrderingType orderingType = boost::none) const;
159
166 DiscreteBayesNet sumProduct(const Ordering& ordering) const;
167
174 DiscreteLookupDAG maxProduct(
175 OptionalOrderingType orderingType = boost::none) const;
176
183 DiscreteLookupDAG maxProduct(const Ordering& ordering) const;
184
192 OptionalOrderingType orderingType = boost::none) const;
193
200 DiscreteValues optimize(const Ordering& ordering) const;
201
204
212 std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
213 const DiscreteFactor::Names& names = {}) const;
214
222 std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
223 const DiscreteFactor::Names& names = {}) const;
224
228
229 using Base::error; // Expose error(const HybridValues&) method..
230
232}; // \ DiscreteFactorGraph
233
234std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr> //
235EliminateForMPE(const DiscreteFactorGraph& factors,
236 const Ordering& frontalKeys);
237
239template <>
240struct traits<DiscreteFactorGraph> : public Testable<DiscreteFactorGraph> {};
241
242} // namespace gtsam
A thin wrapper around std::set that uses boost's fast_pool_allocator.
Variable ordering for the elimination algorithm.
Variable elimination algorithms for factor graphs.
Factor Graph Base Class.
std::pair< DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr > EliminateDiscrete(const DiscreteFactorGraph &factors, const Ordering &frontalKeys)
Main elimination function for DiscreteFactorGraph.
Definition DiscreteFactorGraph.cpp:200
Global functions in a separate testing namespace.
Definition chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:86
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
Definition DiscreteValues.cpp:129
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Optimize for triangulation.
Definition triangulation.cpp:155
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
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
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
Template to create a binary predicate.
Definition Testable.h:111
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
A discrete probabilistic factor.
Definition DecisionTreeFactor.h:45
A Bayes net made from discrete conditional distributions.
Definition DiscreteBayesNet.h:38
A Bayes tree representing a Discrete density.
Definition DiscreteBayesTree.h:70
Discrete Conditional Density Derives from DecisionTreeFactor.
Definition DiscreteConditional.h:40
Elimination tree for discrete factors.
Definition DiscreteEliminationTree.h:33
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition DiscreteFactor.h:38
DiscreteValues::Names Names
Translation table from values to strings.
Definition DiscreteFactor.h:106
DiscreteFactorGraph FactorGraphType
Type of the factor graph (e.g. DiscreteFactorGraph)
Definition DiscreteFactorGraph.h:58
DiscreteJunctionTree JunctionTreeType
Type of Junction tree.
Definition DiscreteFactorGraph.h:63
DiscreteFactor FactorType
Type of factors in factor graph.
Definition DiscreteFactorGraph.h:57
static std::pair< boost::shared_ptr< ConditionalType >, boost::shared_ptr< FactorType > > DefaultEliminate(const FactorGraphType &factors, const Ordering &keys)
The default dense elimination function.
Definition DiscreteFactorGraph.h:67
DiscreteBayesTree BayesTreeType
Type of Bayes tree.
Definition DiscreteFactorGraph.h:62
DiscreteBayesNet BayesNetType
Type of Bayes net from sequential elimination.
Definition DiscreteFactorGraph.h:60
DiscreteConditional ConditionalType
Type of conditionals from elimination.
Definition DiscreteFactorGraph.h:59
static Ordering DefaultOrderingFunc(const FactorGraphType &graph, boost::optional< const VariableIndex & > variableIndex)
The default ordering generation function.
Definition DiscreteFactorGraph.h:71
DiscreteEliminationTree EliminationTreeType
Type of elimination tree.
Definition DiscreteFactorGraph.h:61
A Discrete Factor Graph is a factor graph where all factors are Discrete, i.e.
Definition DiscreteFactorGraph.h:86
DiscreteFactorGraph(const CONTAINER &factors)
Construct from container of factors (shared_ptr or plain objects)
Definition DiscreteFactorGraph.h:108
boost::shared_ptr< This > shared_ptr
shared_ptr to This
Definition DiscreteFactorGraph.h:92
DiscreteFactorGraph()
‍map from keys to values
Definition DiscreteFactorGraph.h:99
DiscreteFactorGraph(const FactorGraph< DERIVEDFACTOR > &graph)
Implicit copy/downcast constructor to override explicit template container constructor.
Definition DiscreteFactorGraph.h:113
DiscreteFactorGraph(ITERATOR firstFactor, ITERATOR lastFactor)
Construct from iterator over factors.
Definition DiscreteFactorGraph.h:103
virtual ~DiscreteFactorGraph()
Destructor.
Definition DiscreteFactorGraph.h:116
EliminateableFactorGraph< This > BaseEliminateable
for elimination
Definition DiscreteFactorGraph.h:91
void add(Args &&... args)
Add a decision-tree factor.
Definition DiscreteFactorGraph.h:127
An EliminatableClusterTree, i.e., a set of variable clusters with factors, arranged in a tree,...
Definition DiscreteJunctionTree.h:52
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:39
A DAG made from lookup tables, as defined above.
Definition DiscreteLookupDAG.h:77
A map from keys to values.
Definition DiscreteValues.h:34
A factor graph is a bipartite graph with factor nodes connected to variable nodes.
Definition FactorGraph.h:97
Traits class for eliminateable factor graphs, specifies the types that result from elimination,...
Definition EliminateableFactorGraph.h:36
EliminateableFactorGraph is a base class for factor graphs that contains elimination algorithms.
Definition EliminateableFactorGraph.h:57
Definition Ordering.h:34
static Ordering Colamd(const FACTOR_GRAPH &graph)
Compute a fill-reducing ordering using COLAMD from a factor graph (see details for note on performanc...
Definition Ordering.h:95