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

A Gaussian kept as its precision and information vector, about a reference value. More...

#include <EmrysFilter/Distributions/InfoGaussian.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 information vector.
using MatrixType = typename MomentsType::MatrixType
 a matrix over differences
using SpaceType = Space_
 the space the values live in
using DensityType = FormGaussian<InfoGaussianParams>
 the view toDensity() returns

Public Member Functions

 InfoGaussianParams ()
 Constructs an InfoGaussianParams in a default space, with a zero reference and no information.
 InfoGaussianParams (Space_ space)
 Constructs an InfoGaussianParams in space, with a zero reference and no information.
template<MatrixExpression Reference, MatrixExpression Matrix, MatrixExpression Vector>
requires internal::SizedByLength<Space_>
 InfoGaussianParams (Reference &&reference, Matrix &&infoMatrix, Vector &&infoVector)
 Constructs an InfoGaussianParams about reference, with the lower triangle of infoMatrix as the precision and infoVector as \( \eta \), moving any passed as an rvalue of the stored type, in a default space resized to fit them.
template<MatrixExpression Reference, MatrixExpression Matrix, MatrixExpression Vector>
 InfoGaussianParams (Space_ space, Reference &&reference, Matrix &&infoMatrix, Vector &&infoVector)
 InfoGaussianParams(reference, infoMatrix, infoVector) in space, which is resized to fit them if it has one resizable block.
 InfoGaussianParams (InfoGaussianParams const &other)
 Copies the data and any valid factorization.
 InfoGaussianParams (InfoGaussianParams &&other) noexcept
 Moves the data and any valid factorization; a view of other may not be read afterward.
InfoGaussianParams & operator= (InfoGaussianParams const &other)
 Copies the data and any valid factorization; a view of this object may not be read afterward.
InfoGaussianParams & operator= (InfoGaussianParams &&other) noexcept
 Moves the data and any valid factorization; a view of either object may not be read afterward.
Index valueDimension () const
Index differenceDimension () const
Space_ const & space () const
VectorType const & reference () const
MatrixType const & infoMatrix () const
DifferenceVectorType const & 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 information about it.
template<MatrixExpression Matrix, MatrixExpression Vector>
void setInfo (Matrix &&infoMatrix, Vector &&infoVector)
 Sets the precision to the lower triangle of infoMatrix and the information vector to infoVector, about the current reference, moving either one passed as an rvalue of the stored type, and invalidates the factorization.
template<typename MatrixDerived, typename VectorDerived>
void addInfo (Eigen::MatrixBase< MatrixDerived > const &infoMatrix, Eigen::MatrixBase< VectorDerived > const &infoVector)
 Adds infoMatrix (its lower triangle) to the precision and infoVector to the information vector, both about the current reference: independent information, such as \( H^T R^{-1} H \) and \( H^T R^{-1} (z - h(x_0)) \) from a measurement linearized at the reference.
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< void, GaussianError > factorize () const
 Factorizes the precision if it has changed since the last factorization.
std::expected< DensityType, GaussianError > toDensity () const &
 Factorizes the precision if needed (see factorize()) and solves for the mean, writing both to the cache, 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 precision, 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 the precision
static constexpr bool IsSqrtForm = false
 holds the precision whole, not a factor

Detailed Description

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

A Gaussian kept as its precision and information vector, about a reference value.

The multivariate normal distribution in canonical (information) form: the precision \( \Lambda = \Sigma^{-1} \) and the information vector \( \eta = \Lambda \delta \), where the mean is \( \mu = x_0 \boxplus \delta \) for the stored reference value \( x_0 \). On a linear space the reference is only an origin; on a space with \( \boxplus \) the information lives in the differences at it, as a covariance lives in the differences at a mean, and moving the reference carries it by the reset Jacobian of decisions.md [covariance-reset] (setReference()).

The form's free operation is the one the covariance form pays for: combining independent information about the same state, from a measurement or another factor, adds precisions and information vectors (addInfo(), multiply()). Its cost is the mean, a solve with \( \Lambda \). And it states what the covariance form cannot: a prior with no information at all, \( \Lambda = 0 \), which is well defined here until something asks for the mean, the covariance, or the density, each of which returns GaussianError::Singular while \( \Lambda \) is not positive definite [gaussian-forms].

Only the lower triangle of the precision is read, as only that of a Gaussian's covariance is. The Cholesky factorization of the precision is cached, as Gaussian caches its covariance's, and survives changes to the information vector. The matrices the accessors give, the precision, the covariance, and their factors, 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 an InfoGaussian, which checks this object for changes as Gaussian checks a GaussianParams. marginal<Path>() and conditional<Path>() return parameters, since their matrices are computed rather than selected. The density's marginal<Path>() cannot fail, as this one's can (decisions.md [form-densities]).

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

Constructor & Destructor Documentation

◆ InfoGaussianParams()

template<Space Space_, RealScalar Scalar_ = double>
Emrys::InfoGaussianParams< Space_, Scalar_ >::InfoGaussianParams ( InfoGaussianParams< Space_, Scalar_ > const & other)
inline

Copies the data and any valid factorization.

Views of other do not see the copy.

Member Function Documentation

◆ addInfo()

template<Space Space_, RealScalar Scalar_ = double>
template<typename MatrixDerived, typename VectorDerived>
void Emrys::InfoGaussianParams< Space_, Scalar_ >::addInfo ( Eigen::MatrixBase< MatrixDerived > const & infoMatrix,
Eigen::MatrixBase< VectorDerived > const & infoVector )
inline

Adds infoMatrix (its lower triangle) to the precision and infoVector to the information vector, both about the current reference: independent information, such as \( H^T R^{-1} H \) and \( H^T R^{-1} (z - h(x_0)) \) from a measurement linearized at the reference.

Exact, and independent of the order in which information arrives. Invalidates the factorization.

◆ conditional()

template<Space Space_, RealScalar Scalar_ = double>
template<typename GivenPath, typename Derived>
auto Emrys::InfoGaussianParams< 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: an InfoGaussianParams in the space of the remaining blocks, about the matching entries of the reference.

Conditioning in the information form takes a block, where the covariance form solves: the precision is \( \Lambda_{tt} \) and the information vector \( \eta_t - \Lambda_{tg} (v \boxminus x_{0,g}) \), from the canonical form of the joint with the given offset fixed. Never fails. There is no conditionalWithEvidence(): the evidence needs the given block's marginal covariance, which this form does not hold (decisions.md [conditional-evidence]).

◆ covariance()

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

◆ covarianceRoot()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< MatrixType, GaussianError > Emrys::InfoGaussianParams< Space_, Scalar_ >::covarianceRoot ( ) const
inlinenodiscard
Returns
\( R^{-1} \) for the upper-triangular Cholesky factor \( R \) of the precision: upper triangular, with \( R^{-1} R^{-T} = \Sigma \). Or the GaussianError of factorize().

◆ differenceDimension()

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

◆ factorize()

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

Factorizes the precision if it has changed since the last factorization.

It is const because it writes only the cached factorization, which the accessors that need it also fill, so none of them is safe on one object from two threads at once until a factorization has succeeded. toDensity() writes the solved mean each time. Threads should share the density instead (see Distributions).

Returns
nothing on success, GaussianError::Singular if the precision is not positive definite, as it is not while some direction has no information, or GaussianError::NonFinite if it is not finite.

◆ infoMatrix()

template<Space Space_, RealScalar Scalar_ = double>
MatrixType const & Emrys::InfoGaussianParams< Space_, Scalar_ >::infoMatrix ( ) const
inlinenodiscard
Returns
the stored precision \( \Lambda \); only its lower triangle is guaranteed to be read

◆ infoVector()

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

◆ marginal()

template<Space Space_, RealScalar Scalar_ = double>
template<typename Path>
auto Emrys::InfoGaussianParams< 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 an InfoGaussianParams about the matching entries of the reference, or GaussianError::Singular if the precision of the rest is not positive definite, or GaussianError::NonFinite if it is not finite.

Marginalizing in the information form is the Schur complement of the rest \( r \) in the precision, \( \Lambda_{kk} - \Lambda_{kr} \Lambda_{rr}^{-1} \Lambda_{rk} \), with \( \eta_k - \Lambda_{kr} \Lambda_{rr}^{-1} \eta_r \): a solve, where the covariance form takes a block. Unlike GaussianParams::marginal(), it returns parameters, since the result is computed rather than selected.

◆ mean()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< VectorType, GaussianError > Emrys::InfoGaussianParams< Space_, Scalar_ >::mean ( ) const
inlinenodiscard
Returns
the mean \( x_0 \boxplus \Lambda^{-1} \eta \), solved with the cached factorization, or the GaussianError of factorize().

◆ moments()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< MomentsType, GaussianError > Emrys::InfoGaussianParams< Space_, Scalar_ >::moments ( ) const
inlinenodiscard
Returns
the mean and the covariance together, both solved with the cached factorization, the covariance carried to the differences at the mean as toGaussian() carries it, or the GaussianError of factorize()

◆ precision()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< MatrixType, GaussianError > Emrys::InfoGaussianParams< Space_, Scalar_ >::precision ( ) const
inlinenodiscard
Returns
the precision, with both triangles filled from the lower one. Never fails.

◆ precisionRoot()

template<Space Space_, RealScalar Scalar_ = double>
std::expected< MatrixType, GaussianError > Emrys::InfoGaussianParams< Space_, Scalar_ >::precisionRoot ( ) const
inlinenodiscard
Returns
the upper-triangular Cholesky factor \( R \) of the precision, with \( R^T R = \Lambda \), or the GaussianError of factorize()

◆ reference()

template<Space Space_, RealScalar Scalar_ = double>
VectorType const & Emrys::InfoGaussianParams< 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::InfoGaussianParams< Space_, Scalar_ >::setReference ( Eigen::MatrixBase< Derived > const & reference)
inline

Moves the reference to reference, normalized by the space, and re-expresses the information 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()),

\[ \Lambda' = G^{-T} \Lambda G^{-1}, \qquad \eta' = G^{-T} (\eta - \Lambda d), \]

which is the quadratic form of the density written in the differences at the new reference, where an error \( \epsilon \) at \( x_0 \) is \( G (\epsilon - d) \). On a space with an identity reset \( G \) is the identity, the distribution is unchanged exactly, and the factorization survives; elsewhere it is the first-order transport of [covariance-reset] and the factorization is invalidated.

◆ space()

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

◆ toDensity()

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

Factorizes the precision if needed (see factorize()) and solves for the mean, writing both to the cache, so it is not safe on one object from two threads at once.

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

◆ valueDimension()

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

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