The parameters of a probability distribution over a discrete space: one weight per value.
More...
|
|
| CategoricalParams (Space_ space={}) |
| | The uniform distribution over space, with log-weights that are its log-probabilities.
|
|
template<typename Derived> |
| | CategoricalParams (Space_ space, Eigen::DenseBase< Derived > const &logWeights) |
| | The distribution over space whose probabilities are proportional to \( e^{\ell_v} \), with logWeights \( \ell \), one per value.
|
| Space_ const & | space () const |
| Eigen::Index | cardinality () const |
| ArrayType const & | logWeights () const |
| Scalar | logWeight (Eigen::Index value) const |
| std::expected< Scalar, WeightError > | logTotalWeight () const |
|
template<typename Derived> |
| void | setLogWeights (Eigen::DenseBase< Derived > const &logWeights) |
| | Sets the log-weights to logWeights, one per value.
|
|
template<typename Derived> |
| void | setWeights (Eigen::DenseBase< Derived > const &weights) |
| | Sets the weights to weights, one per value, which need not sum to one.
|
|
void | setLogWeight (Eigen::Index value, Scalar logWeight) |
| | Sets the log-weight of the value with flat index value to logWeight.
|
|
void | setWeight (Eigen::Index value, Scalar weight) |
| | Sets the weight of the value with flat index value to weight.
|
template<typename... Values>
requires (sizeof...(Values) > 0) |
| void | setLogWeight (Scalar logWeight) |
| | Sets the log-weight of the value with the named values Values, one per axis (see valueOf()), to logWeight.
|
template<typename... Values>
requires (sizeof...(Values) > 0) |
| void | setWeight (Scalar weight) |
| | Sets the weight of the value with the named values Values, one per axis (see valueOf()), to weight.
|
|
template<typename Derived> |
| void | reweight (Eigen::DenseBase< Derived > const &logLikelihoods) |
| | Multiplies each value's weight by its likelihood \( e^{\ell_v} \), with logLikelihoods \( \ell \) one per value, and checks nothing: several measurements can be added before one toDensity() or normalize().
|
| template<typename Derived> |
| std::expected< Scalar, WeightError > | update (Eigen::DenseBase< Derived > const &logLikelihoods) |
| | Bayes' rule: multiplies each value's probability by its likelihood \( e^{\ell_v} \), with logLikelihoods \( \ell \) one per value, and normalizes.
|
|
std::expected< void, WeightError > | normalize () |
| | Shifts the log-weights so that the weights sum to one, or returns the WeightError that stops it, leaving them unchanged.
|
| template<typename P> |
| auto | marginal () const |
| template<typename P> |
| auto | conditional (Eigen::Index value) const |
| template<typename Value> |
| auto | conditional () const |
| std::expected< DensityType, WeightError > | toDensity () const & |
|
void | toDensity () const &&=delete |
| | A density of a temporary would outlive it.
|
template<DiscreteSpace Space_, RealScalar Scalar_ = double>
class Emrys::CategoricalParams< Space_, Scalar_ >
The parameters of a probability distribution over a discrete space: one weight per value.
The categorical distribution, kept as one log-weight per value, so that a value can be improbable without underflowing. The weights need not sum to one, and they are not checked when they are written: a histogram can be filled, a weight set by name, or several sensors' log-likelihoods added with reweight(), one write at a time, since only the whole set has to sum to something. toDensity() checks them once and returns the Categorical that evaluates the probabilities (decisions.md [params-and-density]). A value is its flat index (see Discrete spaces), and a value named by tags is valueOf<Mode, Turn, Outlier>().
p.setWeight<Turn, Outlier>(0.0);
auto const density = p.toDensity();
density->probability<Turn>();
static CategoricalParams fromWeights(Space_ space, Eigen::DenseBase< Derived > const &weights)
Definition Categorical.h:294
CategoricalParams< Space, Scalar > predict(CategoricalParams< Space, Scalar > const &prior, MarkovChain< Space, Scalar > const &chain)
Definition Categorical.h:1049
Eigen::Array< typename Derived::Scalar, Eigen::Dynamic, 1 > logLikelihoods(M const &measurement, Space const &space, Eigen::MatrixBase< Derived > const &states)
Definition Likelihood.h:408
The array holds one weight per value: inline up to the space's MaxCardinality, as a mean stores its coordinates, and on the heap only for an unbounded space.
- Template Parameters
-
| Space_ | the discrete space (see Discrete spaces) |
| Scalar_ | scalar type of the weights, double by default |
- See also
- Categorical, MarkovChain, predict()