gtsam  4.1.0
gtsam
LinearContainerFactor.h
Go to the documentation of this file.
1 
10 #pragma once
11 
13 
14 namespace gtsam {
15 
16  // Forward declarations
17  class JacobianFactor;
18  class HessianFactor;
19 
27 protected:
28 
30  boost::optional<Values> linearizationPoint_;
31 
34 
36  GTSAM_EXPORT LinearContainerFactor(const GaussianFactor::shared_ptr& factor, const boost::optional<Values>& linearizationPoint);
37 
38  // Some handy typedefs
39  typedef NonlinearFactor Base;
40  typedef LinearContainerFactor This;
41 
42 public:
43 
44  typedef boost::shared_ptr<This> shared_ptr;
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 
123  // casting syntactic sugar
124 
125  inline bool hasLinearizationPoint() const { return linearizationPoint_.is_initialized(); }
126 
130  GTSAM_EXPORT bool isJacobian() const;
131  GTSAM_EXPORT bool isHessian() const;
132 
134  GTSAM_EXPORT boost::shared_ptr<JacobianFactor> toJacobian() const;
135 
137  GTSAM_EXPORT boost::shared_ptr<HessianFactor> toHessian() const;
138 
143  GTSAM_EXPORT
144  static NonlinearFactorGraph ConvertLinearGraph(const GaussianFactorGraph& linear_graph,
145  const Values& linearizationPoint = Values());
146 
147  protected:
148  GTSAM_EXPORT void initializeLinearizationPoint(const Values& linearizationPoint);
149 
150  private:
153  template<class ARCHIVE>
154  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
155  ar & boost::serialization::make_nvp("NonlinearFactor",
156  boost::serialization::base_object<Base>(*this));
157  ar & BOOST_SERIALIZATION_NVP(factor_);
158  ar & BOOST_SERIALIZATION_NVP(linearizationPoint_);
159  }
160 
161 }; // \class LinearContainerFactor
162 
163 template<> struct traits<LinearContainerFactor> : public Testable<LinearContainerFactor> {};
164 
165 } // \namespace gtsam
166 
gtsam::GaussianFactor::shared_ptr
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactor.h:42
gtsam::LinearContainerFactor::negateToNonlinear
GTSAM_EXPORT NonlinearFactor::shared_ptr negateToNonlinear() const
Creates the equivalent anti-factor as another LinearContainerFactor.
Definition: LinearContainerFactor.cpp:162
gtsam::LinearContainerFactor::negateToGaussian
GTSAM_EXPORT GaussianFactor::shared_ptr negateToGaussian() const
Creates an anti-factor directly.
Definition: LinearContainerFactor.cpp:156
gtsam::LinearContainerFactor::isJacobian
GTSAM_EXPORT bool isJacobian() const
Simple checks whether this is a Jacobian or Hessian factor.
Definition: LinearContainerFactor.cpp:136
gtsam::LinearContainerFactor
Dummy version of a generic linear factor to be injected into a nonlinear factor graph.
Definition: LinearContainerFactor.h:26
gtsam::LinearContainerFactor::equals
GTSAM_EXPORT bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Check if two factors are equal.
Definition: LinearContainerFactor.cpp:65
gtsam::LinearContainerFactor::clone
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
gtsam::traits
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
gtsam::LinearContainerFactor::access
friend class boost::serialization::access
Serialization function.
Definition: LinearContainerFactor.h:152
gtsam::LinearContainerFactor::linearizationPoint
const boost::optional< Values > & linearizationPoint() const
Extract the linearization point used in recalculating error.
Definition: LinearContainerFactor.h:83
gtsam::LinearContainerFactor::error
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
gtsam::NonlinearFactor::NonlinearFactor
NonlinearFactor()
Default constructor for I/O only.
Definition: NonlinearFactor.h:59
NonlinearFactorGraph.h
Factor Graph Constsiting of non-linear factors.
gtsam
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
gtsam::LinearContainerFactor::dim
GTSAM_EXPORT size_t dim() const override
get the dimension of the factor: rows of linear factor
Definition: LinearContainerFactor.cpp:96
gtsam::Testable
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
gtsam::LinearContainerFactor::toJacobian
GTSAM_EXPORT boost::shared_ptr< JacobianFactor > toJacobian() const
Casts to JacobianFactor.
Definition: LinearContainerFactor.cpp:146
gtsam::NonlinearFactor
Nonlinear factor base class.
Definition: NonlinearFactor.h:43
gtsam::LinearContainerFactor::linearize
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
gtsam::JacobianFactor
A Gaussian factor in the squared-error form.
Definition: JacobianFactor.h:91
gtsam::LinearContainerFactor::toHessian
GTSAM_EXPORT boost::shared_ptr< HessianFactor > toHessian() const
Casts to HessianFactor.
Definition: LinearContainerFactor.cpp:151
gtsam::LinearContainerFactor::LinearContainerFactor
LinearContainerFactor()
Default constructor - necessary for serialization.
Definition: LinearContainerFactor.h:33
gtsam::HessianFactor
A Gaussian factor using the canonical parameters (information form)
Definition: HessianFactor.h:101
gtsam::KeyFormatter
boost::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
gtsam::Values
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:71
gtsam::LinearContainerFactor::print
GTSAM_EXPORT void print(const std::string &s="", const KeyFormatter &keyFormatter=gtsam::DefaultKeyFormatter) const override
print
Definition: LinearContainerFactor.cpp:56
gtsam::LinearContainerFactor::ConvertLinearGraph
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:168