gtsam 4.1.1
gtsam
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#include <boost/make_shared.hpp>
28
29namespace gtsam {
30
31// Forward declarations
32class DiscreteFactorGraph;
33class DiscreteFactor;
34class DiscreteConditional;
35class DiscreteBayesNet;
36class DiscreteEliminationTree;
37class DiscreteBayesTree;
38class DiscreteJunctionTree;
39
41GTSAM_EXPORT std::pair<boost::shared_ptr<DiscreteConditional>, DecisionTreeFactor::shared_ptr>
42EliminateDiscrete(const DiscreteFactorGraph& factors, const Ordering& keys);
43
44/* ************************************************************************* */
46{
55 static std::pair<boost::shared_ptr<ConditionalType>, boost::shared_ptr<FactorType> >
56 DefaultEliminate(const FactorGraphType& factors, const Ordering& keys) {
57 return EliminateDiscrete(factors, keys); }
58};
59
60/* ************************************************************************* */
65class GTSAM_EXPORT DiscreteFactorGraph: public FactorGraph<DiscreteFactor>,
66public EliminateableFactorGraph<DiscreteFactorGraph> {
67public:
68
72 typedef boost::shared_ptr<This> shared_ptr;
73
76 typedef Assignment<Key> Values;
77 typedef boost::shared_ptr<Values> sharedValues;
78
81
83 template<typename ITERATOR>
84 DiscreteFactorGraph(ITERATOR firstFactor, ITERATOR lastFactor) : Base(firstFactor, lastFactor) {}
85
87 template<class CONTAINER>
88 explicit DiscreteFactorGraph(const CONTAINER& factors) : Base(factors) {}
89
91 template<class DERIVEDFACTOR>
93
96
99
100 bool equals(const This& fg, double tol = 1e-9) const;
101
103
104 template<class SOURCE>
105 void add(const DiscreteKey& j, SOURCE table) {
106 DiscreteKeys keys;
107 keys.push_back(j);
108 push_back(boost::make_shared<DecisionTreeFactor>(keys, table));
109 }
110
111 template<class SOURCE>
112 void add(const DiscreteKey& j1, const DiscreteKey& j2, SOURCE table) {
113 DiscreteKeys keys;
114 keys.push_back(j1);
115 keys.push_back(j2);
116 push_back(boost::make_shared<DecisionTreeFactor>(keys, table));
117 }
118
120 template<class SOURCE>
121 void add(const DiscreteKeys& keys, SOURCE table) {
122 push_back(boost::make_shared<DecisionTreeFactor>(keys, table));
123 }
124
126 KeySet keys() const;
127
129 DecisionTreeFactor product() const;
130
132 double operator()(const DiscreteFactor::Values & values) const;
133
135 void print(
136 const std::string& s = "DiscreteFactorGraph",
137 const KeyFormatter& formatter = DefaultKeyFormatter) const override;
138
143 DiscreteFactor::sharedValues optimize() const;
144
145
146// /** Permute the variables in the factors */
147// GTSAM_EXPORT void permuteWithInverse(const Permutation& inversePermutation);
148//
149// /** Apply a reduction, which is a remapping of variable indices. */
150// GTSAM_EXPORT void reduceWithInverse(const internal::Reduction& inverseReduction);
151
152}; // \ DiscreteFactorGraph
153
155template<> struct traits<DiscreteFactorGraph> : public Testable<DiscreteFactorGraph> {};
156
157} // \ namespace gtsam
A thin wrapper around std::set that uses boost's fast_pool_allocator.
Factor Graph Base Class.
Variable ordering for the elimination algorithm.
Variable elimination algorithms for factor graphs.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
std::pair< DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr > EliminateDiscrete(const DiscreteFactorGraph &factors, const Ordering &frontalKeys)
Main elimination function for DiscreteFactorGraph.
Definition: DiscreteFactorGraph.cpp:105
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Optimize for triangulation.
Definition: triangulation.cpp:73
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
std::pair< Key, size_t > DiscreteKey
Key type for discrete conditionals Includes name and cardinality.
Definition: DiscreteKey.h:34
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
An assignment from labels to value index (size_t).
Definition: Assignment.h:34
A discrete probabilistic factor.
Definition: DecisionTreeFactor.h:38
A Bayes net made from linear-Discrete densities.
Definition: DiscreteBayesNet.h:31
A Bayes tree representing a Discrete density.
Definition: DiscreteBayesTree.h:67
Discrete Conditional Density Derives from DecisionTreeFactor.
Definition: DiscreteConditional.h:36
Definition: DiscreteEliminationTree.h:29
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition: DiscreteFactor.h:34
DiscreteFactorGraph FactorGraphType
Type of the factor graph (e.g. DiscreteFactorGraph)
Definition: DiscreteFactorGraph.h:48
DiscreteJunctionTree JunctionTreeType
Type of Junction tree.
Definition: DiscreteFactorGraph.h:53
DiscreteFactor FactorType
Type of factors in factor graph.
Definition: DiscreteFactorGraph.h:47
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:56
DiscreteBayesTree BayesTreeType
Type of Bayes tree.
Definition: DiscreteFactorGraph.h:52
DiscreteBayesNet BayesNetType
Type of Bayes net from sequential elimination.
Definition: DiscreteFactorGraph.h:50
DiscreteConditional ConditionalType
Type of conditionals from elimination.
Definition: DiscreteFactorGraph.h:49
DiscreteEliminationTree EliminationTreeType
Type of elimination tree.
Definition: DiscreteFactorGraph.h:51
A Discrete Factor Graph is a factor graph where all factors are Discrete, i.e.
Definition: DiscreteFactorGraph.h:66
DiscreteFactorGraph(const CONTAINER &factors)
Construct from container of factors (shared_ptr or plain objects)
Definition: DiscreteFactorGraph.h:88
KeyVector Indices
A map from keys to values.
Definition: DiscreteFactorGraph.h:75
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: DiscreteFactorGraph.h:72
DiscreteFactorGraph This
Typedef to this class.
Definition: DiscreteFactorGraph.h:69
FactorGraph< DiscreteFactor > Base
Typedef to base factor graph type.
Definition: DiscreteFactorGraph.h:70
void add(const DiscreteKeys &keys, SOURCE table)
add shared discreteFactor immediately from arguments
Definition: DiscreteFactorGraph.h:121
DiscreteFactorGraph()
Default constructor.
Definition: DiscreteFactorGraph.h:80
EliminateableFactorGraph< This > BaseEliminateable
Typedef to base elimination class.
Definition: DiscreteFactorGraph.h:71
DiscreteFactorGraph(const FactorGraph< DERIVEDFACTOR > &graph)
Implicit copy/downcast constructor to override explicit template container constructor.
Definition: DiscreteFactorGraph.h:92
DiscreteFactorGraph(ITERATOR firstFactor, ITERATOR lastFactor)
Construct from iterator over factors.
Definition: DiscreteFactorGraph.h:84
virtual ~DiscreteFactorGraph()
Destructor.
Definition: DiscreteFactorGraph.h:95
Definition: DiscreteJunctionTree.h:49
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:37
A factor graph is a bipartite graph with factor nodes connected to variable nodes.
Definition: FactorGraph.h:93
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