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

The probabilities of a CategoricalParams whose weights define a distribution: a read-only view. More...

#include <EmrysFilter/Distributions/Categorical.h>

Public Types

using ParamsType = CategoricalParams<Space_, Scalar_>
 the parameters it reads
using Scalar = Scalar_
 the scalar type of the probabilities
using SpaceType = Space_
 the discrete space
using ArrayType = typename ParamsType::ArrayType
 one entry per value, in flat-index order

Public Member Functions

Space_ const & space () const
Eigen::Index cardinality () const
auto logProbabilities () const
auto probabilities () const
Scalar logProbability (Eigen::Index value) const
Scalar probability (Eigen::Index value) const
template<typename... Values>
requires (sizeof...(Values) > 0)
Scalar logProbability () const
template<typename... Values>
requires (sizeof...(Values) > 0)
Scalar probability () const
Scalar entropy () const
Eigen::Index mostProbable () const
template<typename P>
auto marginal () const
template<typename P>
auto conditional (Eigen::Index value) const
template<typename Value>
auto conditional () const

Static Public Attributes

static constexpr int CardinalityAtCompileTime
 the number of values, or Eigen::Dynamic
static constexpr int MaxCardinalityAtCompileTime
 a bound on it, or Eigen::Dynamic
static constexpr bool IsParams = false
 a view: it checks its parameters

Detailed Description

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
class Emrys::Categorical< Space_, Scalar_ >

The probabilities of a CategoricalParams whose weights define a distribution: a read-only view.

Obtained from CategoricalParams::toDensity(), which checks the weights once and gives this view the log of their total, so a value's log-probability is its log-weight minus that total and nothing is copied. It checks its parameters for changes, as its copies do: reading it after they have changed is a programmer error (decisions.md [view-stamp]). A Categorical must not outlive its parameters.

A set of values is named by tag: probability<Turn>() is the probability of every value whose Maneuver is Turn, and probability<Turn, Outlier>() of the one value with both.

auto const params = CategoricalParams<Mode>::fromWeights(0.6, 0.1, 0.25, 0.05);
auto const p = params.toDensity().value();
p.probability<Turn>(); // 0.3
p.marginal<Sensor>(); // CategoricalParams<Sensor>: 0.85, 0.15
p.conditional<Turn>(); // CategoricalParams<Sensor> given Turn: 0.833, 0.167
static CategoricalParams fromWeights(Space_ space, Eigen::DenseBase< Derived > const &weights)
Definition Categorical.h:294
See also
class CategoricalParams

Member Function Documentation

◆ cardinality()

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
Eigen::Index Emrys::Categorical< Space_, Scalar_ >::cardinality ( ) const
inlinenodiscard
Returns
the number of values

◆ conditional() [1/2]

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
template<typename Value>
auto Emrys::Categorical< Space_, Scalar_ >::conditional ( ) const
inlinenodiscard
Returns
the parameters of the other axes given the named value Value; see CategoricalParams::conditional()

◆ conditional() [2/2]

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
template<typename P>
auto Emrys::Categorical< Space_, Scalar_ >::conditional ( Eigen::Index value) const
inlinenodiscard
Returns
the parameters of the other axes given that the axis named by the path P has the value with index value in it; see CategoricalParams::conditional()

◆ entropy()

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
Scalar Emrys::Categorical< Space_, Scalar_ >::entropy ( ) const
inlinenodiscard
Returns
the entropy in nats, \( H(p) = -\sum_v p_v \log p_v \), with a value of probability zero contributing nothing

It is 0 for a single certain value and \( \log n \) for the uniform distribution on \( n \) values, the most there is. Its exponential, the perplexity, is the number of equally likely values that would be as uncertain.

See also
mostProbable(), kullbackLeibler()

◆ logProbabilities()

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
auto Emrys::Categorical< Space_, Scalar_ >::logProbabilities ( ) const
inlinenodiscard
Returns
the log-probability of each value, a lazy Eigen expression that must not outlive the parameters

◆ logProbability() [1/2]

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
template<typename... Values>
requires (sizeof...(Values) > 0)
Scalar Emrys::Categorical< Space_, Scalar_ >::logProbability ( ) const
inlinenodiscard
Returns
the log-probability of the values that have every named value in Values, each a value's tag or a TagPath ending in one: one value if every axis is named, otherwise a marginal

◆ logProbability() [2/2]

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
Scalar Emrys::Categorical< Space_, Scalar_ >::logProbability ( Eigen::Index value) const
inlinenodiscard
Returns
the log-probability of the value with flat index value

◆ marginal()

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
template<typename P>
auto Emrys::Categorical< Space_, Scalar_ >::marginal ( ) const
inlinenodiscard
Returns
the parameters of the axis named by the path P (a tag or a TagPath), summed over the others, with log-weights that are its log-probabilities

◆ mostProbable()

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
Eigen::Index Emrys::Categorical< Space_, Scalar_ >::mostProbable ( ) const
inlinenodiscard
Returns
the flat index of the most probable value; ties go to the lowest

◆ probabilities()

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
auto Emrys::Categorical< Space_, Scalar_ >::probabilities ( ) const
inlinenodiscard
Returns
the probability of each value, a lazy Eigen expression that must not outlive the parameters

◆ probability() [1/2]

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
template<typename... Values>
requires (sizeof...(Values) > 0)
Scalar Emrys::Categorical< Space_, Scalar_ >::probability ( ) const
inlinenodiscard
Returns
the probability of the values that have every named value in Values, as logProbability<Values...>()

◆ probability() [2/2]

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
Scalar Emrys::Categorical< Space_, Scalar_ >::probability ( Eigen::Index value) const
inlinenodiscard
Returns
the probability of the value with flat index value

◆ space()

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
Space_ const & Emrys::Categorical< Space_, Scalar_ >::space ( ) const
inlinenodiscard
Returns
the discrete space

Member Data Documentation

◆ CardinalityAtCompileTime

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
int Emrys::Categorical< Space_, Scalar_ >::CardinalityAtCompileTime
staticconstexpr
Initial value:
=
static constexpr int CardinalityAtCompileTime
Definition Categorical.h:263

the number of values, or Eigen::Dynamic

◆ MaxCardinalityAtCompileTime

template<DiscreteSpace Space_, RealScalar Scalar_ = double>
int Emrys::Categorical< Space_, Scalar_ >::MaxCardinalityAtCompileTime
staticconstexpr
Initial value:
=
static constexpr int MaxCardinalityAtCompileTime
Definition Categorical.h:264

a bound on it, or Eigen::Dynamic


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