mixle.stats.univariate.discrete.skellam module¶
Evaluate, estimate, and sample from a Skellam distribution (the difference of two Poissons).
Defines the SkellamDistribution, SkellamSampler, SkellamAccumulatorFactory, SkellamAccumulator, SkellamEstimator, and SkellamDataEncoder classes for use with mixle.
- 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.
- classmethod compute_capabilities()[source]
- 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]
Returns a SkellamDataEncoder object.
- Return type:
SkellamDataEncoder
- 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]
- 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:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
- scale(c)[source]
Scale linear sufficient statistics in-place by
c.The structural default is correct for ordinary weighted sums, nested tuples/lists/dicts, and numeric arrays. Families whose
value()payload includes non-linear metadata such as support bounds must override this method and leave that metadata unscaled.- Parameters:
c (float)
- Return type:
SkellamAccumulator
- 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:
SkellamDataEncoder
- class SkellamAccumulatorFactory(name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for SkellamAccumulator.
- make()[source]
- Return type:
SkellamAccumulator