gtsam
Loading...
Searching...
No Matches
gtsam::BatchJacobianFactor< ErrorDim, BlockDims > Class Template Reference

Detailed Description

template<int ErrorDim, int... BlockDims>
class gtsam::BatchJacobianFactor< ErrorDim, BlockDims >

Fixed-dimension row-sparse batch Jacobian factor.

This factor stores many small Jacobian row groups in compact form. A row group corresponds to one original nonlinear factor and has ErrorDim scalar rows. For each row group we store:

  • the local key slot used by each factor variable,
  • one fixed-size Jacobian block for each factor variable, and
  • one fixed-size right-hand side vector.

The factor's key list is the union of all keys appearing in the batch. Unlike a dense JacobianFactor, a row group only stores blocks for the keys touched by that original factor. For example, point-first SFM batches avoid storing zero camera blocks for cameras that did not observe the point.

The template parameters require fixed dimensions so the hot loops can use Eigen fixed-size products. Dynamic-dimension factors should use the ordinary JacobianFactor fallback in BatchFactor.

Noise-model convention: if model_ is null or unit, blocks and right-hand sides are treated as already whitened. If model_ is a non-unit diagonal model, updateHessian() applies the per-row diagonal weights directly. Constrained models are intentionally rejected by updateHessian(), matching JacobianFactor's Hessian assembly behavior.

Inheritance diagram for gtsam::BatchJacobianFactor< ErrorDim, BlockDims >:

Public Member Functions

 BatchJacobianFactor (const KeyVector &keys, std::vector< size_t > keyDims, const SharedDiagonal &model=SharedDiagonal())
 Construct an empty compact batch factor with known key dimensions.
GaussianFactor::shared_ptr clone () const override
 Return a deep copy as a GaussianFactor.
void reserve (size_t rowCount)
 Reserve storage for row groups before repeated addRow() calls.
void addRow (const SlotIndices &slots, const std::vector< Matrix > &blocks, const Vector &rhs)
 Add one row group corresponding to one original nonlinear factor.
void addUnaryRow (DenseIndex keySlot, const typename std::tuple_element< 0, Blocks >::type::value_type &block, const RhsVector &rhs)
 Add one row to a unary compact batch without dynamic block containers.
size_t rows () const override
 Return the number of scalar rows represented by all row groups.
const SharedDiagonal & get_model () const override
 Return the optional diagonal model on the stored rows.
DenseIndex getDim (const_iterator variable) const override
 Return the dimension of the variable at the given key iterator.
const std::vector< SlotIndices > & rowSlots () const
 Return the compact key slot used by each row group and factor slot.
template<size_t Slot>
const std::tuple_element< Slot, Blocks >::type::value_type & block (size_t rowIndex) const
 Return one fixed-size Jacobian block from a compact row group.
const RhsVector & rowRhs (size_t rowIndex) const
 Return the right-hand side for one compact row group.
double deltaError (const VectorValues &values, double *oldError=nullptr, double *newError=nullptr) const override
 Evaluate the linear-model error change directly from compact rows.
void hessianDiagonalAdd (VectorValues &diagonal) const override
 Accumulate the Hessian scalar diagonal directly from compact rows.
void multiplyHessianAdd (double alpha, const std::vector< size_t > &scalarOffsets, const double *x, double *y) const override
 Add alpha*A.transpose()*W*A*x directly to a flat output vector.
void gradientAtZeroAdd (const std::vector< size_t > &scalarOffsets, double *gradient) const override
 Add -A.transpose()*W*b directly to a flat gradient vector.
void hessianBlockDiagonalAdd (const std::vector< size_t > &blockSlots, std::vector< Matrix > *diagonalBlocks) const override
 Add compact A.transpose()*W*A diagonal blocks without keyed maps.
JacobianFactor toJacobianFactor () const override
 Convert compact row-block storage into a conventional JacobianFactor.
void updateHessian (const KeyVector &infoKeys, SymmetricBlockMatrix *info) const override
 Add this factor's augmented information matrix to info.
void updateHessian (const KeyVector &infoKeys, SymmetricBlockMatrix *info, DenseIndex beginCol, DenseIndex endCol) const override
 Add this factor's augmented information matrix over a block-column range.
Public Member Functions inherited from gtsam::BatchJacobianFactorBase
void print (const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override
 Print this compact factor by converting to a JacobianFactor.
bool equals (const GaussianFactor &factor, double tol=1e-9) const override
 Test equality by comparing dense JacobianFactor representations.
double error (const VectorValues &values) const override
 Compute the factor error by delegating to the dense compatibility factor.
double deltaError (const VectorValues &values, double *oldError=nullptr, double *newError=nullptr) const override
 Compute the error change by delegating to the dense compatibility factor.
Matrix augmentedJacobian () const override
 Return the dense augmented Jacobian matrix for compatibility callers.
std::pair< Matrix, Vector > jacobian () const override
 Return the dense Jacobian matrix and right-hand side vector.
Matrix augmentedInformation () const override
 Return the dense augmented information matrix for compatibility callers.
Matrix information () const override
 Return the dense information matrix for compatibility callers.
void hessianDiagonalAdd (VectorValues &diagonal) const override
 Add this factor's Hessian diagonal into the given VectorValues.
void hessianDiagonal (double *diagonal) const override
 Add this factor's Hessian diagonal into a raw scalar buffer.
std::map< Key, Matrix > hessianBlockDiagonal () const override
 Return the Hessian diagonal blocks keyed by variable.
GaussianFactor::shared_ptr negate () const override
 Return a factor representing the negated linear system.
void updateHessian (const KeyVector &keys, SymmetricBlockMatrix *info) const override
 Update the augmented Hessian using key lookup through the dense fallback.
void updateHessian (const KeyVector &keys, SymmetricBlockMatrix *info, DenseIndex beginCol, DenseIndex endCol) const override
 Update a column range of the augmented Hessian using the dense fallback.
void multiplyHessianAdd (double alpha, const VectorValues &x, VectorValues &y) const override
 Add the Hessian-vector product into y using the dense fallback.
VectorValues gradientAtZero () const override
 Return the full gradient evaluated at zero.
void gradientAtZero (double *d) const override
 Add the gradient evaluated at zero into a raw scalar buffer.
Vector gradient (Key key, const VectorValues &x) const override
 Return the gradient block for one key at the given linearization point.
 GaussianFactor ()
 Inherit GaussianFactor constructors.
template<typename CONTAINER>
 GaussianFactor (const CONTAINER &keys)
 Inherit GaussianFactor constructors.
Public Member Functions inherited from gtsam::GaussianFactor
 GaussianFactor ()
 Default constructor creates empty factor.
template<typename CONTAINER>
 GaussianFactor (const CONTAINER &keys)
 Construct from container of keys.
double error (const HybridValues &c) const override
 All factor types need to implement an error function.
VectorValues hessianDiagonal () const
 Return the diagonal of the Hessian for this factor.
virtual bool isJacobian () const
 Fast check for JacobianFactor-based types.
Public Member Functions inherited from gtsam::Factor
virtual ~Factor ()=default
 Default destructor.
bool empty () const
 Whether the factor is empty (involves zero variables).
Key front () const
 First key.
Key back () const
 Last key.
const_iterator find (Key key) const
 find
const KeyVector & keys () const
 Access the factor's involved variable keys.
const_iterator begin () const
 Iterator at beginning of involved variable keys.
const_iterator end () const
 Iterator at end of involved variable keys.
size_t size () const
virtual void printKeys (const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
 print only keys
bool equals (const This &other, double tol=1e-9) const
 check equality
KeyVector & keys ()
iterator begin ()
 Iterator at beginning of involved variable keys.
iterator end ()
 Iterator at end of involved variable keys.

Static Public Attributes

static constexpr size_t NumSlots = sizeof...(BlockDims)

Public Types

using Base = BatchJacobianFactorBase
using This = BatchJacobianFactor<ErrorDim, BlockDims...>
using shared_ptr = std::shared_ptr<This>
using SlotIndices = std::array<DenseIndex, NumSlots>
using HessianSlots = std::array<DenseIndex, NumSlots + 1>
using RhsVector = Eigen::Matrix<double, ErrorDim, 1>
template<int BlockDim>
using BlockMatrix = Eigen::Matrix<double, ErrorDim, BlockDim>
template<int BlockDim>
using BlockVector
using Blocks = std::tuple<BlockVector<BlockDims>...>
Public Types inherited from gtsam::GaussianFactor
typedef GaussianFactor This
 This class.
typedef std::shared_ptr< This > shared_ptr
 shared_ptr to this class
typedef Factor Base
 Our base class.
Public Types inherited from gtsam::Factor
typedef KeyVector::iterator iterator
 Iterator over keys.
typedef KeyVector::const_iterator const_iterator
 Const iterator over keys.

Additional Inherited Members

template<typename CONTAINER>
static DenseIndex Slot (const CONTAINER &keys, Key key)
 Factor ()
 Default constructor for I/O.
template<typename CONTAINER>
 Factor (const CONTAINER &keys)
 Construct factor from container of keys.
template<typename ITERATOR>
 Factor (ITERATOR first, ITERATOR last)
 Construct factor from iterator keys.
template<typename CONTAINER>
static Factor FromKeys (const CONTAINER &keys)
 Construct factor from container of keys.
template<typename ITERATOR>
static Factor FromIterators (ITERATOR first, ITERATOR last)
 Construct factor from iterator keys.
Protected Attributes inherited from gtsam::Factor
KeyVector keys_
 The keys involved in this factor.

Member Typedef Documentation

◆ BlockVector

template<int ErrorDim, int... BlockDims>
template<int BlockDim>
using gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::BlockVector
Initial value:
std::vector<BlockMatrix<BlockDim>,
Eigen::aligned_allocator<BlockMatrix<BlockDim>>>

Constructor & Destructor Documentation

◆ BatchJacobianFactor()

template<int ErrorDim, int... BlockDims>
gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::BatchJacobianFactor ( const KeyVector & keys,
std::vector< size_t > keyDims,
const SharedDiagonal & model = SharedDiagonal() )
inline

Construct an empty compact batch factor with known key dimensions.

Parameters
keysUnion of all keys represented by this batch factor.
keyDimsDimensions corresponding to keys, in the same order.
modelOptional diagonal model on the stored rows.

Member Function Documentation

◆ addRow()

template<int ErrorDim, int... BlockDims>
void gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::addRow ( const SlotIndices & slots,
const std::vector< Matrix > & blocks,
const Vector & rhs )
inline

Add one row group corresponding to one original nonlinear factor.

Parameters
slotsLocal key slots touched by this row group. Each entry indexes into this factor's keys() vector.
blocksFixed-size Jacobian blocks, one for each factor variable.
rhsRight-hand side vector for this row group.

◆ clone()

template<int ErrorDim, int... BlockDims>
GaussianFactor::shared_ptr gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::clone ( ) const
inlineoverridevirtual

Return a deep copy as a GaussianFactor.

Implements gtsam::GaussianFactor.

◆ deltaError()

template<int ErrorDim, int... BlockDims>
double gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::deltaError ( const VectorValues & values,
double * oldError = nullptr,
double * newError = nullptr ) const
inlineoverridevirtual

Evaluate the linear-model error change directly from compact rows.

Reimplemented from gtsam::GaussianFactor.

◆ get_model()

template<int ErrorDim, int... BlockDims>
const SharedDiagonal & gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::get_model ( ) const
inlineoverridevirtual

Return the optional diagonal model on the stored rows.

Implements gtsam::BatchJacobianFactorBase.

◆ getDim()

template<int ErrorDim, int... BlockDims>
DenseIndex gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::getDim ( const_iterator variable) const
inlineoverridevirtual

Return the dimension of the variable at the given key iterator.

Implements gtsam::GaussianFactor.

◆ gradientAtZeroAdd()

template<int ErrorDim, int... BlockDims>
void gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::gradientAtZeroAdd ( const std::vector< size_t > & scalarOffsets,
double * gradient ) const
inlineoverridevirtual

Add -A.transpose()*W*b directly to a flat gradient vector.

Reimplemented from gtsam::BatchJacobianFactorBase.

◆ hessianBlockDiagonalAdd()

template<int ErrorDim, int... BlockDims>
void gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::hessianBlockDiagonalAdd ( const std::vector< size_t > & blockSlots,
std::vector< Matrix > * diagonalBlocks ) const
inlineoverridevirtual

Add compact A.transpose()*W*A diagonal blocks without keyed maps.

Reimplemented from gtsam::BatchJacobianFactorBase.

◆ hessianDiagonalAdd()

template<int ErrorDim, int... BlockDims>
void gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::hessianDiagonalAdd ( VectorValues & diagonal) const
inlineoverridevirtual

Accumulate the Hessian scalar diagonal directly from compact rows.

Implements gtsam::GaussianFactor.

◆ multiplyHessianAdd()

template<int ErrorDim, int... BlockDims>
void gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::multiplyHessianAdd ( double alpha,
const std::vector< size_t > & scalarOffsets,
const double * x,
double * y ) const
inlineoverridevirtual

Add alpha*A.transpose()*W*A*x directly to a flat output vector.

Reimplemented from gtsam::BatchJacobianFactorBase.

◆ rows()

template<int ErrorDim, int... BlockDims>
size_t gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::rows ( ) const
inlineoverridevirtual

Return the number of scalar rows represented by all row groups.

Implements gtsam::BatchJacobianFactorBase.

◆ toJacobianFactor()

template<int ErrorDim, int... BlockDims>
JacobianFactor gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::toJacobianFactor ( ) const
inlineoverridevirtual

Convert compact row-block storage into a conventional JacobianFactor.

This compatibility path allocates dense blocks for every key in the batch, including structural zeros. Performance-critical solvers use the internal compact-factor elimination adapter.

Implements gtsam::BatchJacobianFactorBase.

◆ updateHessian() [1/2]

template<int ErrorDim, int... BlockDims>
void gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::updateHessian ( const KeyVector & infoKeys,
SymmetricBlockMatrix * info ) const
inlineoverridevirtual

Add this factor's augmented information matrix to info.

This direct implementation is the legacy Cholesky fast path. It accumulates fixed-size row-group products into the target SymmetricBlockMatrix and avoids constructing a dense compatibility JacobianFactor.

Implements gtsam::GaussianFactor.

◆ updateHessian() [2/2]

template<int ErrorDim, int... BlockDims>
void gtsam::BatchJacobianFactor< ErrorDim, BlockDims >::updateHessian ( const KeyVector & infoKeys,
SymmetricBlockMatrix * info,
DenseIndex beginCol,
DenseIndex endCol ) const
inlineoverridevirtual

Add this factor's augmented information matrix over a block-column range.

This overload supports the partial-column Hessian assembly used by parallel Cholesky paths. It follows the same column ownership convention as JacobianFactor: a block (I,J) is updated when max(I,J) lies in [beginCol,endCol).

Implements gtsam::GaussianFactor.


The documentation for this class was generated from the following file: