Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
covariance_matrix.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
11#include <momentum/math/types.h>
12
13namespace momentum {
14
26template <typename T>
28 public:
30
36 void reset(T sigma, Eigen::Ref<const Eigen::MatrixX<T>> A);
37
39 [[nodiscard]] Eigen::Index dimension() const;
40
42 [[nodiscard]] const Eigen::MatrixX<T>& basis() const;
43
45 [[nodiscard]] T sigma() const;
46
48 [[nodiscard]] Eigen::VectorX<T> inverse_times_vec(Eigen::Ref<const Eigen::VectorX<T>> rhs) const;
50 [[nodiscard]] Eigen::VectorX<T> times_vec(Eigen::Ref<const Eigen::VectorX<T>> rhs) const;
51
53 [[nodiscard]] Eigen::MatrixX<T> inverse_times_mat(Eigen::Ref<const Eigen::MatrixX<T>> rhs) const;
55 [[nodiscard]] Eigen::MatrixX<T> times_mat(Eigen::Ref<const Eigen::MatrixX<T>> rhs) const;
56
59 [[nodiscard]] const Eigen::MatrixX<T>& R() const;
60
62 [[nodiscard]] T logDeterminant() const;
63
65 [[nodiscard]] T inverse_logDeterminant() const;
66
67 private:
79 OnlineHouseholderQR<T> qrFactorization_{0};
80
82 Eigen::MatrixX<T> A_;
83
85 T sigma_ = 0;
86};
87
88} // namespace momentum
Eigen::MatrixX< T > times_mat(Eigen::Ref< const Eigen::MatrixX< T > > rhs) const
Column-wise application of C to a matrix rhs.
Eigen::VectorX< T > times_vec(Eigen::Ref< const Eigen::VectorX< T > > rhs) const
Returns C * rhs = sigma^2 * rhs + A^T * (A * rhs).
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::Index dimension() const
Returns n, the dimension of the covariance (number of columns of A).
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 inverse_logDeterminant() const
Returns log(det(C^{-1})) = -log(det(C)).
const Eigen::MatrixX< T > & basis() const
Returns the stored basis A passed to reset().
void reset(T sigma, Eigen::Ref< const Eigen::MatrixX< T > > A)
(Re)build the covariance from a regularizer sigma and basis A.
Eigen::MatrixX< T > inverse_times_mat(Eigen::Ref< const Eigen::MatrixX< T > > rhs) const
Column-wise application of C^{-1} to a matrix rhs.
T logDeterminant() const
Returns log(det(C)), computed stably as 2 * sum(log|diag(R)|).
Online (incremental) Householder QR solver for tall, column-sparse least-squares problems.