gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RegularHessianFactor.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 <boost/foreach.hpp>
23 #include <vector>
24 
25 namespace gtsam {
26 
27 template<size_t D>
29 
30 private:
31 
32  typedef Eigen::Matrix<double, D, D> MatrixDD; // camera hessian block
33  typedef Eigen::Matrix<double, D, 1> VectorD;
34 
35 public:
36 
41  RegularHessianFactor(const std::vector<Key>& js,
42  const std::vector<Matrix>& Gs, const std::vector<Vector>& gs, double f) :
43  HessianFactor(js, Gs, gs, f) {
44  }
45 
48  template<typename KEYS>
51  HessianFactor(keys, augmentedInformation) {
52  }
53 
55  void multiplyHessianAdd(double alpha, const VectorValues& x,
56  VectorValues& y) const {
58  }
59 
60  // Scratch space for multiplyHessianAdd
61  typedef Eigen::Matrix<double, D, 1> DVector;
62  mutable std::vector<DVector> y;
63 
64  void multiplyHessianAdd(double alpha, const double* x,
65  double* yvalues) const {
66  // Create a vector of temporary y values, corresponding to rows i
67  y.resize(size());
68  BOOST_FOREACH(DVector & yi, y)
69  yi.setZero();
70 
71  typedef Eigen::Map<DVector> DMap;
72  typedef Eigen::Map<const DVector> ConstDMap;
73 
74  // Accessing the VectorValues one by one is expensive
75  // So we will loop over columns to access x only once per column
76  // And fill the above temporary y values, to be added into yvalues after
77  DVector xj(D);
78  for (DenseIndex j = 0; j < (DenseIndex) size(); ++j) {
79  Key key = keys_[j];
80  const double* xj = x + key * D;
81  DenseIndex i = 0;
82  for (; i < j; ++i)
83  y[i] += info_(i, j).knownOffDiagonal() * ConstDMap(xj);
84  // blocks on the diagonal are only half
85  y[i] += info_(j, j).selfadjointView() * ConstDMap(xj);
86  // for below diagonal, we take transpose block from upper triangular part
87  for (i = j + 1; i < (DenseIndex) size(); ++i)
88  y[i] += info_(i, j).knownOffDiagonal() * ConstDMap(xj);
89  }
90 
91  // copy to yvalues
92  for (DenseIndex i = 0; i < (DenseIndex) size(); ++i) {
93  Key key = keys_[i];
94  DMap(yvalues + key * D) += alpha * y[i];
95  }
96  }
97 
98 };
99 
100 }
101 
A Gaussian factor using the canonical parameters (information form)
Definition: HessianFactor.h:131
FastVector< Key > keys_
The keys involved in this factor.
Definition: Factor.h:69
Contains the HessianFactor class, a general quadratic factor.
const FastVector< Key > & keys() const
Access the factor's involved variable keys.
Definition: Factor.h:115
void multiplyHessianAdd(double alpha, const double *x, double *yvalues) const
y += alpha * A'*A*x
Definition: RegularHessianFactor.h:64
Definition: RegularHessianFactor.h:28
RegularHessianFactor(const std::vector< Key > &js, const std::vector< Matrix > &Gs, const std::vector< Vector > &gs, double f)
Construct an n-way factor.
Definition: RegularHessianFactor.h:41
SymmetricBlockMatrix info_
The full augmented information matrix, s.t. the quadratic error is 0.5*[x -1]'H[x -1]...
Definition: HessianFactor.h:134
void multiplyHessianAdd(double alpha, const VectorValues &x, VectorValues &y) const
y += alpha * A'*A*x
Definition: RegularHessianFactor.h:55
void multiplyHessianAdd(double alpha, const VectorValues &x, VectorValues &y) const
y += alpha * A'*A*x
Definition: HessianFactor.cpp:514
size_t Key
Integer nonlinear key type.
Definition: types.h:59
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:74
size_t size() const
Definition: Factor.h:126
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:89
Definition: SymmetricBlockMatrix.h:40
RegularHessianFactor(const KEYS &keys, const SymmetricBlockMatrix &augmentedInformation)
Constructor with an arbitrary number of keys and with the augmented information matrix specified as a...
Definition: RegularHessianFactor.h:49
virtual Matrix augmentedInformation() const
Return the augmented information matrix represented by this GaussianFactor.
Definition: HessianFactor.cpp:338