61 typedef Eigen::Matrix<double, D, 1> VectorD;
62 typedef Eigen::Matrix<double, D, D> MatrixD;
74 const std::vector<Matrix>& Gs,
const std::vector<Vector>& gs,
double f) :
84 const VectorD& g1,
const MatrixD& G22,
const VectorD& g2,
double f) :
93 const MatrixD& G11,
const MatrixD& G12,
const MatrixD& G13,
const VectorD& g1,
94 const MatrixD& G22,
const MatrixD& G23,
const VectorD& g2,
95 const MatrixD& G33,
const VectorD& g3,
double f) :
96 HessianFactor(j1, j2, j3, G11, G12, G13, g1, G22, G23, g2, G33, g3, f) {
107 template<
typename KEYS>
157 void checkInvariants()
const {
160 throw std::invalid_argument(
161 "RegularHessianFactor constructor was given non-regular factors or "
162 "incorrect template dimension D");
166 typedef Eigen::Map<VectorD> DMap;
167 typedef Eigen::Map<const VectorD> ConstDMap;
172 mutable std::vector<VectorD, Eigen::aligned_allocator<VectorD>> y_;
175 template <
class OffsetPolicy>
176 void multiplyHessianAddImpl(
double alpha,
const double* x,
double* yvalues,
177 const OffsetPolicy& offset)
const {
178 const size_t n =
size();
179 if (y_.size() != n) y_.resize(n);
180 for (VectorD& yi : y_) yi.setZero();
182 for (
DenseIndex j = 0; j < static_cast<DenseIndex>(n); ++j) {
183 ConstDMap xj(x + offset(
keys_[j]));
188 y_[i] +=
info_.diagonalBlock(j) * xj;
189 for (i = j + 1; i < static_cast<DenseIndex>(n); ++i) {
190 y_[i] +=
info_.aboveDiagonalBlock(j, i).transpose() * xj;
194 for (
DenseIndex i = 0; i < static_cast<DenseIndex>(n); ++i) {
195 DMap(yvalues + offset(
keys_[i])) += alpha * y_[i];
228 double* yvalues)
const {
229 multiplyHessianAddImpl(alpha, x, yvalues,
230 [](
Key key) {
return key * D; });
246 const std::vector<size_t>& offsets)
const {
247 const auto offset = [&offsets](
Key key) {
248 if (offsets.size() < 2 || key >= offsets.size() - 1 ||
249 offsets[key + 1] - offsets[key] != D) {
250 throw std::runtime_error(
251 "RegularHessianFactor::multiplyHessianAdd: Mismatched "
252 "dimension in offset map.");
256 multiplyHessianAddImpl(alpha, x, yvalues, offset);
268 const size_t n =
size();
269 for (
DenseIndex pos = 0; pos < static_cast<DenseIndex>(n); ++pos) {
272 DMap(d + D * j) +=
info_.diagonal(pos);
287 const size_t n =
size();
288 for (
DenseIndex pos = 0; pos < static_cast<DenseIndex>(n); ++pos) {
291 DMap(d + D * j) +=
info_.aboveDiagonalBlock(pos, n);
301 RegularHessianFactor<D> > {
Contains the HessianFactor class, a general quadratic factor.
JacobianFactor class with fixed sized blcoks.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition types.h:49
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
This class stores a dense matrix and allows it to be accessed as a collection of blocks.
Definition SymmetricBlockMatrix.h:80
DenseIndex cols() const
Column size.
Definition SymmetricBlockMatrix.h:159
constBlock aboveDiagonalBlock(DenseIndex I, DenseIndex J) const
Get block above the diagonal (I, J).
Definition SymmetricBlockMatrix.h:205
DenseIndex nBlocks() const
Block count.
Definition SymmetricBlockMatrix.h:162
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:143
KeyVector keys_
The keys involved in this factor.
Definition Factor.h:88
size_t size() const
Definition Factor.h:160
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition GaussianFactorGraph.h:77
Matrix augmentedInformation() const override
Return the augmented information matrix represented by this GaussianFactor.
Definition HessianFactor.cpp:338
SymmetricBlockMatrix info_
The full augmented information matrix, s.t. the quadratic error is 0.5*[x -1]'H[x -1].
Definition HessianFactor.h:104
void multiplyHessianAdd(double alpha, const VectorValues &x, VectorValues &y) const override
y += alpha * A'*A*x
Definition HessianFactor.cpp:487
HessianFactor()
default constructor for I/O
Definition HessianFactor.cpp:75
A HessianFactor where all variables have the same dimension D.
Definition RegularHessianFactor.h:57
RegularHessianFactor(const GaussianFactorGraph &factors)
Construct from a GaussianFactorGraph.
Definition RegularHessianFactor.h:143
void multiplyHessianAdd(double alpha, const VectorValues &x, VectorValues &y) const override
Multiply the Hessian part of the factor times a VectorValues x and add the result to y.
Definition RegularHessianFactor.h:208
RegularHessianFactor(Key j1, Key j2, Key j3, const MatrixD &G11, const MatrixD &G12, const MatrixD &G13, const VectorD &g1, const MatrixD &G22, const MatrixD &G23, const VectorD &g2, const MatrixD &G33, const VectorD &g3, double f)
Construct a ternary factor.
Definition RegularHessianFactor.h:92
void multiplyHessianAdd(double alpha, const double *x, double *yvalues, const std::vector< size_t > &offsets) const
Multiply the Hessian part of the factor times a raw vector x and add the result to y.
Definition RegularHessianFactor.h:245
void multiplyHessianAdd(double alpha, const double *x, double *yvalues) const
Multiply the Hessian part of the factor times a raw vector x and add the result to y.
Definition RegularHessianFactor.h:227
void hessianDiagonal(double *d) const override
Return the diagonal of the Hessian for this factor (Raw memory version).
Definition RegularHessianFactor.h:266
RegularHessianFactor(const KEYS &keys, const SymmetricBlockMatrix &augmentedInformation)
Constructor with an arbitrary number of keys and the augmented information matrix specified as a bloc...
Definition RegularHessianFactor.h:108
void gradientAtZero(double *d) const override
Add the gradient vector (gradient at zero) to a raw memory block d.
Definition RegularHessianFactor.h:284
RegularHessianFactor(const GaussianFactorGraph &factors, const Scatter &scatter)
Construct from a GaussianFactorGraph combined using a Scatter.
Definition RegularHessianFactor.h:131
RegularHessianFactor(const KeyVector &js, const std::vector< Matrix > &Gs, const std::vector< Vector > &gs, double f)
Construct an n-way factor from supplied components.
Definition RegularHessianFactor.h:73
RegularHessianFactor(Key j1, Key j2, const MatrixD &G11, const MatrixD &G12, const VectorD &g1, const MatrixD &G22, const VectorD &g2, double f)
Construct a binary factor.
Definition RegularHessianFactor.h:83
RegularHessianFactor(const RegularJacobianFactor< D > &jf)
Construct a RegularHessianFactor from a RegularJacobianFactor.
Definition RegularHessianFactor.h:120
JacobianFactor with constant sized blocks Provides raw memory access versions of linear operator.
Definition RegularJacobianFactor.h:32
Scatter is an intermediate data structure used when building a HessianFactor incrementally,...
Definition Scatter.h:49
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:73