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

Independent Gamma distributions on the coordinates, for positive quantities such as ranges, speeds, and rates. More...

#include <EmrysFilter/Distributions/Gamma.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

Index valueDimension () const
Index differenceDimension () const
Space_ const & space () const
VectorType const & shape () const
VectorType const & scale () 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<typename Shape, typename Scale>
static std::expected< Gamma, GammaError > create (Space_ space, Shape const &shape, Scale const &scale)
template<typename Shape, typename Scale>
requires internal::SizedByLength<Space_>
static std::expected< Gamma, GammaError > create (Shape const &shape, Scale const &scale)
 create() in the default space.
template<typename Scale>
static std::expected< Gamma, GammaError > exponential (Space_ space, Scale const &scale)
template<typename Scale>
static std::expected< Gamma, GammaError > exponential (Scale const &scale)
 exponential() in the default space.
template<typename Dof>
static std::expected< Gamma, GammaError > chiSquared (Space_ space, Dof const &dof)
template<typename Dof>
static std::expected< Gamma, GammaError > chiSquared (Dof const &dof)
 chiSquared() in the default space.
template<typename Mean, typename StdDev>
static std::expected< Gamma, GammaError > fromMeanAndStdDev (Space_ space, Mean const &mean, StdDev const &stdDev)
template<typename Mean, typename StdDev>
static std::expected< Gamma, GammaError > fromMeanAndStdDev (Mean const &mean, StdDev const &stdDev)
 fromMeanAndStdDev() 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 Gamma
 Marginals build another instantiation from checked parts.

Detailed Description

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

Independent Gamma distributions on the coordinates, for positive quantities such as ranges, speeds, and rates.

The gamma distribution in its shape and scale parameterization. Coordinate \( i \) has shape \( k_i \) and scale \( \theta_i \):

\[ p(x_i) = \frac{x_i^{k_i - 1} e^{-x_i / \theta_i}}{\Gamma(k_i)\, \theta_i^{k_i}}, \quad x_i \ge 0, \]

with mean \( k_i \theta_i \) and variance \( k_i \theta_i^2 \). A shape of 1 is the exponential distribution (see exponential()); shape \( \nu / 2 \) with scale 2 is \( \chi^2_\nu \) (see chiSquared()). A shape above 1 puts the mode at \( (k - 1) \theta \), away from zero; fromMeanAndStdDev() picks the shape and scale for a given mean and spread.

auto const speed = Gamma<Speed>::create(4.0, 0.5); // or a GammaError
auto const rate = Gamma<Rate>::fromMeanAndStdDev(2.0, 0.5); // shape 16, scale 0.125
static std::expected< Gamma, GammaError > create(Space_ space, Shape const &shape, Scale const &scale)
Definition Gamma.h:158
static std::expected< Gamma, GammaError > fromMeanAndStdDev(Space_ space, Mean const &mean, StdDev const &stdDev)
Definition Gamma.h:224

Every coordinate's space must contain all of [0, ∞) without wrapping it, as Linear does. The support is the distribution's own: the density is zero below zero, and no space keeps a value from going there [no-bounded-coordinates].

A Gamma is an immutable value that owns its parameters. Its factories check them, since a shape or scale is often computed at run time, and return a GammaError if one is not positive and finite; it has no public constructor [checked-factories].

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

Member Function Documentation

◆ chiSquared()

template<Space Space_, RealScalar Scalar_ = double>
template<typename Dof>
std::expected< Gamma, GammaError > Emrys::Gamma< Space_, Scalar_ >::chiSquared ( Space_ space,
Dof const & dof )
inlinestaticnodiscard
Returns
\( \chi^2 \) with dof degrees of freedom in space: shape \( \nu / 2 \), scale 2; or a GammaError if a number of degrees of freedom is not positive and finite

◆ conditional()

template<Space Space_, RealScalar Scalar_ = double>
template<typename GivenPath, typename Derived>
auto Emrys::Gamma< 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. Negative values have zero density, so strictly the conditional is undefined there; this returns the marginal anyway.

◆ create()

template<Space Space_, RealScalar Scalar_ = double>
template<typename Shape, typename Scale>
std::expected< Gamma, GammaError > Emrys::Gamma< Space_, Scalar_ >::create ( Space_ space,
Shape const & shape,
Scale const & scale )
inlinestaticnodiscard
Returns
the Gamma with shape shape and scale scale in space, or a GammaError if a shape or scale is not positive and finite. Each is a vector with one entry per coordinate, or a scalar shared by every coordinate. A space with one resizable block is resized to a vector parameter's size; with only scalars it keeps its own size.

◆ density()

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

◆ differenceDimension()

template<Space Space_, RealScalar Scalar_ = double>
Index Emrys::Gamma< Space_, Scalar_ >::differenceDimension ( ) const
inlinenodiscard
Returns
the same: the coordinates have plain differences

◆ exponential()

template<Space Space_, RealScalar Scalar_ = double>
template<typename Scale>
std::expected< Gamma, GammaError > Emrys::Gamma< Space_, Scalar_ >::exponential ( Space_ space,
Scale const & scale )
inlinestaticnodiscard
Returns
the exponential distribution with mean scale (rate \( 1 / \theta \)) in space, or a GammaError if a scale is not positive and finite

◆ fromMeanAndStdDev()

template<Space Space_, RealScalar Scalar_ = double>
template<typename Mean, typename StdDev>
std::expected< Gamma, GammaError > Emrys::Gamma< Space_, Scalar_ >::fromMeanAndStdDev ( Space_ space,
Mean const & mean,
StdDev const & stdDev )
inlinestaticnodiscard
Returns
the Gamma distribution with mean mean and standard deviation stdDev in space: shape \( (\mu / \sigma)^2 \) and scale \( \sigma^2 / \mu \). A mean or standard deviation that is not positive and finite gives a shape or scale that is not either, and so a GammaError.

◆ logDensity()

template<Space Space_, RealScalar Scalar_ = double>
template<typename Derived>
Scalar Emrys::Gamma< Space_, Scalar_ >::logDensity ( Eigen::MatrixBase< Derived > const & x) const
inlinenodiscard
Returns
the log of the density at x, \( -\infty \) if any coordinate is negative

◆ moments()

template<Space Space_, RealScalar Scalar_ = double>
MomentsType Emrys::Gamma< Space_, Scalar_ >::moments ( ) const
inlinenodiscard
Returns
the mean \( k \theta \) and the diagonal covariance \( k \theta^2 \)

◆ scale()

template<Space Space_, RealScalar Scalar_ = double>
VectorType const & Emrys::Gamma< Space_, Scalar_ >::scale ( ) const
inlinenodiscard
Returns
the scale \( \theta \) of each coordinate

◆ shape()

template<Space Space_, RealScalar Scalar_ = double>
VectorType const & Emrys::Gamma< Space_, Scalar_ >::shape ( ) const
inlinenodiscard
Returns
the shape \( k \) of each coordinate

◆ space()

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

◆ valueDimension()

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

The documentation for this class was generated from the following file:
  • EmrysFilter/Distributions/Gamma.h