|
Momentum
A library for solving nonlinear optimization problems related to human body kinematics
|
Online (incremental) Householder QR solver for tall, column-sparse least-squares problems. 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 | |
| OnlineHouseholderQR (Eigen::Index n, T lambda=T(0)) | |
Constructs a solver for problems with n unknowns. | |
| void | addMutating (Eigen::Ref< MatrixType > A, Eigen::Ref< VectorType > b) |
In-place overload: factorizes A and b directly, mutating both buffers. | |
| void | addMutating (ColumnIndexedMatrix< MatrixType > A, Eigen::Ref< VectorType > b) |
| In-place addition of a Jacobian/residual block to the running QR factorization. | |
| void | add (MatrixType A, VectorType b) |
| Copying overload of addMutating(). | |
| VectorType | result () const |
Solves R * x = y by back-substitution using the currently accumulated state and returns x. | |
| const MatrixType & | R () const |
| const VectorType & | y () const |
| VectorType | At_times_b () const |
| void | reset () |
Discards accumulated state, keeping the existing n and lambda. | |
| void | reset (Eigen::Index n, T lambda=T(0)) |
Discards accumulated state and reconfigures the solver with new n and lambda. | |
Online (incremental) Householder QR solver for tall, column-sparse least-squares problems.
Solves
where a. n (the number of unknowns) is small-ish, b. A is tall and sparse (m >> n), BUT c. (A^T * A) is dense.
This turns out to be the common case for hand-model IK, because: a. The hand has only ~22 DOF, b. Each constraint touches only a few DOFs (typically the 3-4 on a single finger), but c. Constraints that touch the global DOFs tend to densify A^T*A. From the perspective of a QR factorization: since the R matrix has the same sparsity pattern as the L matrix in the Cholesky factorization of A^T*A, there is no point trying to exploit sparsity in the computation of R (e.g. by reordering columns). So instead, we accept the O(n^2) cost of a dense R and try to exploit sparsity in A.
It is possible to exploit sparsity in A if you do the factorization row-wise instead of column-wise as is generally done. One paper that uses Givens rotations to zero out one row at a time is: Solution of Sparse Linear Squares Problems using Givens Rotations (1980) by Alan George and Michael T. Heath
However, Givens rotations aren't really ideal for our case because you have to compute a c/s pair for each entry of the matrix, and it involves a square root. Also, row-wise operations are slow in general due to poor cache locality on Eigen matrices. What we do instead is apply Householder reflections to (k x n) blocks of the matrix; computing a Householder vector for a whole column only requires one square root, and it can be applied as a level-2 BLAS operation. Moreover, this maps perfectly to our problem; a Jacobian matrix from a single constraint has the sparsity pattern where entire columns are dropped, and these zero columns can just be skipped entirely by the Householder process provided we are careful about the order we process them in. And by processing the J submatrices one at a time, we never assemble the full A matrix, eliminating one major disadvantage of QR relative to the normal equations (hence the name "OnlineHouseholderQR").
Even better, we can do the whole operation in-place: the caller passes in the J and r matrix, and the columns of the J matrix are rotated out one by one, revealing the R matrix. At the end, a simple back-substitution using R gives the x vector. (In fact, the answer for the current submatrix of A,b is always available, as a consequence of doing the factorization sort-of row-wise.)
n and (optionally) a Levenberg-Marquardt damping lambda.x. R(), y(), and At_times_b() are also valid at any point and reflect the data accumulated so far.Definition at line 154 of file online_householder_qr.h.
| using momentum::OnlineHouseholderQR< T >::MatrixType = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> |
Definition at line 156 of file online_householder_qr.h.
| using momentum::OnlineHouseholderQR< T >::VectorType = Eigen::Matrix<T, Eigen::Dynamic, 1> |
Definition at line 157 of file online_householder_qr.h.
|
explicit |
Constructs a solver for problems with n unknowns.
The lambda parameter implements Gauss-Newton/Levenberg-Marquardt damping, emulating the augmented least-squares system
without materializing the extra lambda * I rows. R is initialized with lambda on its diagonal so the first add() call sees the regularization.
Definition at line 123 of file online_householder_qr.cpp.
References reset().
| void momentum::OnlineHouseholderQR< T >::add | ( | MatrixType | A, |
| VectorType | b ) |
Copying overload of addMutating().
Definition at line 166 of file online_householder_qr.cpp.
References addMutating().
| void momentum::OnlineHouseholderQR< T >::addMutating | ( | ColumnIndexedMatrix< MatrixType > | A, |
| Eigen::Ref< VectorType > | b ) |
In-place addition of a Jacobian/residual block to the running QR factorization.
Both A and b are required so we can apply Q to the right-hand side as R is being constructed. The factorization is computed inside the passed-in buffers, so callers who do not need the original data can avoid a copy.
n passed to the constructor. A and b are arbitrary on return. Definition at line 171 of file online_householder_qr.cpp.
References momentum::ColumnIndexedMatrix< MatrixType >::col(), momentum::ColumnIndexedMatrix< MatrixType >::cols(), MT_CHECK, MT_PROFILE_FUNCTION, and momentum::ColumnIndexedMatrix< MatrixType >::rows().
|
inline |
In-place overload: factorizes A and b directly, mutating both buffers.
Convenience wrapper that wraps A in a ColumnIndexedMatrix.
Definition at line 173 of file online_householder_qr.h.
References addMutating().
Referenced by add(), and addMutating().
|
nodiscard |
Definition at line 224 of file online_householder_qr.cpp.
|
inlinenodiscard |
Definition at line 201 of file online_householder_qr.h.
| void momentum::OnlineHouseholderQR< T >::reset | ( | ) |
Discards accumulated state, keeping the existing n and lambda.
Definition at line 128 of file online_householder_qr.cpp.
References reset().
Referenced by OnlineHouseholderQR(), and reset().
| void momentum::OnlineHouseholderQR< T >::reset | ( | Eigen::Index | n, |
| T | lambda = T(0) ) |
Discards accumulated state and reconfigures the solver with new n and lambda.
Definition at line 133 of file online_householder_qr.cpp.
|
nodiscard |
Solves R * x = y by back-substitution using the currently accumulated state and returns x.
n containing the least-squares solution for the data added so far. Definition at line 235 of file online_householder_qr.cpp.
|
inlinenodiscard |
n entries). Definition at line 205 of file online_householder_qr.h.