mixle.stats.univariate.continuous.gumbel module

Gumbel distributions for extreme-value maxima.

Observations are real-valued floats. A Gumbel distribution with location loc (mu) and scale beta > 0 has log-density

log(f(x; mu, beta)) = -log(beta) - z - exp(-z), z = (x - mu) / beta,

on the whole real line. It models the distribution of maxima; the mean is mu + beta*gamma (gamma the Euler-Mascheroni constant) and the variance is (pi^2 / 6) * beta^2, which the moment estimator inverts.

The per-row log-density lowers cleanly to the shared symbolic kernel, so the family gets generated NumPy, Torch, and Numba scoring through backend_log_density_from_params.

Reference: Johnson, Kotz & Balakrishnan, Continuous Univariate Distributions (2nd ed., Wiley, 1994/95).

class GumbelSuffStat(sum_, sum2_, count_, anchored=None)[source]

Bases: tuple

A (sum, sum2, count) sufficient statistic that also carries a shift-anchored side payload.

Behaves exactly like the plain 3-tuple everywhere it is indexed, unpacked, or iterated (it is one); anchored is the shift-anchored moment payload (anchor, sum_i w_i*(x_i - anchor), sum_i w_i*(x_i - anchor)^2) that GumbelAccumulator maintains alongside the raw moments so the M-step’s variance survives large-offset data. Code that doesn’t know about the payload (generic scale_suff_stat, engine kernels, …) sees an ordinary tuple and the estimate falls back to the historical raw path.

Parameters:
class GumbelDistribution(loc=0.0, scale=1.0, name=None, keys=None)[source]

Bases: SequenceEncodableProbabilityDistribution

Gumbel (extreme value type I) distribution with location loc and scale beta > 0.

Parameters:
classmethod compute_capabilities()[source]

Describe backend support for generated Gumbel kernels.

classmethod compute_declaration()[source]

Return the structured compute declaration for Gumbel distributions.

static backend_legacy_sufficient_statistics(x, params, engine)[source]

Return per-row Gumbel sufficient statistics in accumulator order.

Parameters:
Return type:

tuple[Any, …]

static backend_log_density_from_params(x, loc, scale, engine)[source]

Engine-neutral Gumbel log-density from explicit parameters.

Parameters:
Return type:

Any

density(x)[source]

Return the probability density at a single observation.

Parameters:

x (float)

Return type:

float

log_density(x)[source]

Return the log-density at a single observation.

Parameters:

x (float)

Return type:

float

seq_log_density(x)[source]

Return vectorized log-density values for sequence-encoded observations.

Parameters:

x (ndarray)

Return type:

ndarray

backend_seq_log_density(x, engine)[source]

Engine-neutral vectorized log-density for encoded data.

Parameters:
Return type:

Any

classmethod backend_stacked_params(dists, engine)[source]

Return stacked Gumbel parameters for a homogeneous mixture kernel.

Parameters:
Return type:

dict[str, Any]

classmethod backend_stacked_log_density(x, params, engine)[source]

Return an (n, k) matrix of Gumbel log densities.

Parameters:
Return type:

Any

classmethod backend_stacked_sufficient_statistics(x, weights, params, engine)[source]

Return stacked Gumbel sufficient statistics using engine-resident arrays.

Parameters:
Return type:

tuple[Any, Any, Any]

cdf(x)[source]

Cumulative distribution function P(X <= x).

Parameters:

x (float)

Return type:

float

quantile(q)[source]

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

q = 0 and q = 1 return the support’s bounds, -inf and +inf: Gumbel was the one continuous family that raised there, where Gaussian, Laplace and the rest already returned the infinities (P01-F12).

Parameters:

q (float)

Return type:

float

mean()[source]

Mean E[X] = loc + scale * euler_gamma.

Return type:

float

variance()[source]

Variance Var[X] = pi^2 scale^2 / 6.

Return type:

float

entropy()[source]

Differential entropy log(scale) + euler_gamma + 1.

Return type:

float

skewness()[source]

Skewness 12*sqrt(6)*zeta(3)/pi^3.

Return type:

float

kurtosis()[source]

Excess kurtosis (12/5).

Return type:

float

mode()[source]

Mode (= the location loc).

Return type:

float

sampler(seed=None)[source]

Return a sampler for drawing observations from this distribution.

Parameters:

seed (int | None)

Return type:

GumbelSampler

estimator(pseudo_count=None)[source]

Return a moment estimator for fitting this distribution from data.

Parameters:

pseudo_count (float | None)

Return type:

GumbelEstimator

dist_to_encoder()[source]

Return the data encoder used by this distribution for vectorized methods.

Return type:

GumbelDataEncoder

class GumbelSampler(dist, seed=None)[source]

Bases: DistributionSampler

Draw iid Gumbel observations.

Parameters:
  • dist (GumbelDistribution)

  • seed (int | None)

sample(size=None, *, batched=True)[source]

Draw size iid observations (a float when size is None).

Parameters:
Return type:

float | ndarray

class GumbelAccumulator(keys=None)[source]

Bases: AnchoredMomentTrack, SequenceEncodableStatisticAccumulator

Accumulate weighted first and second moments for Gumbel estimation.

Alongside the raw (sum, sum2, count) the accumulator keeps the conditioning-gated shift-anchored moment track of AnchoredMomentTrack: the naive E[x^2]-E[x]^2 form the moment inversion needs loses ~``2*log2(abs(mean)/sd)`` bits to cancellation, so Gumbel data with sd ~2 fitted a scale 8.8x too large at offset 1.7e9 and collapsed onto min_scale at 2**31 – silently, with an empty numerical_repairs(). Well-conditioned data never activates the track and accumulates bit-identically to the historical single-pass path.

Parameters:

keys (str | None)

update(x, weight, estimate)[source]

Accumulate weighted first and second moments for one observation.

Parameters:
  • x (float)

  • weight (float)

  • estimate (GumbelDistribution | 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 first and second moments 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 Gumbel sufficient-statistic tuple.

Parameters:

suff_stat (tuple[float, float, float])

Return type:

GumbelAccumulator

value()[source]

Return accumulated sum, second moment sum, and count.

A plain 3-tuple for every consumer that treats it as one; once the shift-anchored moment track is live it is a GumbelSuffStat additionally carrying the anchored moments in its .anchored attribute, so combine() can fold them in and GumbelEstimator.estimate() can invert a shift-invariant variance.

Return type:

tuple[float, float, float]

from_value(x)[source]

Replace accumulator contents from a sufficient-statistic tuple.

Parameters:

x (tuple[float, float, float])

Return type:

GumbelAccumulator

scale(c)[source]

Scale the accumulated statistics in place by c, anchored track included.

Parameters:

c (float)

Return type:

GumbelAccumulator

acc_to_encoder()[source]

Return the encoder used by this accumulator.

Return type:

GumbelDataEncoder

class GumbelAccumulatorFactory(keys=None)[source]

Bases: StatisticAccumulatorFactory

Factory for GumbelAccumulator.

Parameters:

keys (str | None)

make()[source]

Create a fresh Gumbel accumulator.

Return type:

GumbelAccumulator

class GumbelEstimator(pseudo_count=None, suff_stat=None, min_scale=1.0e-8, name=None, keys=None)[source]

Bases: ParameterEstimator

Moment estimator for the Gumbel location and scale.

Inverts the Gumbel moments: beta = sqrt(6 * var) / pi and loc = mean - beta * gamma where gamma is the Euler-Mascheroni constant.

The variance moment is formed from shift-anchored statistics whenever the accumulated sufficient statistics carry that payload (see GumbelAccumulator), which makes the fit SHIFT-EQUIVARIANT: estimating on x + c returns loc + c with scale unchanged, for any constant c the data can carry – epoch seconds (~1.7e9) and 2**31 included. With a plain raw tuple – statistics the conditioning gate never needed to anchor, or ones that arrived already reduced from an engine kernel or an older serialization – the historical raw path is used bit-identically, and estimate warns rather than returning a scale it cannot stand behind.

Parameters:
accumulator_factory()[source]

Return an accumulator factory for Gumbel moment statistics.

Return type:

GumbelAccumulatorFactory

estimate(nobs, suff_stat)[source]

Estimate location and scale from weighted moments.

Parameters:
Return type:

GumbelDistribution

class GumbelDataEncoder[source]

Bases: DataSequenceEncoder

Encode Gumbel observations as a float array.

seq_encode(x)[source]

Encode observations as a floating-point array.

Parameters:

x (Sequence[float])

Return type:

ndarray