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(-(|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).

References

  • Nadarajah, “A generalized normal distribution”, J. Applied Statistics 32 (2005).

  • Subbotin (1923), the original exponential-power family.

class GeneralizedGaussianDistribution(mu, alpha, beta, name=None, keys=None)[source]

Bases: SequenceEncodableProbabilityDistribution

Generalized Gaussian (exponential power) with location mu, scale alpha and shape beta.

Parameters:
classmethod compute_declaration()[source]
static backend_log_density_from_params(x, mu, alpha, beta, engine)[source]

Engine-neutral generalized-Gaussian log-density: log_norm - (|x-mu|/alpha)**beta.

Parameters:
Return type:

Any

density(x)[source]

Return the probability density at x.

Parameters:

x (float)

Return type:

float

log_density(x)[source]

Return the log-density at x.

Parameters:

x (float)

Return type:

float

seq_log_density(x)[source]

Return vectorized log-density for a sequence-encoded array of observations.

Parameters:

x (ndarray)

Return type:

ndarray

cdf(x)[source]

Cumulative distribution function P(X <= x).

Parameters:

x (float)

Return type:

float

quantile(q)[source]

Inverse CDF F^{-1}(q).

Parameters:

q (float)

Return type:

float

mean()[source]

Mean (the location mu).

Return type:

float

variance()[source]

Variance alpha^2 Gamma(3/beta) / Gamma(1/beta).

Return type:

float

skewness()[source]

Skewness (0 – the law is symmetric).

Return type:

float

kurtosis()[source]

Excess kurtosis Gamma(5/beta)Gamma(1/beta)/Gamma(3/beta)^2 - 3.

Return type:

float

entropy()[source]

Differential entropy 1/beta - log(beta / (2 alpha Gamma(1/beta))).

Return type:

float

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: DistributionSampler

Draw x = mu + sign * alpha * Gamma(1/beta)**(1/beta).

Parameters:
  • dist (GeneralizedGaussianDistribution)

  • seed (int | None)

sample(size=None)[source]

Draw observations.

Combinator samplers (mixture/sequence/…) accept batched. With batched=True (the default) each child stream is drawn in one vectorized call instead of a per-draw Python loop – far faster. Because every child sampler owns an independent RandomState, batching consumes each stream in the same order as the loop, so the draws are identical to the legacy path. batched=False forces that legacy per-draw loop as a guaranteed- stable reference. Leaf samplers are already vectorized and ignore the flag.

Parameters:

size (int | None)

Return type:

float | ndarray

class GeneralizedGaussianAccumulator(name=None, keys=None)[source]

Bases: SequenceEncodableStatisticAccumulator

Accumulate the weighted power sums (count, sum x, sum x^2, sum x^3, sum x^4) for the MoM.

Parameters:
  • name (str | None)

  • keys (str | None)

update(x, weight, estimate)[source]
Parameters:
  • x (float)

  • weight (float)

  • estimate (GeneralizedGaussianDistribution | None)

Return type:

None

initialize(x, weight, rng)[source]
Parameters:
Return type:

None

seq_update(x, weights, estimate)[source]
Parameters:
Return type:

None

seq_initialize(x, weights, rng)[source]
Parameters:
Return type:

None

combine(suff_stat)[source]
Parameters:

suff_stat (tuple[float, float, float, float, float])

Return type:

GeneralizedGaussianAccumulator

value()[source]
Return type:

tuple[float, float, float, float, float]

from_value(x)[source]
Parameters:

x (tuple[float, float, float, float, float])

Return type:

GeneralizedGaussianAccumulator

key_merge(stats_dict)[source]

Pool this accumulator’s statistics into stats_dict under its merge key.

The structural default implements the common single-key pattern: store the accumulator under self.keys the first time the key is seen, else combine into 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. A keys of None (the default) is a no-op.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

key_replace(stats_dict)[source]

Replace this accumulator’s statistics from the pooled stats_dict entry (see key_merge).

Parameters:

stats_dict (dict[str, Any])

Return type:

None

acc_to_encoder()[source]
Return type:

GeneralizedGaussianDataEncoder

class GeneralizedGaussianAccumulatorFactory(name=None, keys=None)[source]

Bases: StatisticAccumulatorFactory

Factory for GeneralizedGaussianAccumulator.

Parameters:
  • name (str | None)

  • keys (str | None)

make()[source]
Return type:

GeneralizedGaussianAccumulator

class GeneralizedGaussianEstimator(beta_bounds=(0.25, 50.0), name=None, keys=None)[source]

Bases: ParameterEstimator

Method-of-moments estimator: mu = mean, beta from excess kurtosis, alpha from variance.

Parameters:
accumulator_factory()[source]
Return type:

GeneralizedGaussianAccumulatorFactory

estimate(nobs, suff_stat)[source]
Parameters:
Return type:

GeneralizedGaussianDistribution

class GeneralizedGaussianDataEncoder[source]

Bases: DataSequenceEncoder

Encode observations as a float array.

seq_encode(x)[source]

Encode the iid observation sequence x for vectorized evaluation.

Parameters:

x (Sequence[float])

Return type:

ndarray