gtsam/gtsam/slam/JacobianFactorQ.h

82 lines
2.4 KiB
C
Raw Normal View History

/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
/*
* @file JacobianFactorQ.h
* @date Oct 27, 2013
* @uthor Frank Dellaert
*/
#pragma once
#include <gtsam/linear/RegularJacobianFactor.h>
namespace gtsam {
/**
* JacobianFactor for Schur complement that uses Q noise model
*/
template<size_t D, size_t ZDim>
2015-02-22 15:10:58 +08:00
class JacobianFactorQ: public RegularJacobianFactor<D> {
2015-02-22 15:10:58 +08:00
typedef RegularJacobianFactor<D> Base;
typedef Eigen::Matrix<double, ZDim, D> MatrixZD;
2015-03-05 13:39:35 +08:00
typedef std::pair<Key, Matrix> KeyMatrix;
public:
/// Default constructor
JacobianFactorQ() {
}
/// Empty constructor with keys
2015-02-22 13:32:55 +08:00
JacobianFactorQ(const FastVector<Key>& keys, //
const SharedDiagonal& model = SharedDiagonal()) :
Base() {
2015-02-22 13:32:55 +08:00
Matrix zeroMatrix = Matrix::Zero(0, D);
Vector zeroVector = Vector::Zero(0);
std::vector<KeyMatrix> QF;
QF.reserve(keys.size());
BOOST_FOREACH(const Key& key, keys)
2015-02-22 13:32:55 +08:00
QF.push_back(KeyMatrix(key, zeroMatrix));
JacobianFactor::fillTerms(QF, zeroVector, model);
}
/// Constructor
2015-03-05 13:39:35 +08:00
JacobianFactorQ(const FastVector<Key>& keys,
const std::vector<MatrixZD>& FBlocks, const Matrix& E, const Matrix3& P,
const Vector& b, const SharedDiagonal& model = SharedDiagonal()) :
Base() {
size_t j = 0, m2 = E.rows(), m = m2 / ZDim;
// Calculate projector Q
Matrix Q = eye(m2) - E * P * E.transpose();
// Calculate pre-computed Jacobian matrices
// TODO: can we do better ?
2015-02-22 13:32:55 +08:00
std::vector<KeyMatrix> QF;
QF.reserve(m);
// Below, we compute each mZDim*D block A_j = Q_j * F_j = (mZDim*ZDim) * (Zdim*D)
2015-03-05 13:39:35 +08:00
for (size_t k = 0; k < FBlocks.size(); ++k) {
Key key = keys[k];
2015-02-22 13:32:55 +08:00
QF.push_back(
2015-03-07 00:48:35 +08:00
KeyMatrix(key, - Q.block(0, ZDim * j++, m2, ZDim) * FBlocks[k]));
2015-03-05 13:39:35 +08:00
}
// Which is then passed to the normal JacobianFactor constructor
JacobianFactor::fillTerms(QF, - Q * b, model);
}
};
2015-02-22 13:32:55 +08:00
// end class JacobianFactorQ
// traits
template<size_t D, size_t ZDim> struct traits<JacobianFactorQ<D, ZDim> > : public Testable<
JacobianFactorQ<D, ZDim> > {
};
}