mixle.stats.univariate.continuous.tweedie moduleΒΆ
Evaluate, estimate, and sample from a Tweedie distribution (compound Poisson-Gamma, 1 < p < 2).
Defines TweedieDistribution, TweedieSampler, TweedieAccumulatorFactory, TweedieAccumulator, TweedieEstimator, and TweedieDataEncoder for use with mixle.
Data type (float >= 0): the Tweedie exponential-dispersion model with mean mu, dispersion
phi, and fixed power p in (1, 2) is the compound Poisson-Gamma law
Y = sum_{i=1}^N G_i, N ~ Poisson(lam), G_i ~ Gamma(shape=a, scale=theta) (iid),
with lam = mu**(2-p) / (phi*(2-p)), a = (2-p)/(p-1), theta = phi*(p-1)*mu**(p-1). There
is a point mass P(Y=0) = exp(-lam); for y > 0 the density is the (convergent) series
f(y) = sum_{n>=1} Poisson(n; lam) * Gamma(y; shape=n*a, scale=theta),
evaluated here in log-space via a windowed log-sum-exp over n. E[Y] = mu and
Var[Y] = phi * mu**p, so the method of moments (mean for mu, Pearson for phi) is exact;
p is a fixed hyperparameter (the profile likelihood over p is left to the caller).
Reference: Jorgensen, The Theory of Dispersion Models (Chapman & Hall, 1997).
- class TweedieDistribution(mu, phi, p=1.5, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionTweedie (compound Poisson-Gamma) distribution on
[0, inf)with fixed powerp in (1, 2).- density(x)[source]
Probability density (or the point mass at 0) at
x(seelog_density).
- log_density(x)[source]
Tweedie log-density:
log P(Y=0) = -lamat 0, the series forx > 0,-infforx < 0.
- seq_log_density(x)[source]
Vectorized Tweedie log-density at sequence-encoded non-negative observations
x.
- classmethod compute_capabilities()[source]
- backend_seq_log_density(x, engine)[source]
Engine-neutral vectorized Tweedie log-density for encoded data (see class backend note).
- sampler(seed=None)[source]
Return a TweedieSampler for this distribution.
- Parameters:
seed (int | None)
- Return type:
TweedieSampler
- estimator(pseudo_count=None)[source]
Return a TweedieEstimator (method of moments at the fixed power
p).- Parameters:
pseudo_count (float | None)
- Return type:
TweedieEstimator
- dist_to_encoder()[source]
Returns a TweedieDataEncoder object.
- Return type:
TweedieDataEncoder
- class TweedieSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw iid Tweedie observations exactly as a compound Poisson-Gamma sum.
- Parameters:
dist (TweedieDistribution)
seed (int | None)
- class TweedieAccumulator(name=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate the weighted count, sum, and sum-of-squares for the moment fit.
- update(x, weight, estimate)[source]
- initialize(x, weight, rng)[source]
- Parameters:
x (float)
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:
TweedieAccumulator
- acc_to_encoder()[source]
- Return type:
TweedieDataEncoder
- class TweedieAccumulatorFactory(name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for TweedieAccumulator.
- make()[source]
- Return type:
TweedieAccumulator