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.
- exception DirichletMultinomialResourceError[source]
Bases:
RuntimeErrorRaised before a configured enumeration or fitting resource budget is exceeded.
- class DirichletMultinomialFitReceipt(algorithm, converged, identifiable, iterations, objective_history, max_delta, regularized_categories, concentration_floor)[source]
Bases:
objectMachine-readable evidence about a concentration fixed-point fit.
- class DirichletMultinomialDistribution(alpha, n, name=None, keys=None, *, max_recurrence_cells=_DEFAULT_MAX_RECURRENCE_CELLS, max_frontier_entries=_DEFAULT_MAX_FRONTIER_ENTRIES)[source]
Bases:
SequenceEncodableProbabilityDistributionDirichlet-multinomial over
K-category count vectors summing ton(concentrationalpha).- Parameters:
- 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, non-integer, or the total is notn– a fractional category count is not a valid Dirichlet-multinomial outcome even when the (real-valued) total happens to sum ton).
- seq_log_density(x)[source]
Vectorized log-mass for a stack of count vectors, shape
(N, K)(-infrows where any count is negative, non-integer, or the row total is notn).
- 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 DirichletMultinomialEnumerator(dist, *, max_recurrence_cells=_DEFAULT_MAX_RECURRENCE_CELLS, max_frontier_entries=_DEFAULT_MAX_FRONTIER_ENTRIES)[source]
Bases:
DistributionEnumeratorEnumerate Dirichlet-multinomial count vectors in descending probability order, lazily (A* best-first).
The log-mass separates per category:
log P(x) = log_const + sum_k f_k(x_k)withf_k(c) = gammaln(c + alpha_k) - gammaln(alpha_k) - gammaln(c + 1), and eachf_kis monotone inc(increasing foralpha_k > 1, decreasing foralpha_k < 1), so a prefix assignment(x_1..x_j)withmtrials left admits the admissible completion boundsum_{k>j} max(f_k(0), f_k(m)). A* on the exact prefix score plus that bound streams count vectors in exact descending order without materializing theC(n+K-1, K-1)support.
- 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, *, max_recurrence_cells=_DEFAULT_MAX_RECURRENCE_CELLS)[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, total weight, and logical trial count.
- from_value(x)[source]
Replace accumulator contents from recurrence statistics.
- acc_to_encoder()[source]
Return the encoder used by this accumulator.
- Return type:
DirichletMultinomialDataEncoder
- class DirichletMultinomialAccumulatorFactory(dim, n, name=None, keys=None, *, max_recurrence_cells=_DEFAULT_MAX_RECURRENCE_CELLS)[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, pseudo_count=None, name=None, keys=None, min_alpha=_DEFAULT_MIN_ALPHA, max_recurrence_cells=_DEFAULT_MAX_RECURRENCE_CELLS, max_frontier_entries=_DEFAULT_MAX_FRONTIER_ENTRIES)[source]
Bases:
ParameterEstimatorMinka fixed-point maximum-likelihood estimator for the Dirichlet-multinomial concentration.
- Parameters:
- accumulator_factory()[source]
Return an accumulator factory for Dirichlet-multinomial statistics.
- Return type:
DirichletMultinomialAccumulatorFactory
- class DirichletMultinomialDataEncoder(dim, n)[source]
Bases:
DataSequenceEncoderEncode a sequence of
K-category count vectors as an(N, K)array.