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

The uniform distribution over a box in a space. More...

#include <EmrysFilter/Distributions/Uniform.h>

Public Types

using Scalar = Scalar_
 the scalar type
using Index = Eigen::Index
 Eigen's index type.
using SpaceType = Space_
 the space the values live in
using MomentsType = Moments<Space_, Scalar_>
 a mean and covariance together
using VectorType = typename MomentsType::VectorType
 a value
using MatrixType = typename MomentsType::MatrixType
 a matrix over differences

Public Member Functions

 Uniform (Space_ space={})
 Uniform over the whole of space.
Index valueDimension () const
Index differenceDimension () const
Space_ const & space () const
VectorType const & lower () const
VectorType upper () const
VectorType const & width () const
Scalar logVolume () const
template<typename Derived>
bool contains (Eigen::MatrixBase< Derived > const &x) const
template<typename Derived>
Scalar logDensity (Eigen::MatrixBase< Derived > const &x) const
template<typename Derived>
Scalar density (Eigen::MatrixBase< Derived > const &x) const
MomentsType moments () const
template<typename Path>
auto marginal () const
 marginal() of the subspace named by the tag path Path (see idx()), in that subspace.
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>
auto conditional (Eigen::MatrixBase< Derived > const &values) const

Static Public Member Functions

template<MatrixExpression Lower, typename UpperDerived>
static std::expected< Uniform, UniformError > create (Space_ space, Lower &&lower, Eigen::MatrixBase< UpperDerived > const &upper)
template<MatrixExpression Lower, typename UpperDerived>
requires internal::SizedByLength<Space_>
static std::expected< Uniform, UniformError > create (Lower &&lower, Eigen::MatrixBase< UpperDerived > const &upper)
 create() in the default space.

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 a covariance, or Eigen::Dynamic
static constexpr int MaxDifferenceDimensionAtCompileTime = MomentsType::MaxDifferenceDimensionAtCompileTime
 a bound on the length of a difference, or Eigen::Dynamic

Friends

template<Space, RealScalar>
class Uniform
 Marginals build another instantiation from checked parts.

Detailed Description

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

The uniform distribution over a box in a space.

Each coordinate \( i \) is uniform on an interval of width \( w_i \) starting at \( \ell_i \), independently, so the density is \( 1 / \prod_i w_i \) inside the box and zero outside.

The space supplies the default box where it can: a Periodic coordinate is uniform over one whole period, and that constructor cannot fail. A Linear coordinate has no default and needs a box, which create() checks, since bounds are often computed at run time. A Periodic coordinate's interval may cross the seam: [3, 3.5] on an angle covers [3, π) and [-π, 3.5 - 2π].

auto const heading = Uniform<Heading>{}; // one whole period
auto const box = Uniform<Position>::create(Eigen::Vector2d{0, 0}, Eigen::Vector2d{10, 5}); // or a UniformError
static std::expected< Uniform, UniformError > create(Space_ space, Lower &&lower, Eigen::MatrixBase< UpperDerived > const &upper)
Definition Uniform.h:128
friend class Uniform
Marginals build another instantiation from checked parts.
Definition Uniform.h:323

A Uniform is an immutable value that owns its box [checked-factories].

Template Parameters
Space_space of the coordinates (see Spaces)
Scalar_scalar type
See also
drawSamples(Uniform const &, Eigen::Index, G &)

Constructor & Destructor Documentation

◆ Uniform()

template<Space Space_, RealScalar Scalar_ = double>
Emrys::Uniform< Space_, Scalar_ >::Uniform ( Space_ space = {})
inlineexplicit

Uniform over the whole of space.

Every coordinate must be Periodic.

Member Function Documentation

◆ conditional()

template<Space Space_, RealScalar Scalar_ = double>
template<typename GivenPath, typename Derived>
auto Emrys::Uniform< 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 equals values, in the space of the remaining blocks (see GaussianParams::conditional()): since the coordinates are independent, their marginal. Values outside the box have zero density, so strictly the conditional is undefined there; this returns the marginal anyway.

◆ contains()

template<Space Space_, RealScalar Scalar_ = double>
template<typename Derived>
bool Emrys::Uniform< Space_, Scalar_ >::contains ( Eigen::MatrixBase< Derived > const & x) const
inlinenodiscard
Returns
whether x lies in the box, taking a Periodic coordinate's interval around the circle

◆ create()

template<Space Space_, RealScalar Scalar_ = double>
template<MatrixExpression Lower, typename UpperDerived>
std::expected< Uniform, UniformError > Emrys::Uniform< Space_, Scalar_ >::create ( Space_ space,
Lower && lower,
Eigen::MatrixBase< UpperDerived > const & upper )
inlinestaticnodiscard
Returns
the uniform distribution over the box from lower to upper in space, moving lower if it is an rvalue of the stored type, or a UniformError if a bound is not finite, an upper bound is not above its lower bound, or an interval on a Periodic coordinate is wider than one period. A space with one resizable block is resized to fit.

◆ density()

template<Space Space_, RealScalar Scalar_ = double>
template<typename Derived>
Scalar Emrys::Uniform< Space_, Scalar_ >::density ( Eigen::MatrixBase< Derived > const & x) const
inlinenodiscard
Returns
the density at x

◆ differenceDimension()

template<Space Space_, RealScalar Scalar_ = double>
Index Emrys::Uniform< Space_, Scalar_ >::differenceDimension ( ) const
inlinenodiscard
Returns
the same: the box has plain differences

◆ logDensity()

template<Space Space_, RealScalar Scalar_ = double>
template<typename Derived>
Scalar Emrys::Uniform< Space_, Scalar_ >::logDensity ( Eigen::MatrixBase< Derived > const & x) const
inlinenodiscard
Returns
the log of the density at x: \( -\log \prod_i w_i \) inside the box, and \( -\infty \) outside

◆ logVolume()

template<Space Space_, RealScalar Scalar_ = double>
Scalar Emrys::Uniform< Space_, Scalar_ >::logVolume ( ) const
inlinenodiscard
Returns
the log of the box's volume, \( \sum_i \log w_i \)

◆ lower()

template<Space Space_, RealScalar Scalar_ = double>
VectorType const & Emrys::Uniform< Space_, Scalar_ >::lower ( ) const
inlinenodiscard
Returns
the start \( \ell \) of each coordinate's interval, as given

◆ moments()

template<Space Space_, RealScalar Scalar_ = double>
MomentsType Emrys::Uniform< Space_, Scalar_ >::moments ( ) const
inlinenodiscard
Returns
the mean and covariance: the box's center, normalized, and \( \mathrm{diag}(w_i^2 / 12) \), the variance of a uniform interval of width \( w_i \).

For a Periodic coordinate these are tangent-space moments about the interval's center. Over a whole period every point is equally a center, so the reported mean is arbitrary and the variance \( p^2 / 12 \) only says the coordinate is unknown.

◆ space()

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

◆ upper()

template<Space Space_, RealScalar Scalar_ = double>
VectorType Emrys::Uniform< Space_, Scalar_ >::upper ( ) const
inlinenodiscard
Returns
the end \( \ell + w \) of each coordinate's interval, not normalized: on a Periodic coordinate it may lie past the space's range

◆ valueDimension()

template<Space Space_, RealScalar Scalar_ = double>
Index Emrys::Uniform< Space_, Scalar_ >::valueDimension ( ) const
inlinenodiscard
Returns
the number of coordinates of the box

◆ width()

template<Space Space_, RealScalar Scalar_ = double>
VectorType const & Emrys::Uniform< Space_, Scalar_ >::width ( ) const
inlinenodiscard
Returns
the width \( w \) of each coordinate's interval

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