gtsam 4.1.1
gtsam
LinearContainerFactor.h
Go to the documentation of this file.
1
10#pragma once
11
13
14namespace gtsam {
15
16 // Forward declarations
17 class JacobianFactor;
18 class HessianFactor;
19
27protected:
28
30 boost::optional<Values> linearizationPoint_;
31
33 GTSAM_EXPORT LinearContainerFactor(const GaussianFactor::shared_ptr& factor, const boost::optional<Values>& linearizationPoint);
34
35 // Some handy typedefs
36 typedef NonlinearFactor Base;
38
39public:
40
41 typedef boost::shared_ptr<This> shared_ptr;
42
45
47 GTSAM_EXPORT LinearContainerFactor(const JacobianFactor& factor, const Values& linearizationPoint = Values());
48
50 GTSAM_EXPORT LinearContainerFactor(const HessianFactor& factor, const Values& linearizationPoint = Values());
51
54
55 // Access
56
57 const GaussianFactor::shared_ptr& factor() const { return factor_; }
58
59 // Testable
60
62 GTSAM_EXPORT void print(const std::string& s = "", const KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter) const override;
63
65 GTSAM_EXPORT bool equals(const NonlinearFactor& f, double tol = 1e-9) const override;
66
67 // NonlinearFactor
68
77 GTSAM_EXPORT double error(const Values& c) const override;
78
80 GTSAM_EXPORT size_t dim() const override;
81
83 const boost::optional<Values>& linearizationPoint() const { return linearizationPoint_; }
84
101 GTSAM_EXPORT GaussianFactor::shared_ptr linearize(const Values& c) const override;
102
106 GTSAM_EXPORT GaussianFactor::shared_ptr negateToGaussian() const;
107
111 GTSAM_EXPORT NonlinearFactor::shared_ptr negateToNonlinear() const;
112
119 NonlinearFactor::shared_ptr clone() const override {
120 return NonlinearFactor::shared_ptr(new LinearContainerFactor(factor_,linearizationPoint_));
121 }
122
128 NonlinearFactor::shared_ptr rekey(
129 const std::map<Key, Key>& rekey_mapping) const override;
130
135 NonlinearFactor::shared_ptr rekey(const KeyVector& new_keys) const override;
136
138 inline bool hasLinearizationPoint() const { return linearizationPoint_.is_initialized(); }
139
143 GTSAM_EXPORT bool isJacobian() const;
144 GTSAM_EXPORT bool isHessian() const;
145
147 GTSAM_EXPORT boost::shared_ptr<JacobianFactor> toJacobian() const;
148
150 GTSAM_EXPORT boost::shared_ptr<HessianFactor> toHessian() const;
151
156 GTSAM_EXPORT
158 const Values& linearizationPoint = Values());
159
160 protected:
161 GTSAM_EXPORT void initializeLinearizationPoint(const Values& linearizationPoint);
162
163 private:
166 template<class ARCHIVE>
167 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
168 ar & boost::serialization::make_nvp("NonlinearFactor",
169 boost::serialization::base_object<Base>(*this));
170 ar & BOOST_SERIALIZATION_NVP(factor_);
171 ar & BOOST_SERIALIZATION_NVP(linearizationPoint_);
172 }
173
174}; // \class LinearContainerFactor
175
176template<> struct traits<LinearContainerFactor> : public Testable<LinearContainerFactor> {};
177
178} // \namespace gtsam
179
Factor Graph consisting of non-linear 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::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
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:151
This is the base class for all factor types.
Definition: Factor.h:56
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactor.h:42
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition: GaussianFactorGraph.h:69
A Gaussian factor using the canonical parameters (information form)
Definition: HessianFactor.h:101
A Gaussian factor in the squared-error form.
Definition: JacobianFactor.h:91
Dummy version of a generic linear factor to be injected into a nonlinear factor graph.
Definition: LinearContainerFactor.h:26
GTSAM_EXPORT boost::shared_ptr< HessianFactor > toHessian() const
Casts to HessianFactor.
Definition: LinearContainerFactor.cpp:151
NonlinearFactor::shared_ptr clone() const override
Creates a shared_ptr clone of the factor - needs to be specialized to allow for subclasses.
Definition: LinearContainerFactor.h:119
LinearContainerFactor()
Default constructor - necessary for serialization.
Definition: LinearContainerFactor.h:44
GTSAM_EXPORT size_t dim() const override
get the dimension of the factor: rows of linear factor
Definition: LinearContainerFactor.cpp:96
const boost::optional< Values > & linearizationPoint() const
Extract the linearization point used in recalculating error.
Definition: LinearContainerFactor.h:83
NonlinearFactor::shared_ptr rekey(const std::map< Key, Key > &rekey_mapping) const override
Creates a shared_ptr clone of the factor with different keys using a map from old->new keys.
Definition: LinearContainerFactor.cpp:168
GTSAM_EXPORT void print(const std::string &s="", const KeyFormatter &keyFormatter=gtsam::DefaultKeyFormatter) const override
print
Definition: LinearContainerFactor.cpp:56
GTSAM_EXPORT GaussianFactor::shared_ptr negateToGaussian() const
Creates an anti-factor directly.
Definition: LinearContainerFactor.cpp:156
GTSAM_EXPORT boost::shared_ptr< JacobianFactor > toJacobian() const
Casts to JacobianFactor.
Definition: LinearContainerFactor.cpp:146
GTSAM_EXPORT bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Check if two factors are equal.
Definition: LinearContainerFactor.cpp:65
bool hasLinearizationPoint() const
Casting syntactic sugar.
Definition: LinearContainerFactor.h:138
GTSAM_EXPORT bool isJacobian() const
Simple checks whether this is a Jacobian or Hessian factor.
Definition: LinearContainerFactor.cpp:136
GTSAM_EXPORT NonlinearFactor::shared_ptr negateToNonlinear() const
Creates the equivalent anti-factor as another LinearContainerFactor.
Definition: LinearContainerFactor.cpp:162
GTSAM_EXPORT GaussianFactor::shared_ptr linearize(const Values &c) const override
Linearize to a GaussianFactor, with method depending on the presence of a linearizationPoint.
Definition: LinearContainerFactor.cpp:104
friend class boost::serialization::access
Serialization function.
Definition: LinearContainerFactor.h:165
GTSAM_EXPORT double error(const Values &c) const override
Calculate the nonlinear error for the factor, where the error is computed by passing the delta betwee...
Definition: LinearContainerFactor.cpp:77
static GTSAM_EXPORT NonlinearFactorGraph ConvertLinearGraph(const GaussianFactorGraph &linear_graph, const Values &linearizationPoint=Values())
Utility function for converting linear graphs to nonlinear graphs consisting of LinearContainerFactor...
Definition: LinearContainerFactor.cpp:210
Nonlinear factor base class.
Definition: NonlinearFactor.h:43
NonlinearFactor()
Default constructor for I/O only.
Definition: NonlinearFactor.h:59
A non-linear factor graph is a graph of non-Gaussian, i.e.
Definition: NonlinearFactorGraph.h:78
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:63