mixle.stats.univariate.continuous.tweedie moduleΒΆ
Tweedie compound Poisson-Gamma distributions for 1 < p < 2.
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]
Return compute-backend metadata for Tweedie scoring.
- 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]
Return the encoder for Tweedie observations.
- 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]
Accumulate weighted count, sum, and second moment for one observation.
- initialize(x, weight, rng)[source]
Initialize the sufficient statistics with one weighted observation.
- Parameters:
x (float)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Accumulate weighted count, sum, and second moment from encoded observations.
- seq_initialize(x, weights, rng)[source]
Initialize the sufficient statistics from encoded observations.
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge serialized moment statistics into this accumulator.
- value()[source]
Return the total weight, weighted sum, and weighted second moment.
- from_value(x)[source]
Restore the accumulator from serialized moment statistics.
- scale(c)[source]
Scale accumulated moment statistics by a constant.
- Parameters:
c (float)
- Return type:
TweedieAccumulator
- acc_to_encoder()[source]
Return an encoder for non-negative Tweedie observations.
- Return type:
TweedieDataEncoder
- class TweedieAccumulatorFactory(name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for TweedieAccumulator.
- make()[source]
Create an empty Tweedie accumulator.
- Return type:
TweedieAccumulator