mixle.stats.univariate.continuous.generalized_gaussian module¶
Generalized Gaussian (exponential-power) distribution.
A symmetric location-scale family with a tunable tail/peakedness shape beta that interpolates the
Laplace (beta = 1), Gaussian (beta = 2), and uniform (beta -> inf) laws. With location
mu, scale alpha > 0 and shape beta > 0,
f(x; mu, alpha, beta) = beta / (2 alpha Gamma(1/beta)) * exp(-(abs(x - mu) / alpha)^beta).
The normalizer is closed form (a Gamma function), so density/CDF/quantile/moments/entropy are all exact;
it samples exactly via a Gamma draw with a random sign. Parameters are fit by the method of moments:
mu is the mean, the excess kurtosis Gamma(5/beta)Gamma(1/beta)/Gamma(3/beta)^2 - 3 pins beta
(monotone, solved by a bracketed root find), and alpha follows from the variance
alpha^2 Gamma(3/beta)/Gamma(1/beta).
The M-step is shift-equivariant: fitting x + c returns mu + c with an unchanged alpha
and beta. That does not come for free from raw power sums – the central fourth moment differenced
out of E[x^4] loses about 4*log2(abs(mean)/sd) bits – so the accumulator carries a
conditioning-gated shift-anchored moment track alongside the raw sums (see
GeneralizedGaussianAccumulator).
References
Nadarajah, “A generalized normal distribution”, J. Applied Statistics 32 (2005).
Subbotin (1923), the original exponential-power family.
- class GeneralizedGaussianSuffStat(count, s1, s2, s3, s4, anchored=None)[source]
Bases:
tupleA
(count, s1, s2, s3, s4)sufficient statistic that also carries a side payload.Behaves exactly like the plain 5-tuple everywhere it is indexed, unpacked, or iterated (it is one);
anchoredis the shift-anchored payload(anchor, sum_i w_i (x_i - anchor)^k for k = 1..4)the accumulator maintains alongside the raw power sums so the M-step survives large-offset data. Code that doesn’t know about the payload (genericscale_suff_stat, serializers, …) sees an ordinary tuple and the estimate falls back to the historical raw path.
- class GeneralizedGaussianDistribution(mu, alpha, beta, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionGeneralized Gaussian (exponential power) with location
mu, scalealphaand shapebeta.- classmethod compute_declaration()[source]
Return the structured compute declaration for generalized Gaussian distributions.
- static backend_log_density_from_params(x, mu, alpha, beta, engine)[source]
Engine-neutral generalized-Gaussian log-density:
log_norm - (abs(x-mu)/alpha)**beta.
- seq_log_density(x)[source]
Return vectorized log-density for a sequence-encoded array of observations.
- kurtosis()[source]
Excess kurtosis Gamma(5/beta)Gamma(1/beta)/Gamma(3/beta)^2 - 3.
- Return type:
- entropy()[source]
Differential entropy 1/beta - log(beta / (2 alpha Gamma(1/beta))).
- Return type:
- sampler(seed=None)[source]
Return a sampler (Gamma magnitude with a random sign).
- Parameters:
seed (int | None)
- Return type:
GeneralizedGaussianSampler
- estimator(pseudo_count=None)[source]
Return a method-of-moments estimator for
mu,alpha,beta.- Parameters:
pseudo_count (float | None)
- Return type:
GeneralizedGaussianEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution (the raw value).
- Return type:
GeneralizedGaussianDataEncoder
- class GeneralizedGaussianSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw
x = mu + sign * alpha * Gamma(1/beta)**(1/beta).- Parameters:
dist (GeneralizedGaussianDistribution)
seed (int | None)
- class GeneralizedGaussianAccumulator(name=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate the weighted power sums
(count, sum x, sum x^2, sum x^3, sum x^4)for the MoM.Alongside the raw sums the accumulator keeps a CONDITIONING-GATED shift-anchored track,
sum_i w_i (x_i - anchor)^kfork = 1..4about a data anchor. The method of moments needs central moments, and differencing them out of raw power sums is the classic cancellation-prone form: the fourth reduced moment loses roughly4*log2(abs(mean)/sd)bits, so data with sd ~0.7 at offset 1.7e9 has no correct digits left inm4and the fit collapses onto the shape bound with a scale two orders of magnitude too small – silently. Anchoring keeps every term of the scatterO(count * spread^4), making the M-step shift-equivariant.The gate keeps the historical path bit-identical for well-conditioned data: a chunk whose
abs(mean)/spreadratio the raw form handles to ~1e-9 relative (see_needs_anchor()) accumulates exactly the way it always did, with no anchor and no second pass. The raw sums remain the exchange format, so the anchored track rides along as a payload onGeneralizedGaussianSuffStat; a consumer that drops the payload simply gets the historical raw estimate back.- update(x, weight, estimate)[source]
Accumulate weighted raw moments up to order four for one observation.
- initialize(x, weight, rng)[source]
Initialize statistics from one observation.
- Parameters:
x (float)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Accumulate weighted raw moments up to order four from encoded data.
- 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 generalized-Gaussian sufficient-statistic tuple.
- value()[source]
Return count and raw moment sums through order four.
The returned object is a plain 5-tuple for every consumer that treats it as one; once the shift-anchored track is live it additionally carries the anchored moments in its
.anchoredattribute, socombine()can fold them in andGeneralizedGaussianEstimator.estimate()can use them for the reduced moments. The payload is withheld when the track was seeded from raw statistics that had already lost their central moments (see_activate_anchor()), so a pool that cannot honestly claim shift-equivariance reports the historical raw statistics instead of a worse anchored guess.
- from_value(x)[source]
Replace accumulator contents from a sufficient-statistic tuple.
- scale(c)[source]
Scale accumulated evidence, keeping the shift-anchored track in step with the raw sums.
The generic base implementation round-trips through
scale_suff_stat/from_value, which sees only a plain tuple and would silently drop the anchored payload – turning a scaled accumulator back into the ill-conditioned raw path.- Parameters:
c (float)
- Return type:
GeneralizedGaussianAccumulator
- acc_to_encoder()[source]
Return the encoder used by this accumulator.
- Return type:
GeneralizedGaussianDataEncoder
- class GeneralizedGaussianAccumulatorFactory(name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for GeneralizedGaussianAccumulator.
- make()[source]
Create a fresh generalized-Gaussian accumulator.
- Return type:
GeneralizedGaussianAccumulator
- class GeneralizedGaussianEstimator(pseudo_count=None, suff_stat=None, beta_bounds=(0.25, 50.0), name=None, keys=None, prior_central=None)[source]
Bases:
ParameterEstimatorMethod-of-moments estimator:
mu= mean,betafrom excess kurtosis,alphafrom variance.The reduced moments are formed about a reference point rather than about zero whenever the accumulated statistics carry a shift-anchored payload (see
GeneralizedGaussianAccumulator), which makes the fit shift-equivariant:estimateonx + creturnsmu + cwithalphaandbetaunchanged. With a plain raw tuple – statistics restored from an older serialization, or a hand-built one – the historical raw path is used unchanged.- Parameters:
- accumulator_factory()[source]
Return an accumulator factory for generalized-Gaussian raw moments.
- Return type:
GeneralizedGaussianAccumulatorFactory