gtsam  4.0.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 
26 class GTSAM_EXPORT LinearContainerFactor : public NonlinearFactor {
27 protected:
28 
30  boost::optional<Values> linearizationPoint_;
31 
34 
36  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  LinearContainerFactor(const JacobianFactor& factor, const Values& linearizationPoint = Values());
48 
50  LinearContainerFactor(const HessianFactor& factor, const Values& linearizationPoint = Values());
51 
53  LinearContainerFactor(const GaussianFactor::shared_ptr& factor, const Values& linearizationPoint = Values());
54 
55  // Access
56 
57  const GaussianFactor::shared_ptr& factor() const { return factor_; }
58 
59  // Testable
60 
62  void print(const std::string& s = "", const KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter) const;
63 
65  bool equals(const NonlinearFactor& f, double tol = 1e-9) const;
66 
67  // NonlinearFactor
68 
77  double error(const Values& c) const;
78 
80  size_t dim() const;
81 
83  const boost::optional<Values>& linearizationPoint() const { return linearizationPoint_; }
84 
101  GaussianFactor::shared_ptr linearize(const Values& c) const;
102 
106  GaussianFactor::shared_ptr negateToGaussian() const;
107 
111  NonlinearFactor::shared_ptr negateToNonlinear() const;
112 
119  NonlinearFactor::shared_ptr clone() const {
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  bool isJacobian() const;
131  bool isHessian() const;
132 
134  boost::shared_ptr<JacobianFactor> toJacobian() const;
135 
137  boost::shared_ptr<HessianFactor> toHessian() const;
138 
143  static NonlinearFactorGraph ConvertLinearGraph(const GaussianFactorGraph& linear_graph,
144  const Values& linearizationPoint = Values());
145 
146 #ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V4
147  static NonlinearFactorGraph convertLinearGraph(const GaussianFactorGraph& linear_graph,
148  const Values& linearizationPoint = Values()) {
149  return ConvertLinearGraph(linear_graph, linearizationPoint);
150  }
151 #endif
152 
153 protected:
154  void initializeLinearizationPoint(const Values& linearizationPoint);
155 
156 private:
157 
159  friend class boost::serialization::access;
160  template<class ARCHIVE>
161  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
162  ar & boost::serialization::make_nvp("NonlinearFactor",
163  boost::serialization::base_object<Base>(*this));
164  ar & BOOST_SERIALIZATION_NVP(factor_);
165  ar & BOOST_SERIALIZATION_NVP(linearizationPoint_);
166  }
167 
168 }; // \class LinearContainerFactor
169 
170 template<> struct traits<LinearContainerFactor> : public Testable<LinearContainerFactor> {};
171 
172 } // \namespace gtsam
173 
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
Dummy version of a generic linear factor to be injected into a nonlinear factor graph.
Definition: LinearContainerFactor.h:26
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
const boost::optional< Values > & linearizationPoint() const
Extract the linearization point used in recalculating error.
Definition: LinearContainerFactor.h:83
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:33
Factor Graph Constsiting of non-linear factors.
Nonlinear factor base class.
Definition: NonlinearFactor.h:50
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 Gaussian factor in the squared-error form.
Definition: JacobianFactor.h:87
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
NonlinearFactor::shared_ptr clone() const
Creates a shared_ptr clone of the factor - needs to be specialized to allow for subclasses.
Definition: LinearContainerFactor.h:119
A Gaussian factor using the canonical parameters (information form)
Definition: HessianFactor.h:101
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactor.h:42
LinearContainerFactor()
Default constructor - necessary for serialization.
Definition: LinearContainerFactor.h:33