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

A Gaussian kept as a mean and a lower-triangular root of its covariance. More...

#include <EmrysFilter/Distributions/SqrtGaussian.h>

Public Types

using MomentsType = Moments<Space_, Scalar_>
 the mean and covariance together
using Scalar = typename MomentsType::Scalar
 the scalar type
using Index = typename MomentsType::Index
 Eigen's index type.
using VectorType = typename MomentsType::VectorType
 a value, such as the mean
using DifferenceVectorType = typename MomentsType::DifferenceVectorType
 a difference, such as a residual
using MatrixType = typename MomentsType::MatrixType
 a matrix over differences
using SpaceType = Space_
 the space the values live in
using DensityType = FormGaussian<SqrtGaussianParams>
 the view toDensity() returns

Public Member Functions

 SqrtGaussianParams ()
 Constructs a SqrtGaussianParams in a default space, with a zero mean and root.
 SqrtGaussianParams (Space_ space)
 Constructs a SqrtGaussianParams in space, with a zero mean and root.
template<MatrixExpression Mean, MatrixExpression Root>
requires internal::SizedByLength<Space_>
 SqrtGaussianParams (Mean &&mean, Root &&root)
 Constructs a SqrtGaussianParams from mean and the lower triangle of root, moving either one passed as an rvalue of the stored type, in a default space resized to fit them.
template<MatrixExpression Mean, MatrixExpression Root>
 SqrtGaussianParams (Space_ space, Mean &&mean, Root &&root)
 SqrtGaussianParams(mean, root) in space, which is resized to fit them if it has one resizable block.
Index valueDimension () const
Index differenceDimension () const
Space_ const & space () const
VectorType const & mean () const
MatrixType const & root () const
MomentsType moments () const
template<MatrixExpression Mean>
void setMean (Mean &&mean)
 Sets the mean, normalized by the space, moving mean if it is an rvalue of the stored type.
template<MatrixExpression Root>
void setRoot (Root &&root)
 Sets the root to the lower triangle of root, moving it if it is an rvalue of the stored type.
std::expected< MatrixType, GaussianError > covariance () const
std::expected< MatrixType, GaussianError > precision () const
std::expected< MatrixType, GaussianError > covarianceRoot () const
std::expected< MatrixType, GaussianError > precisionRoot () const
template<typename Path>
auto marginal () const
template<typename Path>
auto marginal (Index element) const
 marginal<Path>() of repetition element of the repeated block Path starts at (see GaussianParams::marginal(element)).
std::expected< void, GaussianError > factorize () const
 Checks the root and computes \( \log|\Sigma| = 2 \sum_i \log|S_{ii}| \), writing it to a cache when it has changed, so that a container of components can read their densities (see Component).
template<typename R>
std::expected< void, GaussianError > factorize (R const &) const
 Refused: a root needs no repair, being positive semidefinite by construction, so a mixture of square-root components given a repair does not compile.
std::expected< DensityType, GaussianError > toDensity () const &
 factorize(), so that the cache it writes is not safe on one object from two threads at once while the root changes.
void toDensity () const &&=delete
 A density of a temporary would outlive it.

Static Public Attributes

static constexpr int ValueDimensionAtCompileTime = MomentsType::ValueDimensionAtCompileTime
 the length of a value, or Eigen::Dynamic
static constexpr int MaxValueDimensionAtCompileTime = MomentsType::MaxValueDimensionAtCompileTime
 a bound on the length of a value, or Eigen::Dynamic
static constexpr int DifferenceDimensionAtCompileTime = MomentsType::DifferenceDimensionAtCompileTime
 the length of a difference and the rows of the root, or Eigen::Dynamic
static constexpr int MaxDifferenceDimensionAtCompileTime = MomentsType::MaxDifferenceDimensionAtCompileTime
 a bound on the length of a difference, or Eigen::Dynamic
static constexpr bool IsParams = true
 parameters, which views check
static constexpr bool IsInfoForm = false
 holds a root of the covariance, not the precision
static constexpr bool IsSqrtForm = true
 holds a triangular root

Friends

struct ComponentTraits< SqrtGaussianParams >
 A container's density reads the log-determinant without a view.

Detailed Description

template<Space Space_, RealScalar Scalar_ = double>
class Emrys::SqrtGaussianParams< Space_, Scalar_ >

A Gaussian kept as a mean and a lower-triangular root of its covariance.

The multivariate normal distribution with covariance \( \Sigma = S S^T \), where the lower-triangular \( S \) is what is stored and the covariance is formed only on request (decisions.md [gaussian-forms]). A root is positive semidefinite by construction and represents the covariance at twice the precision of the covariance itself, so a filter that keeps it, updating it by triangularize() rather than by adding and subtracting covariances, never needs the repair that a Repair makes after the fact. The density, its whitening, and draws come from \( S \) directly, where Gaussian has to factorize first.

Only the lower triangle of a root passed in is kept; the upper is set to zero. The diagonal may have either sign, since flipping the sign of a column of \( S \) leaves \( S S^T \) unchanged. A zero on the diagonal makes the covariance singular: covarianceRoot() and covariance() still succeed, and precision(), precisionRoot(), and toDensity() return GaussianError::NotPositiveDefinite.

The space and dimension contract is Gaussian's [sizes-and-dimensions]: the mean is a value with valueDimension() coordinates, normalized whenever it is set, and the root is square over its differences. toDensity() returns a FormGaussian, which checks this object for changes as Gaussian checks a GaussianParams. marginal<Path>() returns parameters, since its root is computed rather than selected; a conditional, insert(), and erase() go through toGaussian() and back.

It is a Component (decisions.md [component-first]), so a MixtureParams or a Hybrid holds it as it holds GaussianParams: factorize() checks the root and caches its log-determinant, and the collapse of several is one triangularization, so a mixture filter or an IMM over the square-root form keeps roots throughout.

Template Parameters
Space_space of the coordinates (see Spaces)
Scalar_scalar type, double by default
See also
toSqrt(), class GaussianParams, GaussianForm

Member Function Documentation

◆ covariance()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< MatrixType, GaussianError > Emrys::SqrtGaussianParams< Space_, Scalar_ >::covariance ( ) const
inlinenodiscard
Returns
the covariance \( S S^T \), formed on request. Never fails.

◆ covarianceRoot()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< MatrixType, GaussianError > Emrys::SqrtGaussianParams< Space_, Scalar_ >::covarianceRoot ( ) const
inlinenodiscard
Returns
the stored root \( S \). Never fails.

◆ differenceDimension()

template<Space Space_, RealScalar Scalar_ = double>
Index Emrys::SqrtGaussianParams< Space_, Scalar_ >::differenceDimension ( ) const
inlinenodiscard
Returns
the number of rows and columns of the root (see Spaces)

◆ factorize()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< void, GaussianError > Emrys::SqrtGaussianParams< Space_, Scalar_ >::factorize ( ) const
inlinenodiscard

Checks the root and computes \( \log|\Sigma| = 2 \sum_i \log|S_{ii}| \), writing it to a cache when it has changed, so that a container of components can read their densities (see Component).

Returns
nothing, or GaussianError::NonFinite or GaussianError::NotPositiveDefinite as precision() returns them

◆ marginal()

template<Space Space_, RealScalar Scalar_ = double>
template<typename Path>
auto Emrys::SqrtGaussianParams< Space_, Scalar_ >::marginal ( ) const
inlinenodiscard
Returns
the marginal of the subspace named by the path Path (a tag or a TagPath), in that subspace, as a SqrtGaussianParams: the mean's entries, and the lower-triangular root of \( S_k S_k^T \) for the root's rows \( S_k \) at the block's differences, by triangularization (internal::lowerTriangularRoot()), so the block's covariance is never formed. Never fails. Unlike GaussianParams::marginal(), it returns parameters, since the root is computed rather than selected.

◆ mean()

template<Space Space_, RealScalar Scalar_ = double>
VectorType const & Emrys::SqrtGaussianParams< Space_, Scalar_ >::mean ( ) const
inlinenodiscard
Returns
the mean, a value in the space

◆ moments()

template<Space Space_, RealScalar Scalar_ = double>
MomentsType Emrys::SqrtGaussianParams< Space_, Scalar_ >::moments ( ) const
inlinenodiscard
Returns
the mean and the covariance \( S S^T \) together, formed on request

◆ precision()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< MatrixType, GaussianError > Emrys::SqrtGaussianParams< Space_, Scalar_ >::precision ( ) const
inlinenodiscard
Returns
the precision \( S^{-T} S^{-1} \), or GaussianError::NotPositiveDefinite if the root has a zero on its diagonal, or GaussianError::NonFinite if it is not finite.

◆ precisionRoot()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< MatrixType, GaussianError > Emrys::SqrtGaussianParams< Space_, Scalar_ >::precisionRoot ( ) const
inlinenodiscard
Returns
\( S^{-1} \), lower triangular, with \( (S^{-1})^T S^{-1} = \Sigma^{-1} \), or the GaussianError of precision()

◆ root()

template<Space Space_, RealScalar Scalar_ = double>
MatrixType const & Emrys::SqrtGaussianParams< Space_, Scalar_ >::root ( ) const
inlinenodiscard
Returns
the stored lower-triangular root \( S \), \( S S^T = \Sigma \), with zeros above the diagonal [roots-and-factors]

◆ space()

template<Space Space_, RealScalar Scalar_ = double>
Space_ const & Emrys::SqrtGaussianParams< Space_, Scalar_ >::space ( ) const
inlinenodiscard
Returns
the space, with its sizes

◆ toDensity()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< DensityType, GaussianError > Emrys::SqrtGaussianParams< Space_, Scalar_ >::toDensity ( ) const &
inlinenodiscard

factorize(), so that the cache it writes is not safe on one object from two threads at once while the root changes.

Threads should share the density instead (see Distributions).

Returns
a FormGaussian that checks this object, or the GaussianError of factorize()

◆ valueDimension()

template<Space Space_, RealScalar Scalar_ = double>
Index Emrys::SqrtGaussianParams< Space_, Scalar_ >::valueDimension ( ) const
inlinenodiscard
Returns
the number of coordinates of the mean (see Spaces)

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