gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JacobianFactorQ.h
1 /*
2  * @file JacobianFactorQ.h
3  * @date Oct 27, 2013
4  * @uthor Frank Dellaert
5  */
6 
7 #pragma once
8 
9 #include "JacobianSchurFactor.h"
10 
11 namespace gtsam {
15 template<size_t D>
17 
19 
20 public:
21 
24  }
25 
28  const SharedDiagonal& model = SharedDiagonal()) : JacobianSchurFactor<D>() {
29  Matrix zeroMatrix = Matrix::Zero(0,D);
30  Vector zeroVector = Vector::Zero(0);
31  typedef std::pair<Key, Matrix> KeyMatrix;
32  std::vector<KeyMatrix> QF;
33  QF.reserve(keys.size());
34  BOOST_FOREACH(const Key& key, keys)
35  QF.push_back(KeyMatrix(key, zeroMatrix));
36  JacobianFactor::fillTerms(QF, zeroVector, model);
37  }
38 
40  JacobianFactorQ(const std::vector<typename Base::KeyMatrix2D>& Fblocks,
41  const Matrix& E, const Matrix3& P, const Vector& b,
42  const SharedDiagonal& model = SharedDiagonal()) :
43  JacobianSchurFactor<D>() {
44  size_t j = 0, m2 = E.rows(), m = m2 / 2;
45  // Calculate projector Q
46  Matrix Q = eye(m2) - E * P * E.transpose();
47  // Calculate pre-computed Jacobian matrices
48  // TODO: can we do better ?
49  typedef std::pair<Key, Matrix> KeyMatrix;
50  std::vector < KeyMatrix > QF;
51  QF.reserve(m);
52  // Below, we compute each 2m*D block A_j = Q_j * F_j = (2m*2) * (2*D)
53  BOOST_FOREACH(const typename Base::KeyMatrix2D& it, Fblocks)
54  QF.push_back(KeyMatrix(it.first, Q.block(0, 2 * j++, m2, 2) * it.second));
55  // Which is then passed to the normal JacobianFactor constructor
56  JacobianFactor::fillTerms(QF, Q * b, model);
57  }
58 };
59 
60 }
JacobianFactor for Schur complement that uses Q noise model.
Definition: JacobianFactorQ.h:16
Matrix eye(size_t m, size_t n)
Creates an identity matrix, with matlab-like syntax.
Definition: Matrix.cpp:50
const FastVector< Key > & keys() const
Access the factor's involved variable keys.
Definition: Factor.h:115
This is the base class for all factor types.
Definition: Factor.h:51
void fillTerms(const TERMS &terms, const Vector &b, const SharedDiagonal &noiseModel)
Internal function to fill blocks and set dimensions.
Definition: JacobianFactor-inl.h:60
JacobianFactorQ(const std::vector< typename Base::KeyMatrix2D > &Fblocks, const Matrix &E, const Matrix3 &P, const Vector &b, const SharedDiagonal &model=SharedDiagonal())
Constructor.
Definition: JacobianFactorQ.h:40
JacobianFactorQ()
Default constructor.
Definition: JacobianFactorQ.h:23
JacobianFactorQ(const FastVector< Key > &keys, const SharedDiagonal &model=SharedDiagonal())
Empty constructor with keys.
Definition: JacobianFactorQ.h:27
size_t Key
Integer nonlinear key type.
Definition: types.h:59
JacobianFactor for Schur complement that uses Q noise model.
Definition: JacobianSchurFactor.h:22