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

A Gaussian kept as an upper-triangular root of its precision and a whitened offset, about a reference value. More...

#include <EmrysFilter/Distributions/SqrtInfoGaussian.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 reference
using DifferenceVectorType = typename MomentsType::DifferenceVectorType
 a difference, or the whitened offset
using MatrixType = typename MomentsType::MatrixType
 a matrix over differences
using SpaceType = Space_
 the space the values live in
using DensityType = FormGaussian<SqrtInfoGaussianParams>
 the view toDensity() returns

Public Member Functions

 SqrtInfoGaussianParams ()
 Constructs a SqrtInfoGaussianParams in a default space, with a zero reference and no information.
 SqrtInfoGaussianParams (Space_ space)
 Constructs a SqrtInfoGaussianParams in space, with a zero reference and no information.
template<MatrixExpression Reference, MatrixExpression Root, MatrixExpression Offset>
requires internal::SizedByLength<Space_>
 SqrtInfoGaussianParams (Reference &&reference, Root &&root, Offset &&whitenedOffset)
 Constructs a SqrtInfoGaussianParams about reference, with the upper triangle of root as \( R \) and whitenedOffset as \( r \), moving any passed as an rvalue of the stored type, in a default space resized to fit them.
template<MatrixExpression Reference, MatrixExpression Root, MatrixExpression Offset>
 SqrtInfoGaussianParams (Space_ space, Reference &&reference, Root &&root, Offset &&whitenedOffset)
 SqrtInfoGaussianParams(reference, root, whitenedOffset) 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 & reference () const
MatrixType const & infoRoot () const
DifferenceVectorType const & whitenedOffset () const
DifferenceVectorType infoVector () const
template<typename Derived>
void setReference (Eigen::MatrixBase< Derived > const &reference)
 Moves the reference to reference, normalized by the space, and re-expresses the data array about it.
template<MatrixExpression Root, MatrixExpression Offset>
void setRoot (Root &&root, Offset &&whitenedOffset)
 Sets \( R \) to the upper triangle of root and \( r \) to whitenedOffset, about the current reference, moving either one passed as an rvalue of the stored type.
std::expected< VectorType, GaussianError > mean () const
std::expected< MomentsType, GaussianError > moments () const
std::expected< MatrixType, GaussianError > covariance () const
std::expected< MatrixType, GaussianError > precision () const
std::expected< MatrixType, GaussianError > covarianceRoot () const
std::expected< MatrixType, GaussianError > precisionRoot () const
std::expected< DensityType, GaussianError > toDensity () const &
 Checks the root, solves for the mean, and computes \( \log|\Sigma| = -2 \sum_i \log|R_{ii}| \), writing both to a cache each time, so it is not safe on one object from two threads at once.
void toDensity () const &&=delete
 A density of a temporary would outlive it.
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)).
template<typename GivenPath, typename Derived>
auto conditional (Eigen::MatrixBase< Derived > const &values) const

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 = true
 holds a root of the precision
static constexpr bool IsSqrtForm = true
 holds a triangular root

Detailed Description

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

A Gaussian kept as an upper-triangular root of its precision and a whitened offset, about a reference value.

The square-root information form of Bierman (1977) (Ke et al. (2024), §II): an upper-triangular \( R \) with \( R^T R = \Lambda \), and \( r = R \delta \), where the mean is \( \mu = x_0 \boxplus \delta \) for the stored reference value \( x_0 \). The pair is the data array \( [\,R \;\; z\,] \), with the state solving \( R x = z \); here \( x \) is the offset from the reference, as in InfoGaussianParams, so that the information lives in the differences at \( x_0 \) on a space with \( \boxplus \), and moving the reference carries it by the reset Jacobian of decisions.md [covariance-reset] (setReference()).

It combines the information form's strengths with the square root's: independent information is combined by stacking whitened rows under \( [\,R \;\; r\,] \) and triangularizing (triangularize(), multiply()), which never fails and never forms \( \Lambda \), and a prior with no information is \( R = 0 \). The mean, the covariance, and the density are triangular solves with \( R \), which return GaussianError::Singular while it has a zero on its diagonal.

Only the upper triangle of a root passed in is kept; the lower is set to zero. The diagonal may have either sign, since flipping a row of \( [\,R \;\; r\,] \) leaves \( R^T R \) and \( \delta \) unchanged. The matrices the accessors give are in the differences at the reference; moments() and the conversions to a covariance form carry the covariance to the differences at the mean [covariance-reset]. toDensity() returns a FormGaussian, which checks this object for changes as Gaussian checks a GaussianParams. marginal<Path>() and conditional<Path>() return parameters, since their roots are computed rather than selected.

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

Member Function Documentation

◆ conditional()

template<Space Space_, RealScalar Scalar_ = double>
template<typename GivenPath, typename Derived>
auto Emrys::SqrtInfoGaussianParams< Space_, Scalar_ >::conditional ( Eigen::MatrixBase< Derived > const & values) const
inlinenodiscard
Returns
the distribution of the other coordinates given that the subspace named by the path GivenPath (a tag or a TagPath) equals values, which are in that subspace: a SqrtInfoGaussianParams in the space of the remaining blocks, about the matching entries of the reference.

With \( \delta_g = v \boxminus x_{0,g} \) the given offset, the target's data array is the triangularization of \( [\,R_{:t} \;\; r - R_{:g} \delta_g\,] \), whose top rows give \( R_{tt}^T R_{tt} = \Lambda_{tt} \) and \( R_{tt}^T r_t = \eta_t - \Lambda_{tg} \delta_g \), the conditional of InfoGaussianParams::conditional() in factored form. Never fails, and has no conditionalWithEvidence(), as InfoGaussianParams has none.

◆ covariance()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< MatrixType, GaussianError > Emrys::SqrtInfoGaussianParams< Space_, Scalar_ >::covariance ( ) const
inlinenodiscard
Returns
the covariance \( R^{-1} R^{-T} \), in the differences at the reference, or the GaussianError of mean()

◆ covarianceRoot()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< MatrixType, GaussianError > Emrys::SqrtInfoGaussianParams< Space_, Scalar_ >::covarianceRoot ( ) const
inlinenodiscard
Returns
\( R^{-1} \), upper triangular, with \( R^{-1} R^{-T} = \Sigma \), or the GaussianError of mean()

◆ differenceDimension()

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

◆ infoRoot()

template<Space Space_, RealScalar Scalar_ = double>
MatrixType const & Emrys::SqrtInfoGaussianParams< Space_, Scalar_ >::infoRoot ( ) const
inlinenodiscard
Returns
the stored upper-triangular root \( R \) of the precision, \( R^T R = \Lambda \), with zeros below the diagonal: named for the information form, since \( R \) is no root of the covariance [roots-and-factors]

◆ infoVector()

template<Space Space_, RealScalar Scalar_ = double>
DifferenceVectorType Emrys::SqrtInfoGaussianParams< Space_, Scalar_ >::infoVector ( ) const
inlinenodiscard
Returns
the information vector \( \eta = \Lambda \delta = R^T r \) about the reference

◆ marginal()

template<Space Space_, RealScalar Scalar_ = double>
template<typename Path>
auto Emrys::SqrtInfoGaussianParams< 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 SqrtInfoGaussianParams about the matching entries of the reference, or GaussianError::Singular if the rest's root is singular.

The data array's columns are reordered with the rest \( r \) first and the kept block \( k \) after it, and triangularized:

\[ Q^T \begin{bmatrix} R_{:r} & R_{:k} & r \end{bmatrix} = \begin{bmatrix} R_{rr} & R_{rk} & r_r \\ 0 & R_{kk} & r_k \end{bmatrix}, \]

whose trailing block is the marginal, \( R_{kk}^T R_{kk} \) being the Schur complement of \( \Lambda_{rr} \) in \( \Lambda \) and \( R_{kk}^T r_k \) the matching information vector, when \( R_{rr} \) is nonsingular. This is the orthogonal elimination of variables from a data array of Bierman (1977), as Ke et al. (2024), §III-D, apply it to marginalize states; a time update eliminates the process noise, and here it eliminates the rest of the state. Nothing is inverted, and a bounded space allocates nothing.

◆ mean()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< VectorType, GaussianError > Emrys::SqrtInfoGaussianParams< Space_, Scalar_ >::mean ( ) const
inlinenodiscard
Returns
the mean \( x_0 \boxplus R^{-1} r \), or GaussianError::Singular if \( R \) has a zero on its diagonal, or GaussianError::NonFinite if it is not finite

◆ moments()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< MomentsType, GaussianError > Emrys::SqrtInfoGaussianParams< Space_, Scalar_ >::moments ( ) const
inlinenodiscard
Returns
the mean and the covariance together, by triangular solves, the covariance carried to the differences at the mean as toGaussian() carries it, or the GaussianError of mean()

◆ precision()

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

◆ precisionRoot()

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

◆ reference()

template<Space Space_, RealScalar Scalar_ = double>
VectorType const & Emrys::SqrtInfoGaussianParams< Space_, Scalar_ >::reference ( ) const
inlinenodiscard
Returns
the reference value \( x_0 \), at whose differences the information lives

◆ setReference()

template<Space Space_, RealScalar Scalar_ = double>
template<typename Derived>
void Emrys::SqrtInfoGaussianParams< Space_, Scalar_ >::setReference ( Eigen::MatrixBase< Derived > const & reference)
inline

Moves the reference to reference, normalized by the space, and re-expresses the data array about it.

With \( d = x_0' \boxminus x_0 \) the step and \( G \) the reset Jacobian of the space at \( x_0 \) and \( d \) (decisions.md [covariance-reset], resetJacobian()), the new array is the triangularization of \( [\,R G^{-1} \;\; r - R d\,] \), which is InfoGaussianParams::setReference()'s \( \Lambda' = G^{-T} \Lambda G^{-1} \) and \( \eta' = G^{-T}(\eta - \Lambda d) \) in factored form. On a space with an identity reset \( G \) is the identity and only \( r \) changes, exactly.

◆ space()

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

◆ toDensity()

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

Checks the root, solves for the mean, and computes \( \log|\Sigma| = -2 \sum_i \log|R_{ii}| \), writing both to a cache each time, so it is not safe on one object from two threads at once.

Threads should share the density instead (see Distributions).

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

◆ valueDimension()

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

◆ whitenedOffset()

template<Space Space_, RealScalar Scalar_ = double>
DifferenceVectorType const & Emrys::SqrtInfoGaussianParams< Space_, Scalar_ >::whitenedOffset ( ) const
inlinenodiscard
Returns
the whitened offset \( r = R \delta \) of the mean from the reference

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