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.

Parameters:

x (ndarray | list[float])

Return type:

float

seq_log_density(x)[source]

Vectorized log-density at sequence-encoded (m, n) array of probability vectors.

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)[source]

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

Parameters:

size (int | None)

Return type:

ndarray

class SymmetricDirichletDataEncoder[source]

Bases: DataSequenceEncoder

Encodes a sequence of probability vectors into an (m, n) float array of log values.

seq_encode(x)[source]

Encode the iid observation sequence x for vectorized evaluation.

Parameters:

x (Any)

Return type:

ndarray