gtsam
Loading...
Searching...
No Matches
SymbolicFactor.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
17
18#pragma once
19
21#include <gtsam/inference/Key.h>
22#include <gtsam/base/Testable.h>
23
24#include <memory>
25
26#include <utility>
27
28namespace gtsam {
29
30 // Forward declarations
32 class HybridValues;
33 class Ordering;
34
38 class GTSAM_EXPORT SymbolicFactor : public Factor {
39
40 public:
41
42 typedef SymbolicFactor This;
43 typedef Factor Base;
44 typedef SymbolicConditional ConditionalType;
45
47 typedef std::shared_ptr<This> shared_ptr;
48
51
54
56 explicit SymbolicFactor(Key j) :
57 Base(KeyVector{j}) {}
58
61 Base(KeyVector{j1, j2}) {}
62
64 SymbolicFactor(Key j1, Key j2, Key j3) :
65 Base(KeyVector{j1, j2, j3}) {}
66
68 SymbolicFactor(Key j1, Key j2, Key j3, Key j4) :
69 Base(KeyVector{j1, j2, j3, j4}) {}
70
72 SymbolicFactor(Key j1, Key j2, Key j3, Key j4, Key j5) :
73 Base(KeyVector{j1, j2, j3, j4, j5}) {}
74
76 SymbolicFactor(Key j1, Key j2, Key j3, Key j4, Key j5, Key j6) :
77 Base(KeyVector{j1, j2, j3, j4, j5, j6}) {}
78
80 explicit SymbolicFactor(const Factor& factor) : Base(factor.keys()) {}
81
83 SymbolicFactor::shared_ptr clone() const { return std::make_shared<This>(*this); }
84
86
89
90 bool equals(const This& other, double tol = 1e-9) const;
91
93 void print(
94 const std::string& s = "SymbolicFactor",
95 const KeyFormatter& formatter = DefaultKeyFormatter) const override {
96 Base::print(s, formatter);
97 }
98
101 const std::string& s = "SymbolicFactor",
102 const KeyFormatter& formatter = DefaultKeyFormatter) const override {
103 Base::printKeys(s, formatter);
104 }
105
109
111 template<typename KEYITERATOR>
112 static SymbolicFactor FromIterators(KEYITERATOR beginKey, KEYITERATOR endKey) {
113 return SymbolicFactor(Base::FromIterators(beginKey, endKey));
114 }
115
117 template<typename KEYITERATOR>
118 static SymbolicFactor::shared_ptr FromIteratorsShared(KEYITERATOR beginKey, KEYITERATOR endKey) {
119 SymbolicFactor::shared_ptr result = std::make_shared<SymbolicFactor>();
120 result->keys_.assign(beginKey, endKey);
121 return result;
122 }
123
126 template<class CONTAINER>
127 static SymbolicFactor FromKeys(const CONTAINER& keys) {
129 }
130
133 template<class CONTAINER>
135 return FromIteratorsShared(keys.begin(), keys.end());
136 }
137
139
142
144 double error(const HybridValues& c) const override;
145
148 std::pair<std::shared_ptr<SymbolicConditional>, std::shared_ptr<SymbolicFactor> >
149 eliminate(const Ordering& keys) const;
150
152
153 private:
154#if GTSAM_ENABLE_BOOST_SERIALIZATION
156 friend class boost::serialization::access;
157 template<class ARCHIVE>
158 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
159 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
160 }
161#endif
162 }; // IndexFactor
163
164 // Forward declarations
166 class Ordering;
167
172 GTSAM_EXPORT std::pair<std::shared_ptr<SymbolicConditional>, std::shared_ptr<SymbolicFactor> >
173 EliminateSymbolic(const SymbolicFactorGraph& factors, const Ordering& keys);
174
176 template<>
177 struct traits<SymbolicFactor> : public Testable<SymbolicFactor> {
178 };
179
180} //\ namespace gtsam
181
Concept check for values that can be used in unit tests.
The base class for all factors.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
std::pair< std::shared_ptr< SymbolicConditional >, std::shared_ptr< SymbolicFactor > > EliminateSymbolic(const SymbolicFactorGraph &factors, const Ordering &keys)
Dense elimination function for symbolic factors.
Definition SymbolicFactor.cpp:35
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
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Template to create a binary predicate.
Definition Testable.h:112
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
HybridValues represents a collection of DiscreteValues and VectorValues.
Definition HybridValues.h:37
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:143
Factor()
Default constructor for I/O.
Definition Factor.h:94
static Factor FromIterators(ITERATOR first, ITERATOR last)
Construct factor from iterator keys.
Definition Factor.h:115
static Factor FromKeys(const CONTAINER &keys)
Construct factor from container of keys.
Definition Factor.h:109
virtual void printKeys(const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
print only keys
Definition Factor.cpp:35
virtual void print(const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
print
Definition Factor.cpp:29
Definition Ordering.h:33
SymbolicConditional is a conditional with keys but no probability data, produced by symbolic eliminat...
Definition SymbolicConditional.h:38
SymbolicFactor represents a symbolic factor that specifies graph topology but is not associated with ...
Definition SymbolicFactor.h:38
void print(const std::string &s="SymbolicFactor", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
Definition SymbolicFactor.h:93
SymbolicFactor(Key j1, Key j2, Key j3, Key j4, Key j5, Key j6)
Construct 6-way factor.
Definition SymbolicFactor.h:76
static SymbolicFactor FromKeys(const CONTAINER &keys)
Constructor from a collection of keys - compatible with boost assign::list_of and boost assign::cref_...
Definition SymbolicFactor.h:127
SymbolicFactor(const Factor &factor)
Create symbolic version of any factor.
Definition SymbolicFactor.h:80
SymbolicFactor(Key j1, Key j2, Key j3, Key j4)
Construct 4-way factor.
Definition SymbolicFactor.h:68
SymbolicFactor(Key j1, Key j2)
Construct binary factor.
Definition SymbolicFactor.h:60
static SymbolicFactor FromIterators(KEYITERATOR beginKey, KEYITERATOR endKey)
Constructor from a collection of keys.
Definition SymbolicFactor.h:112
std::shared_ptr< This > shared_ptr
Overriding the shared_ptr typedef.
Definition SymbolicFactor.h:47
void printKeys(const std::string &s="SymbolicFactor", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print only keys
Definition SymbolicFactor.h:100
static SymbolicFactor::shared_ptr FromKeysShared(const CONTAINER &keys)
Constructor from a collection of keys - compatible with boost assign::list_of and boost assign::cref_...
Definition SymbolicFactor.h:134
SymbolicFactor(Key j1, Key j2, Key j3)
Construct ternary factor.
Definition SymbolicFactor.h:64
SymbolicFactor(Key j)
Construct unary factor.
Definition SymbolicFactor.h:56
SymbolicFactor(Key j1, Key j2, Key j3, Key j4, Key j5)
Construct 5-way factor.
Definition SymbolicFactor.h:72
static SymbolicFactor::shared_ptr FromIteratorsShared(KEYITERATOR beginKey, KEYITERATOR endKey)
Constructor from a collection of keys.
Definition SymbolicFactor.h:118
SymbolicFactor()
Default constructor for I/O.
Definition SymbolicFactor.h:53
SymbolicFactor::shared_ptr clone() const
Copy this object as its actual derived type.
Definition SymbolicFactor.h:83
Symbolic Factor Graph.
Definition SymbolicFactorGraph.h:64