Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
momentum::OnlineBandedHouseholderQR< T > Class Template Reference

Online Householder QR solver for band-plus-arrowhead matrices. More...

#include <online_householder_qr.h>

Public Types

using MatrixType = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
using VectorType = Eigen::Matrix<T, Eigen::Dynamic, 1>

Public Member Functions

 OnlineBandedHouseholderQR (Eigen::Index n_band, Eigen::Index n_common, Eigen::Index bandwidth, T lambda=T(0))
 Constructs a banded solver.
void add (size_t iCol_offset, MatrixType A_band, MatrixType A_common, VectorType b)
 Copying overload of addMutating() that takes both banded and common contributions.
void add (MatrixType A_common, VectorType b)
 Copying overload for contributions that only touch the common columns.
void addMutating (const Eigen::Index iCol_offset, Eigen::Ref< MatrixType > A_band, Eigen::Ref< MatrixType > A_common, Eigen::Ref< VectorType > b)
 In-place addition; convenience wrapper that wraps the matrices in ColumnIndexedMatrix views without remapping.
void addMutating (Eigen::Ref< MatrixType > A_common, Eigen::Ref< VectorType > b)
 In-place addition for contributions that only touch the common columns.
void addMutating (Eigen::Index iCol_offset, ColumnIndexedMatrix< MatrixType > A_band, ColumnIndexedMatrix< MatrixType > A_common, Eigen::Ref< VectorType > b)
 In-place addition that accepts column-remapped views, so callers can pass arbitrary subsets of the columns in A_band and A_common.
void addMutating (ColumnIndexedMatrix< MatrixType > A_common, Eigen::Ref< VectorType > b)
 Common-only addition overload. Use when a contribution touches no banded columns.
void zeroBandedPart (Eigen::Index iCol_offset, ColumnIndexedMatrix< MatrixType > A_band, ColumnIndexedMatrix< MatrixType > A_common, Eigen::Ref< VectorType > b)
 Zeros out just the banded part of A_band by applying Householder rotations.
VectorType x_dense () const
 Retrieves the full dense result vector of length n_band() + n_common().
MatrixType R_dense () const
MatrixType y_dense () const
VectorType At_times_b () const
void reset ()
 Discards accumulated state, keeping the existing dimensions and damping.
Eigen::Index bandwidth () const
Eigen::Index n_band () const
Eigen::Index n_common () const

Detailed Description

template<typename T>
class momentum::OnlineBandedHouseholderQR< T >

Online Householder QR solver for band-plus-arrowhead matrices.

The left-hand part of the matrix is required to have a limited column-bandwidth, and a "common" section is permitted on the right, like this:

...b a n d e d... common
[ a_11 a_15 ]
[ a_21 a_22 a_25 ]
[ a_31 a_32 a_35 ]
[ a_42 a_43 a_45 ]
[ a_53 a_54 a_55 ]
[ a_64 a_65 ]

Here "bandwidth" is in columns; the matrix above has a bandwidth of 2 because no row spans more than two columns (excluding the common section). The common section holds parameters shared by every row.

While this seems specialized, it maps to a very common class of problems where the band structure represents a time dimension (smoothness constraints tend to connect adjacent timepoints) and the common parameters are shared across time. For example:

  • body tracking: band structure maps to smoothness constraints between adjacent frames, while common parameters control body scale.
  • camera calibration: band structure maps to smoothness constraints between adjacent frames of the extrinsics, while common parameters refer to intrinsics.

Usage contract

  1. Construct with n_band (number of banded unknowns), n_common (shared unknowns), bandwidth, and optional lambda damping.
  2. Add contributions via add()/addMutating(). Pass an iCol_offset indicating where the contribution's left-most banded column lives in the global numbering. Contributions touching only the common columns use the no-offset overload.
  3. Optionally use zeroBandedPart() to parallelize the banded sweep over disjoint column ranges; the matching addMutating(A_common, b) call must be serialized.
  4. Retrieve results via x_dense() (and inspect via R_dense()/y_dense()).
  5. Call reset() to discard accumulated state and reuse the solver.

Definition at line 406 of file online_householder_qr.h.

Member Typedef Documentation

◆ MatrixType

template<typename T>
using momentum::OnlineBandedHouseholderQR< T >::MatrixType = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>

Definition at line 408 of file online_householder_qr.h.

◆ VectorType

template<typename T>
using momentum::OnlineBandedHouseholderQR< T >::VectorType = Eigen::Matrix<T, Eigen::Dynamic, 1>

Definition at line 409 of file online_householder_qr.h.

Constructor & Destructor Documentation

◆ OnlineBandedHouseholderQR()

template<typename T>
momentum::OnlineBandedHouseholderQR< T >::OnlineBandedHouseholderQR ( Eigen::Index n_band,
Eigen::Index n_common,
Eigen::Index bandwidth,
T lambda = T(0) )
explicit

Constructs a banded solver.

Parameters
n_bandNumber of banded (per-time) unknowns.
n_commonNumber of common unknowns (the right-hand "arrowhead").
bandwidthMaximum number of banded columns any single row may touch.
lambdaLM-style damping; emulates the augmented system | [lambda*I; A] [x] - [0; b] |^2 without materializing the extra rows.

Definition at line 520 of file online_householder_qr.cpp.

References bandwidth(), MT_CHECK, n_band(), and n_common().

Member Function Documentation

◆ add() [1/2]

template<typename T>
void momentum::OnlineBandedHouseholderQR< T >::add ( MatrixType A_common,
VectorType b )
inline

Copying overload for contributions that only touch the common columns.

Definition at line 429 of file online_householder_qr.h.

References addMutating().

◆ add() [2/2]

template<typename T>
void momentum::OnlineBandedHouseholderQR< T >::add ( size_t iCol_offset,
MatrixType A_band,
MatrixType A_common,
VectorType b )
inline

Copying overload of addMutating() that takes both banded and common contributions.

Definition at line 424 of file online_householder_qr.h.

References addMutating().

◆ addMutating() [1/4]

template<typename T>
void momentum::OnlineBandedHouseholderQR< T >::addMutating ( ColumnIndexedMatrix< MatrixType > A_common,
Eigen::Ref< VectorType > b )

Common-only addition overload. Use when a contribution touches no banded columns.

Definition at line 644 of file online_householder_qr.cpp.

References momentum::ColumnIndexedMatrix< MatrixType >::col(), momentum::ColumnIndexedMatrix< MatrixType >::cols(), MT_CHECK, n_band(), n_common(), and momentum::ColumnIndexedMatrix< MatrixType >::rows().

◆ addMutating() [2/4]

template<typename T>
void momentum::OnlineBandedHouseholderQR< T >::addMutating ( const Eigen::Index iCol_offset,
Eigen::Ref< MatrixType > A_band,
Eigen::Ref< MatrixType > A_common,
Eigen::Ref< VectorType > b )
inline

In-place addition; convenience wrapper that wraps the matrices in ColumnIndexedMatrix views without remapping.

Definition at line 435 of file online_householder_qr.h.

References addMutating().

Referenced by add(), add(), addMutating(), addMutating(), and addMutating().

◆ addMutating() [3/4]

template<typename T>
void momentum::OnlineBandedHouseholderQR< T >::addMutating ( Eigen::Index iCol_offset,
ColumnIndexedMatrix< MatrixType > A_band,
ColumnIndexedMatrix< MatrixType > A_common,
Eigen::Ref< VectorType > b )

In-place addition that accepts column-remapped views, so callers can pass arbitrary subsets of the columns in A_band and A_common.

Parameters
iCol_offsetGlobal column index of A_band's left-most column. Must satisfy iCol_offset + A_band.cols() <= n_band().
A_bandBanded contribution. A_band.cols() must be at most bandwidth().
A_commonCommon contribution. A_common.cols() must equal n_common().
bResidual vector with A_band.rows() entries.
Postcondition
Internal R_band_, R_common_, and y_ are updated. The contents of A_band, A_common, and b are arbitrary on return.

Definition at line 569 of file online_householder_qr.cpp.

References addMutating(), and zeroBandedPart().

◆ addMutating() [4/4]

template<typename T>
void momentum::OnlineBandedHouseholderQR< T >::addMutating ( Eigen::Ref< MatrixType > A_common,
Eigen::Ref< VectorType > b )
inline

In-place addition for contributions that only touch the common columns.

Definition at line 448 of file online_householder_qr.h.

References addMutating().

◆ At_times_b()

template<typename T>
OnlineBandedHouseholderQR< T >::VectorType momentum::OnlineBandedHouseholderQR< T >::At_times_b ( ) const
nodiscard
Returns
A^T * b for the data accumulated so far.

Definition at line 756 of file online_householder_qr.cpp.

References bandwidth(), n_band(), and n_common().

Referenced by momentum::SequenceSolverT< T >::doIteration().

◆ bandwidth()

template<typename T>
Eigen::Index momentum::OnlineBandedHouseholderQR< T >::bandwidth ( ) const
inlinenodiscard

Definition at line 517 of file online_householder_qr.h.

Referenced by At_times_b(), OnlineBandedHouseholderQR(), R_dense(), and x_dense().

◆ n_band()

template<typename T>
Eigen::Index momentum::OnlineBandedHouseholderQR< T >::n_band ( ) const
inlinenodiscard

◆ n_common()

template<typename T>
Eigen::Index momentum::OnlineBandedHouseholderQR< T >::n_common ( ) const
inlinenodiscard

◆ R_dense()

template<typename T>
OnlineBandedHouseholderQR< T >::MatrixType momentum::OnlineBandedHouseholderQR< T >::R_dense ( ) const
nodiscard
Returns
R as a dense matrix of size (n_band+n_common) x (n_band+n_common), reconstructed from the banded and common storage.

Definition at line 678 of file online_householder_qr.cpp.

References bandwidth(), n_band(), and n_common().

◆ reset()

template<typename T>
void momentum::OnlineBandedHouseholderQR< T >::reset ( )

Discards accumulated state, keeping the existing dimensions and damping.

Definition at line 560 of file online_householder_qr.cpp.

◆ x_dense()

template<typename T>
OnlineBandedHouseholderQR< T >::VectorType momentum::OnlineBandedHouseholderQR< T >::x_dense ( ) const
nodiscard

Retrieves the full dense result vector of length n_band() + n_common().

Definition at line 709 of file online_householder_qr.cpp.

References bandwidth(), n_band(), and n_common().

Referenced by momentum::SequenceSolverT< T >::doIteration().

◆ y_dense()

template<typename T>
MatrixType momentum::OnlineBandedHouseholderQR< T >::y_dense ( ) const
inlinenodiscard
Returns
The transformed right-hand side Q * b.

Definition at line 507 of file online_householder_qr.h.

◆ zeroBandedPart()

template<typename T>
void momentum::OnlineBandedHouseholderQR< T >::zeroBandedPart ( Eigen::Index iCol_offset,
ColumnIndexedMatrix< MatrixType > A_band,
ColumnIndexedMatrix< MatrixType > A_common,
Eigen::Ref< VectorType > b )

Zeros out just the banded part of A_band by applying Householder rotations.

A_common is updated in place but will still have nonzero entries on return, so after calling this you should follow up with addMutating(A_common, b) to fold the remaining common contribution into the factorization.

Why is this useful? If you are careful, you can call zeroBandedPart on multiple non-overlapping segments of the banded matrix in parallel; only the A_common processing must be serialized. Because the number of common variables is usually much smaller than the number of banded variables, this can provide a substantial speedup in practice.

Precondition
iCol_offset, A_band, A_common, b satisfy the same shape rules as addMutating().
The column range [iCol_offset, iCol_offset + A_band.cols()) does not overlap any concurrently in-flight zeroBandedPart call on the same solver.
Postcondition
R_band_ is updated; A_band is zeroed; A_common and b are mutated and must be passed to the common-only addMutating() to finish the contribution.

Definition at line 579 of file online_householder_qr.cpp.

References momentum::ColumnIndexedMatrix< MatrixType >::col(), momentum::ColumnIndexedMatrix< MatrixType >::cols(), MT_CHECK, n_common(), and momentum::ColumnIndexedMatrix< MatrixType >::rows().

Referenced by addMutating().


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