mixle.stats.bayes.dict_dirichlet module¶
Dirichlet distribution on dictionary-valued probability maps.
Observations are dicts {value: probability} whose probabilities are non-negative and sum to one (points on the simplex indexed by the dict keys). A DictDirichletDistribution with concentration parameters alpha = {k: a_k} has log-density
log f(x; alpha) = gammaln(sum_k a_k) + sum_k [(a_k - 1)*log(x_k) - gammaln(a_k)].
A single scalar alpha is treated as a symmetric Dirichlet whose dimension is inferred from each observation (is_unbounded).
This is the conjugate prior used by CategoricalDistribution (see its
prior= argument). It is a parameter prior: it is scored on probability maps, not fit from data by
EM. Ported from mixle.bstats.catdirichlet.
- class DictDirichletDistribution(alpha, name=None)[source]
Bases:
SequenceEncodableProbabilityDistributionDirichlet distribution over probability maps keyed by arbitrary values; a scalar alpha denotes a symmetric Dirichlet of unspecified dimension.
- get_parameters()[source]
Returns the concentration parameters (dict, or scalar if unbounded).
- set_parameters(params)[source]
Set the concentration parameters.
- density(x)[source]
Density at the probability map x (exp of log_density).
- log_density(x)[source]
Log-density of the Dirichlet at the probability map x.
With scalar alpha the dimension is len(x); with dict alpha the observation is scored with the concentration entries matching its keys.
- seq_log_density(x)[source]
Vectorized log-density at a sequence of probability maps.
- cross_entropy(dist)[source]
Cross entropy -E_self[log dist(x)] for a DictDirichlet argument.
- Parameters:
dist (DictDirichletDistribution)
- Return type:
- sampler(seed=None)[source]
Returns a DictDirichletSampler for this distribution.
- Parameters:
seed (int | None)
- Return type:
DictDirichletSampler
- estimator(pseudo_count=None)[source]
DictDirichlet is a parameter prior and is not fit from data by EM.
- Parameters:
pseudo_count (float | None)
- Return type:
ParameterEstimator
- dist_to_encoder()[source]
Returns a DictDirichletDataEncoder for encoding probability maps.
- Return type:
DictDirichletDataEncoder