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

Efficient and numerically stable representation of a low-rank-plus-diagonal Gaussian covariance matrix C = sigma^2 * I + A^T * A where C and I are [n x n] and the basis A is [m x n] (m may be larger or smaller than n). More...

#include <covariance_matrix.h>

Public Member Functions

 LowRankCovarianceMatrixT ()=default
void reset (T sigma, Eigen::Ref< const Eigen::MatrixX< T > > A)
 (Re)build the covariance from a regularizer sigma and basis A.
Eigen::Index dimension () const
 Returns n, the dimension of the covariance (number of columns of A).
const Eigen::MatrixX< T > & basis () const
 Returns the stored basis A passed to reset().
T sigma () const
 Returns the diagonal regularizer sigma passed to reset().
Eigen::VectorX< T > inverse_times_vec (Eigen::Ref< const Eigen::VectorX< T > > rhs) const
 Returns C^{-1} * rhs, computed via two triangular solves on R.
Eigen::VectorX< T > times_vec (Eigen::Ref< const Eigen::VectorX< T > > rhs) const
 Returns C * rhs = sigma^2 * rhs + A^T * (A * rhs).
Eigen::MatrixX< T > inverse_times_mat (Eigen::Ref< const Eigen::MatrixX< T > > rhs) const
 Column-wise application of C^{-1} to a matrix rhs.
Eigen::MatrixX< T > times_mat (Eigen::Ref< const Eigen::MatrixX< T > > rhs) const
 Column-wise application of C to a matrix rhs.
const Eigen::MatrixX< T > & R () const
 Returns the upper-triangular R factor of the QR factorization of [sigma*I; A], so that C = R^T * R.
T logDeterminant () const
 Returns log(det(C)), computed stably as 2 * sum(log|diag(R)|).
T inverse_logDeterminant () const
 Returns log(det(C^{-1})) = -log(det(C)).

Detailed Description

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

Efficient and numerically stable representation of a low-rank-plus-diagonal Gaussian covariance matrix C = sigma^2 * I + A^T * A where C and I are [n x n] and the basis A is [m x n] (m may be larger or smaller than n).

Access to C^{-1} is computed via the QR factorization of the augmented matrix [sigma*I; A], which keeps the construction numerically stable and avoids ever forming A^T * A explicitly.

Precondition
sigma > 0 (required for C to be strictly positive-definite and for the QR-based inverse to exist; the implementation does not check).
Note
C is symmetric positive-definite by construction.

Definition at line 27 of file covariance_matrix.h.

Constructor & Destructor Documentation

◆ LowRankCovarianceMatrixT()

template<typename T>
momentum::LowRankCovarianceMatrixT< T >::LowRankCovarianceMatrixT ( )
default

Member Function Documentation

◆ basis()

template<typename T>
const Eigen::MatrixX< T > & momentum::LowRankCovarianceMatrixT< T >::basis ( ) const
nodiscard

Returns the stored basis A passed to reset().

Definition at line 38 of file covariance_matrix.cpp.

◆ dimension()

template<typename T>
Eigen::Index momentum::LowRankCovarianceMatrixT< T >::dimension ( ) const
nodiscard

Returns n, the dimension of the covariance (number of columns of A).

Definition at line 33 of file covariance_matrix.cpp.

Referenced by inverse_times_mat(), and logDeterminant().

◆ inverse_logDeterminant()

template<typename T>
T momentum::LowRankCovarianceMatrixT< T >::inverse_logDeterminant ( ) const
nodiscard

Returns log(det(C^{-1})) = -log(det(C)).

Definition at line 114 of file covariance_matrix.cpp.

References logDeterminant().

◆ inverse_times_mat()

template<typename T>
Eigen::MatrixX< T > momentum::LowRankCovarianceMatrixT< T >::inverse_times_mat ( Eigen::Ref< const Eigen::MatrixX< T > > rhs) const
nodiscard

Column-wise application of C^{-1} to a matrix rhs.

Definition at line 71 of file covariance_matrix.cpp.

References dimension(), MT_CHECK, and R().

◆ inverse_times_vec()

template<typename T>
Eigen::VectorX< T > momentum::LowRankCovarianceMatrixT< T >::inverse_times_vec ( Eigen::Ref< const Eigen::VectorX< T > > rhs) const
nodiscard

Returns C^{-1} * rhs, computed via two triangular solves on R.

Definition at line 48 of file covariance_matrix.cpp.

References MT_CHECK, and R().

◆ logDeterminant()

template<typename T>
T momentum::LowRankCovarianceMatrixT< T >::logDeterminant ( ) const
nodiscard

Returns log(det(C)), computed stably as 2 * sum(log|diag(R)|).

Definition at line 95 of file covariance_matrix.cpp.

References dimension(), MT_CHECK, and R().

Referenced by inverse_logDeterminant().

◆ R()

template<typename T>
const Eigen::MatrixX< T > & momentum::LowRankCovarianceMatrixT< T >::R ( ) const
nodiscard

Returns the upper-triangular R factor of the QR factorization of [sigma*I; A], so that C = R^T * R.

Definition at line 90 of file covariance_matrix.cpp.

Referenced by inverse_times_mat(), inverse_times_vec(), and logDeterminant().

◆ reset()

template<typename T>
void momentum::LowRankCovarianceMatrixT< T >::reset ( T sigma,
Eigen::Ref< const Eigen::MatrixX< T > > A )

(Re)build the covariance from a regularizer sigma and basis A.

Computes the QR factorization of [sigma*I; A] from scratch (batch update; not an incremental/online refinement of any previous state).

Parameters
sigmaDiagonal regularizer; must be > 0.
ALow-rank basis with n columns and m rows.

Definition at line 15 of file covariance_matrix.cpp.

References sigma().

◆ sigma()

template<typename T>
T momentum::LowRankCovarianceMatrixT< T >::sigma ( ) const
nodiscard

Returns the diagonal regularizer sigma passed to reset().

Definition at line 43 of file covariance_matrix.cpp.

Referenced by reset().

◆ times_mat()

template<typename T>
Eigen::MatrixX< T > momentum::LowRankCovarianceMatrixT< T >::times_mat ( Eigen::Ref< const Eigen::MatrixX< T > > rhs) const
nodiscard

Column-wise application of C to a matrix rhs.

Definition at line 82 of file covariance_matrix.cpp.

◆ times_vec()

template<typename T>
Eigen::VectorX< T > momentum::LowRankCovarianceMatrixT< T >::times_vec ( Eigen::Ref< const Eigen::VectorX< T > > rhs) const
nodiscard

Returns C * rhs = sigma^2 * rhs + A^T * (A * rhs).

Definition at line 60 of file covariance_matrix.cpp.


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