gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JacobianSchurFactor.h
1 /*
2  * @file JacobianSchurFactor.h
3  * @brief Jacobianfactor that combines and eliminates points
4  * @date Oct 27, 2013
5  * @uthor Frank Dellaert
6  */
7 
8 #pragma once
9 
10 #include <gtsam/inference/Symbol.h>
15 #include <boost/foreach.hpp>
16 
17 namespace gtsam {
21 template<size_t D>
23 
24 public:
25 
26  typedef Eigen::Matrix<double, 2, D> Matrix2D;
27  typedef std::pair<Key, Matrix2D> KeyMatrix2D;
28 
29  // Use eigen magic to access raw memory
30  typedef Eigen::Matrix<double, D, 1> DVector;
31  typedef Eigen::Map<DVector> DMap;
32  typedef Eigen::Map<const DVector> ConstDMap;
33 
38  Vector operator*(const double* x) const {
39  Vector Ax = zero(Ab_.rows());
40  if (empty()) return Ax;
41 
42  // Just iterate over all A matrices and multiply in correct config part
43  for(size_t pos=0; pos<size(); ++pos)
44  Ax += Ab_(pos) * ConstDMap(x + D * keys_[pos]);
45 
46  return model_ ? model_->whiten(Ax) : Ax;
47  }
48 
53  void transposeMultiplyAdd(double alpha, const Vector& e, double* x) const
54  {
55  Vector E = alpha * (model_ ? model_->whiten(e) : e);
56  // Just iterate over all A matrices and insert Ai^e into y
57  for(size_t pos=0; pos<size(); ++pos)
58  DMap(x + D * keys_[pos]) += Ab_(pos).transpose() * E;
59  }
60 
62  void multiplyHessianAdd(double alpha, const VectorValues& x, VectorValues& y) const {
64  }
65 
70  void multiplyHessianAdd(double alpha, const double* x, double* y) const {
71 // Vector Ax = (*this)*x;
72 // this->transposeMultiplyAdd(alpha,Ax,y);
73  if (empty()) return;
74  Vector Ax = zero(Ab_.rows());
75 
76  // Just iterate over all A matrices and multiply in correct config part
77  for(size_t pos=0; pos<size(); ++pos)
78  Ax += Ab_(pos) * ConstDMap(x + D * keys_[pos]);
79 
80  // Deal with noise properly, need to Double* whiten as we are dividing by variance
81  if (model_) { model_->whitenInPlace(Ax); model_->whitenInPlace(Ax); }
82 
83  // multiply with alpha
84  Ax *= alpha;
85 
86  // Again iterate over all A matrices and insert Ai^e into y
87  for(size_t pos=0; pos<size(); ++pos)
88  DMap(y + D * keys_[pos]) += Ab_(pos).transpose() * Ax;
89  }
90 
91 }; // class
92 
93 } // gtsam
DenseIndex rows() const
Row size.
Definition: VerticalBlockMatrix.h:111
Vector operator*(const double *x) const
double* Matrix-vector multiply, i.e.
Definition: JacobianSchurFactor.h:38
void multiplyHessianAdd(double alpha, const VectorValues &x, VectorValues &y) const
y += alpha * A'*A*x
Definition: JacobianFactor.cpp:525
Chordal Bayes Net, the result of eliminating a factor graph.
FastVector< Key > keys_
The keys involved in this factor.
Definition: Factor.h:69
Factor Graph Values.
A Gaussian factor in the squared-error form.
Definition: JacobianFactor.h:82
void multiplyHessianAdd(double alpha, const VectorValues &x, VectorValues &y) const
y += alpha * A'*A*x
Definition: JacobianSchurFactor.h:62
void multiplyHessianAdd(double alpha, const double *x, double *y) const
double* Hessian-vector multiply, i.e.
Definition: JacobianSchurFactor.h:70
bool zero(const Vector &v)
check if all zero
Definition: Vector.cpp:39
void transposeMultiplyAdd(double alpha, const Vector &e, double *x) const
double* Transpose Matrix-vector multiply, i.e.
Definition: JacobianSchurFactor.h:53
size_t size() const
Definition: Factor.h:126
virtual bool empty() const
Check if the factor is empty.
Definition: JacobianFactor.h:228
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:89
JacobianFactor for Schur complement that uses Q noise model.
Definition: JacobianSchurFactor.h:22
Linear Factor Graph where all factors are Gaussians.