EmrysFilter 0.1.0
State estimation utilities in C++23 using Eigen
Loading...
Searching...
No Matches
Emrys::Mixture< Component_, Allocator_ > Class Template Reference

The density of a Mixture whose components have been factorized: a read-only view. More...

#include <EmrysFilter/Distributions/Mixture.h>

Public Types

using ParamsType = MixtureParams<Component_, Allocator_>
 the parameters it reads
using ComponentType = Params<Component_>
 a component
using SpaceType = typename ParamsType::SpaceType
 the components' space
using allocator_type = Allocator_
 the parameters' allocator
using Entry = typename ParamsType::Entry
 one weighted component
using const_iterator = typename ParamsType::const_iterator
 iterates the entries
using MomentsType = typename ParamsType::MomentsType
 a mean and covariance together
using Scalar = typename ParamsType::Scalar
 the scalar type
using Index = typename ParamsType::Index
 Eigen's index type.
using VectorType = typename ParamsType::VectorType
 a value, such as a mean
using DifferenceVectorType = typename ParamsType::DifferenceVectorType
 a difference
using MatrixType = typename ParamsType::MatrixType
 a matrix over differences

Public Member Functions

Index size () const
Index valueDimension () const
Index differenceDimension () const
SpaceType const & space () const
allocator_type get_allocator () const
const_iterator begin () const
const_iterator end () const
ParamsType::Entry const & operator[] (Index i) const
Scalar logTotalWeight () const
Scalar ess () const
Index mostProbable () const
ComponentType collapsed () const
MomentsType moments () const
template<typename Derived>
Scalar logDensity (Eigen::MatrixBase< Derived > const &x) const
template<typename Derived>
Scalar density (Eigen::MatrixBase< Derived > const &x) const
template<typename Path>
auto marginal () const
 marginal() of the subspace named by the tag path Path; see MixtureParams::marginal().
template<typename Path>
auto marginal (Index element) const
 marginal() of one repetition of a repeated block; see GaussianParams::marginal(element).
template<typename GivenPath, typename Derived>
requires (isGaussian<ComponentType>)
auto conditional (Eigen::MatrixBase< Derived > const &values) const

Static Public Attributes

static constexpr int ValueDimensionAtCompileTime = ParamsType::ValueDimensionAtCompileTime
 the length of a value, or Eigen::Dynamic
static constexpr int MaxValueDimensionAtCompileTime = ParamsType::MaxValueDimensionAtCompileTime
 a bound on the length of a value, or Eigen::Dynamic
static constexpr int DifferenceDimensionAtCompileTime = ParamsType::DifferenceDimensionAtCompileTime
 the length of a difference and the rows of a covariance, or Eigen::Dynamic
static constexpr int MaxDifferenceDimensionAtCompileTime = ParamsType::MaxDifferenceDimensionAtCompileTime
 a bound on the length of a difference, or Eigen::Dynamic
static constexpr bool IsParams = false
 a view: it checks its parameters

Detailed Description

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
class Emrys::Mixture< Component_, Allocator_ >

The density of a Mixture whose components have been factorized: a read-only view.

Represents the normalized density

\[ p(x) = \frac{\sum_i w_i \, p_i(x)}{\sum_i w_i}, \]

with \( p_i \) the density of component \( i \), read from its factorization under this view's check (see ComponentTraits).

Obtained from MixtureParams::toDensity(). It checks the source for changes, as its copies do: reading it after the source has changed is a programmer error (decisions.md [view-stamp]). A Mixture must not outlive its source.

See also
class MixtureParams

Member Function Documentation

◆ begin()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
const_iterator Emrys::Mixture< Component_, Allocator_ >::begin ( ) const
inlinenodiscard
Returns
an iterator to the first entry

◆ collapsed()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
ComponentType Emrys::Mixture< Component_, Allocator_ >::collapsed ( ) const
inlinenodiscard
Returns
the mixture as one component, moment-matched over the components with their normalized weights (see ComponentTraits): for Gaussian components the Gaussian with moments(), and for hybrid components the hybrid whose mode probabilities are the weighted sums and whose conditionals are collapsed per mode

◆ conditional()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
template<typename GivenPath, typename Derived>
requires (isGaussian<ComponentType>)
auto Emrys::Mixture< Component_, Allocator_ >::conditional ( Eigen::MatrixBase< Derived > const & values) const
inlinenodiscard
Returns
a copy of the conditional distribution; see MixtureParams::conditional().

◆ density()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
template<typename Derived>
Scalar Emrys::Mixture< Component_, Allocator_ >::density ( Eigen::MatrixBase< Derived > const & x) const
inlinenodiscard
Returns
the density \( p(x) \) at x
Warning
Underflows easily in high dimensions; prefer logDensity().
See also
logDensity()

◆ differenceDimension()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
Index Emrys::Mixture< Component_, Allocator_ >::differenceDimension ( ) const
inlinenodiscard
Returns
the number of rows and columns of every component's covariance

◆ end()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
const_iterator Emrys::Mixture< Component_, Allocator_ >::end ( ) const
inlinenodiscard
Returns
an iterator past the last entry

◆ ess()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
Scalar Emrys::Mixture< Component_, Allocator_ >::ess ( ) const
inlinenodiscard
Returns
the effective sample size \( 1 / \sum_i \hat w_i^2 \) of the normalized weights, between 1 and size()

◆ get_allocator()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
allocator_type Emrys::Mixture< Component_, Allocator_ >::get_allocator ( ) const
inlinenodiscard
Returns
the source's allocator

◆ logDensity()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
template<typename Derived>
Scalar Emrys::Mixture< Component_, Allocator_ >::logDensity ( Eigen::MatrixBase< Derived > const & x) const
inlinenodiscard
Returns
the log of the density at x: the log-sum-exp of each component's log-weight plus its log-density, less the log of the total weight (LogSumExp). It reads the components' factorizations under this view's check and makes none of its own, so it may be evaluated at several points at once.
See also
density()

◆ logTotalWeight()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
Scalar Emrys::Mixture< Component_, Allocator_ >::logTotalWeight ( ) const
inlinenodiscard
Returns
the log of the sum of the (unnormalized) component weights

◆ moments()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
MomentsType Emrys::Mixture< Component_, Allocator_ >::moments ( ) const
inlinenodiscard
Returns
the mean and covariance of the mixture, \( \mu = \sum_i \hat w_i \mu_i \) and \( \Sigma = \sum_i \hat w_i \left(\Sigma_i + (\mu_i - \mu)(\mu_i - \mu)^T\right) \), where \( \hat w_i \) are the normalized weights. In a non-linear space the mean is a tangent-space mean and the deviations are \( \mu_i \boxminus \mu \).

Only the lower triangle of each component covariance is read; the result is symmetric. It allocates nothing sized by the number of components.

◆ mostProbable()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
Index Emrys::Mixture< Component_, Allocator_ >::mostProbable ( ) const
inlinenodiscard
Returns
the index of the most probable component, the one with the largest weight; ties go to the lowest. The factorization checked the weights, so none is NaN.
See also
MixtureParams::mostProbable()

◆ operator[]()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
ParamsType::Entry const & Emrys::Mixture< Component_, Allocator_ >::operator[] ( Index i) const
inlinenodiscard
Returns
entry i of the source, which must be less than size()

◆ size()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
Index Emrys::Mixture< Component_, Allocator_ >::size ( ) const
inlinenodiscard
Returns
the number of components

◆ space()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
SpaceType const & Emrys::Mixture< Component_, Allocator_ >::space ( ) const
inlinenodiscard
Returns
the source's space

◆ valueDimension()

template<internal::ComponentOrInfoForm Component_, typename Allocator_ = DefaultAllocator>
Index Emrys::Mixture< Component_, Allocator_ >::valueDimension ( ) const
inlinenodiscard
Returns
the number of coordinates of every component's mean

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