mixle.stats.univariate.discrete.logseries module¶
Create, estimate, and sample from a logarithmic (log-series) distribution on positive integers.
Defines the LogSeriesDistribution, LogSeriesSampler, LogSeriesAccumulatorFactory, LogSeriesAccumulator, LogSeriesEstimator, and the LogSeriesDataEncoder classes for use with mixle.
Data type: (int): a positive integer k >= 1. The LogSeriesDistribution with shape p in (0, 1) has log-mass
log(P(k; p)) = k*log(p) - log(k) - log(-log(1 - p)), k = 1, 2, …,
a one-parameter exponential family used for over-dispersed positive counts (species abundance,
word-frequency / type-token models). The mean is -p / ((1 - p) * log(1 - p)) (a value in
(1, inf) that increases with p), which the estimator inverts.
The per-row score is linear in the encoded k and log(k) fields once the scalar normalizer
log(-log(1 - p)) is precomputed, so the family gets generated NumPy, Torch, and Numba kernels.
Reference: Fisher, Corbet & Williams, ‘The relation between the number of species and the number of individuals…’, J. Animal Ecology (1943).
- class LogSeriesDistribution(p, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionLogarithmic (log-series) distribution on k = 1, 2, … with shape parameter p in (0, 1).
- classmethod compute_capabilities()[source]
- classmethod compute_declaration()[source]
- static backend_legacy_sufficient_statistics(x, params, engine)[source]
Return per-row (count, k) sufficient statistics in accumulator order.
- static exp_family_sufficient_statistics(x, engine)[source]
Return the log-series sufficient statistic
T(k) = (k,).
- static exp_family_natural_parameters(params, engine)[source]
Return the log-series natural parameter
eta = log(p).
- static exp_family_log_partition(params, engine)[source]
Return the log-series log partition
A = log(-log(1 - p)).
- static exp_family_base_measure(x, engine)[source]
Return the log-series base measure
log h(k) = -log(k)(independent of p, fixed base).
- static exp_family_from_natural(eta)[source]
Return the log-series with natural parameter
eta = log(p)(sop = exp(eta)).- Parameters:
eta (Any)
- Return type:
LogSeriesDistribution
- static backend_log_density_from_params(k, log_k, log_p, log_norm, engine)[source]
Engine-neutral log-series log-mass from explicit parameters (linear in k and log k).
- density(x)[source]
Return the probability mass at a single observation.
- log_density(x)[source]
Return the log-mass at a single positive integer (or -inf off support).
- seq_log_density(x)[source]
Return vectorized log-mass values for sequence-encoded (k, log k) observations.
- backend_seq_log_density(x, engine)[source]
Engine-neutral vectorized log-mass for encoded data.
- classmethod backend_stacked_params(dists, engine)[source]
Return stacked parameters for a homogeneous mixture kernel.
- classmethod backend_stacked_log_density(x, params, engine)[source]
Return an
(n, k)matrix of log-series log densities.
- classmethod backend_stacked_sufficient_statistics(x, weights, params, engine)[source]
Return stacked sufficient statistics using engine-resident arrays.
- cdf(x)[source]
Cumulative distribution function P(X <= x), support x >= 1 (via scipy logser).
- quantile(q)[source]
Inverse CDF F^{-1}(q) (via scipy logser).
- sampler(seed=None)[source]
Return a sampler for drawing observations from this distribution.
- Parameters:
seed (int | None)
- Return type:
LogSeriesSampler
- estimator(pseudo_count=None)[source]
Return an estimator for fitting this distribution from data.
- Parameters:
pseudo_count (float | None)
- Return type:
LogSeriesEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution for vectorized methods.
- Return type:
LogSeriesDataEncoder
- class LogSeriesSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw iid log-series observations.
- Parameters:
dist (LogSeriesDistribution)
seed (int | None)
- class LogSeriesAccumulator(keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate weighted count and sum for log-series estimation.
- Parameters:
keys (str | None)
- update(x, weight, estimate)[source]
- initialize(x, weight, rng)[source]
- Parameters:
x (int)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
- seq_initialize(x, weights, rng)[source]
- Parameters:
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
- key_merge(stats_dict)[source]
Pool this accumulator’s statistics into
stats_dictunder its merge key.The structural default implements the common single-key pattern: store the accumulator under
self.keysthe first time the key is seen, elsecombineinto the one already there. Accumulators with several named keys (e.g. an HMM’s init/trans/state keys) or a non-accumulator stats payload override this. AkeysofNone(the default) is a no-op.
- key_replace(stats_dict)[source]
Replace this accumulator’s statistics from the pooled
stats_dictentry (see key_merge).
- acc_to_encoder()[source]
- Return type:
LogSeriesDataEncoder
- class LogSeriesAccumulatorFactory(keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for LogSeriesAccumulator.
- Parameters:
keys (str | None)
- make()[source]
- Return type:
LogSeriesAccumulator