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: SequenceEncodableProbabilityDistribution

Symmetric Dirichlet distribution with shared concentration alpha; the dimension is inferred from each observation (or fixed with dim for sampling).

Parameters:
get_parameters()[source]

Returns the shared concentration parameter alpha.

Return type:

float

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).

Parameters:

x (ndarray | list[float])

Return type:

float

log_density(x)[source]

Log-density of the symmetric Dirichlet at the probability vector x (-inf off the simplex: a negative or non-finite entry, or a vector that doesn’t sum to one).

Parameters:

x (ndarray | list[float])

Return type:

float

seq_log_density(x)[source]

Vectorized log-density at a sequence-encoded (m, n) array of probability vectors (-inf rows that are off the simplex: a negative or non-finite entry, or a row that doesn’t sum to one).

Parameters:

x (ndarray)

Return type:

ndarray

entropy()[source]

Differential entropy in nats (requires dim to be set).

Return type:

float

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: DistributionSampler

Draws probability vectors from a SymmetricDirichletDistribution with a known dimension.

Parameters:
  • dist (SymmetricDirichletDistribution)

  • seed (int | None)

sample(size=None, *, batched=True)[source]

Draw symmetric-Dirichlet-distributed probability vectors (requires dist.dim).

Parameters:
Return type:

ndarray

class SymmetricDirichletDataEncoder(dimension=None)[source]

Bases: DataSequenceEncoder

Encodes 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_density can 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.

Parameters:

x (Any)

Return type:

ndarray