HessianFactor.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 
19 #pragma once
20 
22 #include <gtsam/linear/Scatter.h>
24 #include <gtsam/base/FastVector.h>
25 
26 
27 namespace gtsam {
28 
29  // Forward declarations
30  class Ordering;
31  class JacobianFactor;
32  class HessianFactor;
33  class GaussianConditional;
34  class GaussianBayesNet;
35  class GaussianFactorGraph;
36 
100  class GTSAM_EXPORT HessianFactor : public GaussianFactor {
101  protected:
102 
104 
105  public:
106 
108  typedef HessianFactor This;
109  typedef std::shared_ptr<This> shared_ptr;
112 
113 
115  HessianFactor();
116 
122  HessianFactor(Key j, const Matrix& G, const Vector& g, double f);
123 
127  HessianFactor(Key j, const Vector& mu, const Matrix& Sigma);
128 
144  HessianFactor(Key j1, Key j2,
145  const Matrix& G11, const Matrix& G12, const Vector& g1,
146  const Matrix& G22, const Vector& g2, double f);
147 
152  HessianFactor(Key j1, Key j2, Key j3,
153  const Matrix& G11, const Matrix& G12, const Matrix& G13, const Vector& g1,
154  const Matrix& G22, const Matrix& G23, const Vector& g2,
155  const Matrix& G33, const Vector& g3, double f);
156 
161  HessianFactor(const KeyVector& js, const std::vector<Matrix>& Gs,
162  const std::vector<Vector>& gs, double f);
163 
166  template<typename KEYS>
167  HessianFactor(const KEYS& keys, const SymmetricBlockMatrix& augmentedInformation);
168 
170  explicit HessianFactor(const JacobianFactor& cg);
171 
174  explicit HessianFactor(const GaussianFactor& factor);
175 
177  explicit HessianFactor(const GaussianFactorGraph& factors,
178  const Scatter& scatter);
179 
182  : HessianFactor(factors, Scatter(factors)) {}
183 
185  ~HessianFactor() override {}
186 
189  return std::make_shared<HessianFactor>(*this); }
190 
192  void print(const std::string& s = "",
193  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
194 
196  bool equals(const GaussianFactor& lf, double tol = 1e-9) const override;
197 
199  using GaussianFactor::error;
200 
205  double error(const VectorValues& c) const override;
206 
212  DenseIndex getDim(const_iterator variable) const override {
213  return info_.getDim(std::distance(begin(), variable));
214  }
215 
217  size_t rows() const { return info_.rows(); }
218 
224  GaussianFactor::shared_ptr negate() const override;
225 
229  double constantTerm() const {
230  const auto view = info_.diagonalBlock(size());
231  return view(0, 0);
232  }
233 
237  double& constantTerm() { return info_.diagonalBlock(size())(0, 0); }
238 
244  assert(!empty());
245  return info_.aboveDiagonalBlock(j - begin(), size());
246  }
247 
251  assert(!empty());
252  // get the last column (except the bottom right block)
253  return info_.aboveDiagonalRange(0, size(), size(), size() + 1);
254  }
255 
259  assert(!empty());
260  return info_.aboveDiagonalRange(0, size(), size(), size() + 1);
261  }
262 
264  const SymmetricBlockMatrix& info() const { return info_; }
265 
268  SymmetricBlockMatrix& info() { return info_; }
269 
285  Matrix augmentedInformation() const override;
286 
289 
293  Matrix information() const override;
294 
296  void hessianDiagonalAdd(VectorValues& d) const override;
297 
299  using Base::hessianDiagonal;
300 
302  void hessianDiagonal(double* d) const override;
303 
305  std::map<Key,Matrix> hessianBlockDiagonal() const override;
306 
308  std::pair<Matrix, Vector> jacobian() const override;
309 
315  Matrix augmentedJacobian() const override;
316 
322  void updateHessian(const KeyVector& keys, SymmetricBlockMatrix* info) const override;
323 
328  assert(other);
329  updateHessian(other->keys_, &other->info_);
330  }
331 
333  void multiplyHessianAdd(double alpha, const VectorValues& x, VectorValues& y) const override;
334 
336  VectorValues gradientAtZero() const override;
337 
339  void gradientAtZero(double* d) const override;
340 
345  Vector gradient(Key key, const VectorValues& x) const override;
346 
351  std::shared_ptr<GaussianConditional> eliminateCholesky(const Ordering& keys);
352 
354  VectorValues solve();
355 
356  private:
358  void Allocate(const Scatter& scatter);
359 
361  HessianFactor(const Scatter& scatter);
362 
363  friend class NonlinearFactorGraph;
364  friend class NonlinearClusterTree;
365 
366 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
367 
368  friend class boost::serialization::access;
369  template<class ARCHIVE>
370  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
371  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(GaussianFactor);
372  ar & BOOST_SERIALIZATION_NVP(info_);
373  }
374 #endif
375  };
376 
393 GTSAM_EXPORT std::pair<std::shared_ptr<GaussianConditional>, std::shared_ptr<HessianFactor> >
395 
411 GTSAM_EXPORT std::pair<std::shared_ptr<GaussianConditional>, std::shared_ptr<GaussianFactor> >
413 
415 template<>
416 struct traits<HessianFactor> : public Testable<HessianFactor> {};
417 
418 } // \ namespace gtsam
419 
420 
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
const gtsam::Symbol key('X', 0)
Scalar * y
Access to matrices via blocks of pre-defined sizes. Used in GaussianFactor and GaussianConditional.
std::shared_ptr< This > shared_ptr
A shared_ptr to this class.
std::string serialize(const T &input)
serializes to a string
SymmetricBlockMatrix & info()
JacobiRotation< float > G
constBlock aboveDiagonalRange(DenseIndex i_startBlock, DenseIndex i_endBlock, DenseIndex j_startBlock, DenseIndex j_endBlock) const
Get a range [i,j) from the matrix. Indices are in block units.
double mu
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
A factor with a quadratic error function - a Gaussian.
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set view
GaussianFactor::shared_ptr clone() const override
GaussianFactor Base
Typedef to base class.
const GaussianFactorGraph factors
Double_ distance(const OrientedPlane3_ &p)
std::pair< std::shared_ptr< GaussianConditional >, std::shared_ptr< GaussianFactor > > EliminatePreferCholesky(const GaussianFactorGraph &factors, const Ordering &keys)
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:87
SymmetricBlockMatrix::constBlock constBlock
A block from the Hessian matrix (const version)
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:108
void g(const string &key, int i)
Definition: testBTree.cpp:41
const KeyFormatter & formatter
HessianFactor This
Typedef to this class.
else if n * info
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
size_t rows() const
DenseIndex rows() const
Row size.
~HessianFactor() override
Eigen::VectorXd Vector
Definition: Vector.h:38
std::pair< std::shared_ptr< GaussianConditional >, std::shared_ptr< HessianFactor > > EliminateCholesky(const GaussianFactorGraph &factors, const Ordering &keys)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
RealScalar alpha
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
Expression of a selfadjoint matrix from a triangular part of a dense matrix.
double constantTerm() const
SymmetricBlockMatrix::constBlock linearTerm() const
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
SymmetricBlockMatrix::Block Block
A block from the Hessian matrix.
SymmetricBlockMatrix info_
The full augmented information matrix, s.t. the quadratic error is 0.5*[x -1]&#39;H[x -1]...
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Maps global variable indices to slot indices.
A thin wrapper around std::vector that uses a custom allocator.
traits
Definition: chartTesting.h:28
SymmetricBlockMatrix::constBlock linearTerm(const_iterator j) const
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
SymmetricBlockMatrix::Block linearTerm()
Pose3 g1(Rot3(), Point3(100.0, 0.0, 300.0))
A Gaussian factor using the canonical parameters (information form)
DenseIndex getDim(const_iterator variable) const override
static double error
Definition: testRot3.cpp:37
void updateHessian(HessianFactor *other) const
Contains the HessianFactor class, a general quadratic factor.
const G double tol
Definition: Group.h:86
Eigen::SelfAdjointView< Block, Eigen::Upper > diagonalBlock(DenseIndex J)
Return the J&#39;th diagonal block as a self adjoint view.
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition: Factor.h:82
const KeyVector keys
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
DenseIndex getDim(DenseIndex block) const
Number of dimensions for variable on this diagonal block.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Pose3 g2(g1.expmap(h *V1_g1))
HessianFactor(const GaussianFactorGraph &factors)
const SymmetricBlockMatrix & info() const
Return underlying information matrix.
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
constBlock aboveDiagonalBlock(DenseIndex I, DenseIndex J) const
Get block above the diagonal (I, J).
std::ptrdiff_t j
virtual double error(const VectorValues &c) const


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:19