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]

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 - (|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 one sample or an array of iid samples.

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]

Accumulate weighted raw moments up to order four for one observation.

Parameters:
  • x (float)

  • weight (float)

  • estimate (GeneralizedGaussianDistribution | None)

Return type:

None

initialize(x, weight, rng)[source]

Initialize statistics from one observation.

Parameters:
Return type:

None

seq_update(x, weights, estimate)[source]

Accumulate weighted raw moments up to order four from encoded data.

Parameters:
Return type:

None

seq_initialize(x, weights, rng)[source]

Initialize statistics from encoded observations.

Parameters:
Return type:

None

combine(suff_stat)[source]

Merge another generalized-Gaussian sufficient-statistic tuple.

Parameters:

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

Return type:

GeneralizedGaussianAccumulator

value()[source]

Return count and raw moment sums through order four.

Return type:

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

from_value(x)[source]

Replace accumulator contents from a sufficient-statistic tuple.

Parameters:

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

Return type:

GeneralizedGaussianAccumulator

key_merge(stats_dict)[source]

Merge keyed statistics into stats_dict when keys are configured.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

key_replace(stats_dict)[source]

Replace this accumulator from keyed statistics when available.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

acc_to_encoder()[source]

Return the encoder used by this accumulator.

Return type:

GeneralizedGaussianDataEncoder

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

Bases: StatisticAccumulatorFactory

Factory for GeneralizedGaussianAccumulator.

Parameters:
  • name (str | None)

  • keys (str | None)

make()[source]

Create a fresh generalized-Gaussian accumulator.

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 an accumulator factory for generalized-Gaussian raw moments.

Return type:

GeneralizedGaussianAccumulatorFactory

estimate(nobs, suff_stat)[source]

Estimate location, scale, and shape from weighted raw moments.

Parameters:
Return type:

GeneralizedGaussianDistribution

class GeneralizedGaussianDataEncoder[source]

Bases: DataSequenceEncoder

Encode observations as a float array.

seq_encode(x)[source]

Encode observations as a floating-point array.

Parameters:

x (Sequence[float])

Return type:

ndarray