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

Mixture of Probabilistic Principal Component Analyzers (MPPCA). More...

#include <mppca.h>

Public Member Functions

void set (const VectorX< T > &pi, const MatrixX< T > &mmu, momentum::span< const MatrixX< T > > W, const VectorX< T > &sigma2)
 Initializes the model from raw mixture parameters and precomputes Cinv, L, and Rpre for fast log-likelihood evaluation.
template<typename T2>
MppcaT< T2 > cast () const
 Returns a copy of this model with all numeric data converted to scalar type T2.
bool isApprox (const MppcaT< T > &mppcaT) const
 Returns true if every member matches mppcaT exactly (d, p, names) or approximately (mu, Cinv, L, Rpre) using Eigen's isApprox default tolerance.

Public Attributes

size_t d = 0
 Dimensionality of the data space x.
size_t p = 0
 Number of mixture components.
std::vector< std::string > names
 Optional human-readable names for each of the d data dimensions.
Eigen::MatrixX< T > mu
 Per-component mean vectors stored as a p x d matrix; row c is mu_c.
std::vector< Eigen::MatrixX< T > > Cinv
 Per-component inverse covariance matrices C_c^{-1} of size d x d.
std::vector< Eigen::MatrixX< T > > L
 Per-component lower-triangular factors derived from the Cholesky-like decomposition of C_c (used as a whitening transform when sampling or evaluating the Mahalanobis term efficiently).
Eigen::VectorX< T > Rpre
 Per-component constant term of the log-likelihood: Rpre(c) = log(pi_c) - 0.5 * log|C_c| - (d/2) * log(2*pi).

Detailed Description

template<typename T>
struct momentum::MppcaT< T >

Mixture of Probabilistic Principal Component Analyzers (MPPCA).

Each component models the data as x = W_c z + mu_c + epsilon, where z is a low-dimensional latent vector and epsilon ~ N(0, sigma_c^2 I) is isotropic noise. The full mixture density is p(x) = sum_c pi_c N(x | mu_c, C_c) with C_c = W_c W_c^T + sigma_c^2 I.

After set(), the model stores precomputed quantities so that the per-component log-likelihood of a sample x can be evaluated as Rpre(c) - 0.5 * (x - mu.row(c))^T * Cinv[c] * (x - mu.row(c)).

Based on: http://www.miketipping.com/papers/met-mppca.pdf

Template Parameters
TScalar type (float or double).

Definition at line 29 of file mppca.h.

Member Function Documentation

◆ cast()

template<typename T>
template<typename T2>
template MppcaT< double > momentum::MppcaT< T >::cast ( ) const
nodiscard

Returns a copy of this model with all numeric data converted to scalar type T2.

Names and dimensions are copied unchanged.

Template Parameters
T2Target scalar type.
Returns
Converted MPPCA model.

Definition at line 113 of file mppca.cpp.

References momentum::cast(), momentum::castMatrices(), Cinv, d, L, mu, names, p, and Rpre.

◆ isApprox()

template<typename T>
bool momentum::MppcaT< T >::isApprox ( const MppcaT< T > & mppcaT) const
nodiscard

Returns true if every member matches mppcaT exactly (d, p, names) or approximately (mu, Cinv, L, Rpre) using Eigen's isApprox default tolerance.

Parameters
[in]mppcaTModel to compare with.
Returns
True if approximately equal.

Definition at line 128 of file mppca.cpp.

References Cinv, d, momentum::isApprox(), L, mu, names, p, and Rpre.

◆ set()

template<typename T>
void momentum::MppcaT< T >::set ( const VectorX< T > & pi,
const MatrixX< T > & mmu,
momentum::span< const MatrixX< T > > W,
const VectorX< T > & sigma2 )

Initializes the model from raw mixture parameters and precomputes Cinv, L, and Rpre for fast log-likelihood evaluation.

Parameters
[in]piMixture weights, length p. Must sum to 1 and be > 0.
[in]mmuPer-component means as a p x d matrix (row c is mu_c).
[in]WPer-component factor-loading matrices W_c; expected to be of size d x q_c where q_c < d is the latent dimension. Length p.
[in]sigma2Per-component isotropic noise variances sigma_c^2, length p. Must be strictly positive.
Precondition
pi.size() == p, mmu.rows() == p, W.size() == p, sigma2.size() == p, and W[c].rows() == mmu.cols() for all c.
Postcondition
d == mmu.cols(), p == sigma2.rows(), and Cinv, L, Rpre, mu, names are sized consistently.

Definition at line 17 of file mppca.cpp.

References Cinv, d, L, MT_THROW_IF, mu, names, p, Rpre, and momentum::twopi().

Member Data Documentation

◆ Cinv

template<typename T>
std::vector<Eigen::MatrixX<T> > momentum::MppcaT< T >::Cinv

Per-component inverse covariance matrices C_c^{-1} of size d x d.

Cinv.size() == p after set().

Definition at line 45 of file mppca.h.

Referenced by cast(), isApprox(), momentum::saveMppca(), and set().

◆ d

template<typename T>
size_t momentum::MppcaT< T >::d = 0

Dimensionality of the data space x.

Definition at line 31 of file mppca.h.

Referenced by cast(), isApprox(), momentum::saveMppca(), and set().

◆ L

template<typename T>
std::vector<Eigen::MatrixX<T> > momentum::MppcaT< T >::L

Per-component lower-triangular factors derived from the Cholesky-like decomposition of C_c (used as a whitening transform when sampling or evaluating the Mahalanobis term efficiently).

L.size() == p after set().

Definition at line 51 of file mppca.h.

Referenced by cast(), isApprox(), and set().

◆ mu

template<typename T>
Eigen::MatrixX<T> momentum::MppcaT< T >::mu

Per-component mean vectors stored as a p x d matrix; row c is mu_c.

Definition at line 41 of file mppca.h.

Referenced by cast(), isApprox(), momentum::saveMppca(), and set().

◆ names

template<typename T>
std::vector<std::string> momentum::MppcaT< T >::names

Optional human-readable names for each of the d data dimensions.

set() resizes this to d empty strings; callers may overwrite entries.

Definition at line 38 of file mppca.h.

Referenced by cast(), isApprox(), momentum::saveMppca(), and set().

◆ p

template<typename T>
size_t momentum::MppcaT< T >::p = 0

Number of mixture components.

Definition at line 34 of file mppca.h.

Referenced by cast(), isApprox(), momentum::saveMppca(), and set().

◆ Rpre

template<typename T>
Eigen::VectorX<T> momentum::MppcaT< T >::Rpre

Per-component constant term of the log-likelihood: Rpre(c) = log(pi_c) - 0.5 * log|C_c| - (d/2) * log(2*pi).

Add the -0.5 * Mahalanobis term to obtain the log-density of x under component c. Length is p after set().

Definition at line 57 of file mppca.h.

Referenced by cast(), isApprox(), momentum::saveMppca(), and set().


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