mixle.stats.multivariate.dirichlet_multinomial module¶
Dirichlet-multinomial (Polya) distribution – an overdispersed multinomial.
The multivariate analogue of the beta-binomial: a multinomial whose category probabilities are
Dirichlet(alpha) distributed and integrated out. For a count vector x over K categories summing
to n,
P(x; alpha) = n!/prod_k x_k! * B(alpha + x) / B(alpha), B(a) = prod_k Gamma(a_k) / Gamma(sum a),
which adds overdispersion (and category correlation) over a plain multinomial. The number of trials
n is a fixed, known parameter; alpha is fit by Minka’s maximum-likelihood fixed point, run from
a cumulative-count sufficient statistic so it converges inside a single estimate call.
- class DirichletMultinomialDistribution(alpha, n, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionDirichlet-multinomial over
K-category count vectors summing ton(concentrationalpha).- density(x)[source]
Return the probability mass at a single count vector
x.
- log_density(x)[source]
Return the log-mass at
x(-infif any count is negative or the total is notn).
- seq_log_density(x)[source]
Vectorized log-mass for a stack of count vectors, shape
(N, K).
- sampler(seed=None)[source]
Return a sampler for drawing count vectors from this distribution.
- Parameters:
seed (int | None)
- Return type:
DirichletMultinomialSampler
- estimator(pseudo_count=None)[source]
Return a Minka fixed-point MLE estimator for
alphaat the fixed number of trialsn.- Parameters:
pseudo_count (float | None)
- Return type:
DirichletMultinomialEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution for vectorized methods.
- Return type:
DirichletMultinomialDataEncoder
- class DirichletMultinomialSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw counts as
p ~ Dirichlet(alpha)thenx ~ Multinomial(n, p).- Parameters:
dist (DirichletMultinomialDistribution)
seed (int | None)
- class DirichletMultinomialAccumulator(dim, n, name=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate cumulative counts
c[k, j] = sum_i w_i 1{x_ik > j}(the Minka digamma-recurrence stat).- update(x, weight, estimate)[source]
Accumulate Minka recurrence statistics for one count vector.
- initialize(x, weight, rng)[source]
Initialize statistics from one count vector.
- Parameters:
x (ndarray)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Accumulate Minka recurrence statistics from encoded count vectors.
- seq_initialize(x, weights, rng)[source]
Initialize statistics from encoded count vectors.
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge another Dirichlet-multinomial sufficient-statistic tuple.
- value()[source]
Return cumulative recurrence counts and total weight.
- from_value(x)[source]
Replace accumulator contents from recurrence statistics.
- key_merge(stats_dict)[source]
Merge keyed statistics into
stats_dictwhen keys are configured.
- key_replace(stats_dict)[source]
Replace this accumulator from keyed statistics when available.
- acc_to_encoder()[source]
Return the encoder used by this accumulator.
- Return type:
DirichletMultinomialDataEncoder
- class DirichletMultinomialAccumulatorFactory(dim, n, name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for DirichletMultinomialAccumulator.
- make()[source]
Create a fresh Dirichlet-multinomial accumulator.
- Return type:
DirichletMultinomialAccumulator
- class DirichletMultinomialEstimator(dim, n, max_iter=500, tol=1.0e-9, name=None, keys=None)[source]
Bases:
ParameterEstimatorMinka fixed-point maximum-likelihood estimator for the Dirichlet-multinomial concentration.
- accumulator_factory()[source]
Return an accumulator factory for Dirichlet-multinomial statistics.
- Return type:
DirichletMultinomialAccumulatorFactory