mixle.stats.bayes.symmetric_dirichlet module¶
Symmetric Dirichlet distribution on probability vectors with a single shared concentration alpha.
Observations are length-n sequences/arrays of non-negative reals summing to one (points on the (n-1)-simplex), scored with one shared concentration parameter alpha. The log-density is
log f(x; alpha) = sum_k (alpha - 1)*log(x_k) + gammaln(n*alpha) - n*gammaln(alpha),
where n = len(x) is inferred from each observation.
This is a parameter prior (the conjugate Dirichlet prior used by
IntegerCategoricalDistribution when a symmetric prior is desired). It
is scored on probability vectors, not fit from data by EM. Ported from mixle.bstats.symdirichlet.
- class SymmetricDirichletDistribution(alpha, dim=None, name=None)[source]
Bases:
SequenceEncodableProbabilityDistributionSymmetric Dirichlet distribution with shared concentration alpha; the dimension is inferred from each observation (or fixed with dim for sampling).
- set_parameters(params)[source]
Set the shared concentration parameter alpha.
- Parameters:
params (float)
- Return type:
None
- density(x)[source]
Density at the probability vector x (exp of log_density).
- log_density(x)[source]
Log-density of the symmetric Dirichlet at the probability vector x (
-infoff the simplex: a negative or non-finite entry, or a vector that doesn’t sum to one).
- seq_log_density(x)[source]
Vectorized log-density at a sequence-encoded (m, n) array of probability vectors (
-infrows that are off the simplex: a negative or non-finite entry, or a row that doesn’t sum to one).
- sampler(seed=None)[source]
Returns a SymmetricDirichletSampler for this distribution.
- Parameters:
seed (int | None)
- Return type:
SymmetricDirichletSampler
- estimator(pseudo_count=None)[source]
SymmetricDirichlet 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 SymmetricDirichletDataEncoder for encoding probability vectors.
- Return type:
SymmetricDirichletDataEncoder
- class SymmetricDirichletSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraws probability vectors from a SymmetricDirichletDistribution with a known dimension.
- Parameters:
dist (SymmetricDirichletDistribution)
seed (int | None)
- class SymmetricDirichletDataEncoder(dimension=None)[source]
Bases:
DataSequenceEncoderEncodes a sequence of probability vectors into an (m, n) float array of log values.
- Parameters:
dimension (int | None)
- seq_encode(x)[source]
Encode simplex observations as a raw (m, n) float array.
Kept raw (not pre-logged/clipped) so
seq_log_densitycan validate simplex membership – negative entries, non-finite entries, rows not summing to one – from the actual values; a pre-clipped log representation would silently discard exactly the information needed to reject those.