gtsam 4.2.0
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
18#pragma once
19
21#include <gtsam/inference/Key.h>
22#include <gtsam/base/Testable.h>
23
24#include <boost/shared_ptr.hpp>
25#include <boost/make_shared.hpp>
26
27#include <utility>
28
29namespace gtsam {
30
31 // Forward declarations
32 class SymbolicConditional;
33 class HybridValues;
34 class Ordering;
35
39 class GTSAM_EXPORT SymbolicFactor : public Factor {
40
41 public:
42
43 typedef SymbolicFactor This;
44 typedef Factor Base;
46
48 typedef boost::shared_ptr<This> shared_ptr;
49
52
55
57 explicit SymbolicFactor(Key j) :
58 Base(KeyVector{j}) {}
59
62 Base(KeyVector{j1, j2}) {}
63
65 SymbolicFactor(Key j1, Key j2, Key j3) :
66 Base(KeyVector{j1, j2, j3}) {}
67
69 SymbolicFactor(Key j1, Key j2, Key j3, Key j4) :
70 Base(KeyVector{j1, j2, j3, j4}) {}
71
73 SymbolicFactor(Key j1, Key j2, Key j3, Key j4, Key j5) :
74 Base(KeyVector{j1, j2, j3, j4, j5}) {}
75
77 SymbolicFactor(Key j1, Key j2, Key j3, Key j4, Key j5, Key j6) :
78 Base(KeyVector{j1, j2, j3, j4, j5, j6}) {}
79
81 explicit SymbolicFactor(const Factor& factor) : Base(factor.keys()) {}
82
83 virtual ~SymbolicFactor() {}
84
86 SymbolicFactor::shared_ptr clone() const { return boost::make_shared<This>(*this); }
87
89
92
93 bool equals(const This& other, double tol = 1e-9) const;
94
96 void print(
97 const std::string& s = "SymbolicFactor",
98 const KeyFormatter& formatter = DefaultKeyFormatter) const override {
99 Base::print(s, formatter);
100 }
101
104 const std::string& s = "SymbolicFactor",
105 const KeyFormatter& formatter = DefaultKeyFormatter) const override {
106 Base::printKeys(s, formatter);
107 }
108
112
114 template<typename KEYITERATOR>
115 static SymbolicFactor FromIterators(KEYITERATOR beginKey, KEYITERATOR endKey) {
116 return SymbolicFactor(Base::FromIterators(beginKey, endKey));
117 }
118
120 template<typename KEYITERATOR>
121 static SymbolicFactor::shared_ptr FromIteratorsShared(KEYITERATOR beginKey, KEYITERATOR endKey) {
122 SymbolicFactor::shared_ptr result = boost::make_shared<SymbolicFactor>();
123 result->keys_.assign(beginKey, endKey);
124 return result;
125 }
126
129 template<class CONTAINER>
130 static SymbolicFactor FromKeys(const CONTAINER& keys) {
131 return SymbolicFactor(Base::FromKeys(keys));
132 }
133
136 template<class CONTAINER>
137 static SymbolicFactor::shared_ptr FromKeysShared(const CONTAINER& keys) {
138 return FromIteratorsShared(keys.begin(), keys.end());
139 }
140
142
145
147 double error(const HybridValues& c) const override;
148
151 std::pair<boost::shared_ptr<SymbolicConditional>, boost::shared_ptr<SymbolicFactor> >
152 eliminate(const Ordering& keys) const;
153
155
156 private:
158 friend class boost::serialization::access;
159 template<class ARCHIVE>
160 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
161 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
162 }
163 }; // IndexFactor
164
165 // Forward declarations
166 class SymbolicFactorGraph;
167 class Ordering;
168
173 GTSAM_EXPORT std::pair<boost::shared_ptr<SymbolicConditional>, boost::shared_ptr<SymbolicFactor> >
174 EliminateSymbolic(const SymbolicFactorGraph& factors, const Ordering& keys);
175
177 template<>
178 struct traits<SymbolicFactor> : public Testable<SymbolicFactor> {
179 };
180
181} //\ namespace gtsam
182
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
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:86
std::pair< boost::shared_ptr< SymbolicConditional >, boost::shared_ptr< SymbolicFactor > > EliminateSymbolic(const SymbolicFactorGraph &factors, const Ordering &keys)
Dense elimination function for symbolic factors.
Definition SymbolicFactor.cpp:36
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
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
HybridValues represents a collection of DiscreteValues and VectorValues.
Definition HybridValues.h:38
Definition Factor.h:68
Definition Ordering.h:34
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:39
void print(const std::string &s="SymbolicFactor", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
Definition SymbolicFactor.h:96
SymbolicFactor(Key j1, Key j2, Key j3, Key j4, Key j5, Key j6)
Construct 6-way factor.
Definition SymbolicFactor.h:77
boost::shared_ptr< This > shared_ptr
Overriding the shared_ptr typedef.
Definition SymbolicFactor.h:48
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:130
SymbolicFactor(const Factor &factor)
Create symbolic version of any factor.
Definition SymbolicFactor.h:81
SymbolicFactor(Key j1, Key j2, Key j3, Key j4)
Construct 4-way factor.
Definition SymbolicFactor.h:69
SymbolicFactor(Key j1, Key j2)
Construct binary factor.
Definition SymbolicFactor.h:61
static SymbolicFactor FromIterators(KEYITERATOR beginKey, KEYITERATOR endKey)
Constructor from a collection of keys.
Definition SymbolicFactor.h:115
void printKeys(const std::string &s="SymbolicFactor", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print only keys
Definition SymbolicFactor.h:103
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:137
SymbolicFactor(Key j1, Key j2, Key j3)
Construct ternary factor.
Definition SymbolicFactor.h:65
SymbolicFactor(Key j)
Construct unary factor.
Definition SymbolicFactor.h:57
SymbolicFactor(Key j1, Key j2, Key j3, Key j4, Key j5)
Construct 5-way factor.
Definition SymbolicFactor.h:73
static SymbolicFactor::shared_ptr FromIteratorsShared(KEYITERATOR beginKey, KEYITERATOR endKey)
Constructor from a collection of keys.
Definition SymbolicFactor.h:121
SymbolicFactor()
Default constructor for I/O.
Definition SymbolicFactor.h:54
SymbolicFactor::shared_ptr clone() const
Copy this object as its actual derived type.
Definition SymbolicFactor.h:86
the error.