mixle.stats.univariate.discrete.skellam module¶
Skellam distributions for differences of independent Poisson counts.
- Data type (int):
K = N1 - N2withN1 ~ Poisson(mu1),N2 ~ Poisson(mu2)independent, so Kranges over all integers (negative, zero, positive). Its log-mass islog p(k) = -(sqrt(mu1) - sqrt(mu2))^2 + (k/2) * log(mu1/mu2) + log(I_|k|(2*sqrt(mu1*mu2))),
where
I_vis the modified Bessel function of the first kind. The exponentially-scaledive(v, z) = I_v(z) * exp(-z)is used (log I_v(z) = log(ive(v, z)) + z) so the Bessel term does not overflow for largez; combined with-(mu1+mu2) + zthis collapses to the stable-(sqrt(mu1) - sqrt(mu2))^2constant above.
The MLE has no closed form, but the method of moments is exact and closed-form here: with sample
mean m and variance v, mu1 = (v + m)/2 and mu2 = (v - m)/2 (since E[K] = mu1-mu2
and Var[K] = mu1+mu2), which the estimator uses (clamped to keep both rates positive).
Reference: Skellam, ‘The frequency distribution of the difference between two Poisson variates’, JRSS A (1946).
- class SkellamDistribution(mu1, mu2, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionSkellam distribution:
K = N1 - N2for independentN1 ~ Poisson(mu1),N2 ~ Poisson(mu2).- density(x)[source]
Probability mass at integer
x(seelog_density).
- log_density(x)[source]
Stable Skellam log-mass at integer
x(-inffor non-integer input).
- seq_log_density(x)[source]
Vectorized Skellam log-mass at sequence-encoded integer counts
x.
- entropy()[source]
Shannon entropy in nats, by exact two-sided summation of the standard series.
The Skellam entropy
-sum_k p_k log p_khas no closed form. The sum runs over the support between this distribution’s own quantiles at1e-16and1 - 1e-16(plus a safety margin on each side), beyond which the remaining tail mass on both sides is far below double rounding. Terms where the scaled Bessel term underflows to exactly zero (mass indistinguishable from 0 at double precision) are dropped, matching thep log p -> 0limit.- Return type:
- classmethod compute_capabilities()[source]
Describe backend support for generated Skellam scoring kernels.
- backend_seq_log_density(x, engine)[source]
Engine-neutral vectorized Skellam log-mass for encoded data (see class backend note).
The series yields the UNSCALED
log I_k(notlog ive = log I_k - z), so the constant here is-(mu1 + mu2)— the legacy path’s-sqrt_diff_sqplus its implicit-z.
- cdf(x)[source]
Cumulative distribution function P(X <= x) (via scipy skellam).
- quantile(q)[source]
Inverse CDF F^{-1}(q) (via scipy skellam).
- sampler(seed=None)[source]
Return a SkellamSampler for this distribution.
- Parameters:
seed (int | None)
- Return type:
SkellamSampler
- estimator(pseudo_count=None)[source]
Return a SkellamEstimator (method of moments).
- Parameters:
pseudo_count (float | None)
- Return type:
SkellamEstimator
- dist_to_encoder()[source]
Return the encoder for Skellam observations.
- Return type:
SkellamDataEncoder
- enumerator()[source]
Return an enumerator over all integers in descending probability order.
- Return type:
SkellamEnumerator
- class SkellamEnumerator(dist)[source]
Bases:
DistributionEnumeratorEnumerate the two-sided Skellam support in descending probability order.
The Skellam pmf is log-concave (the difference of two independent Poisson counts, each log-concave on the integers), hence unimodal: enumeration hill-climbs from
round(mu1 - mu2)to the mode and walks outward with the standard two-pointer merge over the two tails, emitting the larger side each step. Values whose mass underflows to zero are skipped per the enumerator contract, so the iterator ends when both tails are exhausted at float precision.- Parameters:
dist (SkellamDistribution)
- class SkellamSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw iid Skellam observations as the difference of two independent Poisson draws.
- Parameters:
dist (SkellamDistribution)
seed (int | None)
- class SkellamAccumulator(name=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate the weighted count, sum, and sum-of-squares needed for the moment fit.
- update(x, weight, estimate)[source]
Accumulate count, sum, and squared sum for one integer observation.
- initialize(x, weight, rng)[source]
Initialize statistics from one observation.
- Parameters:
x (int)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Accumulate count, sum, and squared sum from encoded observations.
- seq_initialize(x, weights, rng)[source]
Initialize statistics from encoded observations.
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge another Skellam sufficient-statistic tuple.
- from_value(x)[source]
Replace accumulator contents from a sufficient-statistic tuple.
- scale(c)[source]
Scale all weight-linear sufficient statistics by
c.- Parameters:
c (float)
- Return type:
SkellamAccumulator
- acc_to_encoder()[source]
Return the encoder used by this accumulator.
- Return type:
SkellamDataEncoder
- class SkellamAccumulatorFactory(name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for SkellamAccumulator.
- make()[source]
Create a fresh Skellam accumulator.
- Return type:
SkellamAccumulator
- class SkellamEstimator(pseudo_count=None, suff_stat=None, name=None, keys=None)[source]
Bases:
ParameterEstimatorEstimate
(mu1, mu2)by the (exact, closed-form) method of moments.- Parameters:
- accumulator_factory()[source]
Return an accumulator factory for Skellam moment statistics.
- Return type:
SkellamAccumulatorFactory