mixle.stats.univariate.continuous.generalized_extreme_value module¶
Generalized Extreme Value distribution (GEV): the limit law of block maxima.
By the Fisher-Tippett-Gnedenko theorem the normalized maximum of a large block of iid observations
converges to a GEV, the standard model for extremes (flood levels, wind speeds, record losses). With
location mu, scale sigma > 0 and shape xi (the EVT sign convention; scipy’s
genextreme uses c = -xi), for z = (x - mu)/sigma:
log f = -log sigma - (1/xi + 1) log s - s ** (-1/xi), s = 1 + xi z > 0 (xi != 0), log f = -log sigma - z - exp(-z) (xi == 0, Gumbel).
xi > 0 is the heavy-tailed Frechet type (support x >= mu - sigma/xi), xi = 0 the Gumbel
type (all reals), xi < 0 the bounded Weibull type (x <= mu - sigma/xi). All three parameters
are fit by method of moments: the shape is solved from the (monotone) skewness-vs-xi relation,
then scale from the variance and location from the mean.
The M-step is shift-equivariant: fitting x + c returns loc + c with an unchanged scale
and shape. That does not come for free from raw power sums – the central third moment
differenced out of E[x^3] loses about 3*log2(abs(mean)/sd) bits, and the variance about twice
that – so the accumulator carries a conditioning-gated shift-anchored moment track alongside the raw
sums (see GeneralizedExtremeValueAccumulator).
Reference: Coles, An Introduction to Statistical Modeling of Extreme Values (Springer, 2001).
- class GeneralizedExtremeValueSuffStat(sum_, sum2_, sum3_, count_, min_val, max_val, anchored=None)[source]
Bases:
tupleA
(sum, sum2, sum3, count, min_val, max_val)statistic that also carries a side payload.Behaves exactly like the plain 6-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..3)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 GeneralizedExtremeValueDistribution(loc, scale, shape, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionGeneralized Extreme Value distribution with location
loc, scale> 0and shapexi.- density(x)[source]
Return the probability density at a single observation.
- log_density(x)[source]
Return the log-density at a single observation (
-infoutside the support).
- seq_log_density(x)[source]
Return vectorized log-density values for sequence-encoded observations.
- classmethod compute_capabilities()[source]
Describe backend support for generated GEV kernels.
- classmethod compute_declaration()[source]
Return the structured compute declaration for GEV distributions.
- static backend_legacy_sufficient_statistics(x, params, engine)[source]
Per-row GEV moment sums in accumulator order
(sum, sum2, sum3, count).Deliberately not wired into the declaration as
legacy_sufficient_statistics. The generated statistic path reduces every declared statistic with a weighted sum, ignoringStatisticSpec.additive, so it cannot produce the observed range the M-step needs to keep the fitted support around the data (see_shape_covering_range()) – it would silently handestimatea summed min and max. GEV therefore accumulates through the hostseq_update, which is three dot products for a univariate leaf; engine-resident scoring viabackend_seq_log_densityis unaffected. Reinstate this hook once the generated path honours non-additive support bounds.
- static backend_log_density_from_params(x, loc, scale, shape, engine)[source]
Engine-neutral GEV log-density; the
abs(xi) < tolGumbel limit is selected per element.s^{-1/xi}is computed asexp(-log(s)/xi)so the whole expression stays on engine ops.
- backend_seq_log_density(x, engine)[source]
Engine-neutral vectorized log-density for encoded data.
- classmethod backend_stacked_params(dists, engine)[source]
Stacked GEV parameters for a homogeneous mixture kernel.
- classmethod backend_stacked_log_density(x, params, engine)[source]
Return an
(n, k)matrix of GEV log densities.
- cdf(x)[source]
Cumulative distribution function
P(X <= x)(exact).
- mean()[source]
Mean: loc + scale*(Gamma(1-xi)-1)/xi (loc+scale*euler_gamma at xi=0); inf for xi>=1.
- Return type:
- variance()[source]
Variance: scale^2 (Gamma(1-2xi)-Gamma(1-xi)^2)/xi^2 (scale^2 pi^2/6 at xi=0); inf for xi>=1/2.
- Return type:
- entropy()[source]
Differential entropy log(scale) + euler_gamma * xi + euler_gamma + 1.
- Return type:
- sampler(seed=None)[source]
Return a sampler for drawing observations from this distribution.
- Parameters:
seed (int | None)
- Return type:
GeneralizedExtremeValueSampler
- estimator(pseudo_count=None)[source]
Return a method-of-moments estimator for
loc,scaleandshape.- Parameters:
pseudo_count (float | None)
- Return type:
GeneralizedExtremeValueEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution for vectorized methods.
- Return type:
GeneralizedExtremeValueDataEncoder
- class GeneralizedExtremeValueSampler(dist, seed=None)[source]
Bases:
DistributionSamplerDraw iid GEV observations by inverse-CDF transform.
- Parameters:
dist (GeneralizedExtremeValueDistribution)
seed (int | None)
- class GeneralizedExtremeValueAccumulator(name=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate weighted first three moments and the observed range for GEV estimation.
The range is not a moment: it is the support bound the estimate has to respect, since a GEV with
xi != 0is bounded on one side and moment matching alone can place that bound inside the sample. See_shape_covering_range().Alongside the raw sums the accumulator keeps a CONDITIONING-GATED shift-anchored track,
sum_i w_i (x_i - anchor)^kfork = 1..3about a data anchor. The method of moments needs central moments, and differencing them out of raw power sums is the classic cancellation-prone form: at sd ~0.6 and offset 1.7e9 the raw variance is wrong by a factor of thousands and the raw third moment has no correct digits at all, which drives the shape onto its bound and the scale tens of times too large – silently. Anchoring keeps every term of the scatterO(count * spread^3), 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 onGeneralizedExtremeValueSuffStat; a consumer that drops the payload simply gets the historical raw estimate back.- update(x, weight, estimate)[source]
Accumulate weighted first three raw moments and the observed range 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 first three raw moments and the observed range 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 GEV sufficient-statistic tuple.
- value()[source]
Return raw moment sums, observation count, and the observed range.
The returned object is a plain 6-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 andGeneralizedExtremeValueEstimator.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 while preserving the observed range.
The shift-anchored track scales with the raw sums; leaving it behind would turn a scaled accumulator back into the ill-conditioned raw path.
- Parameters:
c (float)
- Return type:
GeneralizedExtremeValueAccumulator
- acc_to_encoder()[source]
Return the encoder used by this accumulator.
- Return type:
GeneralizedExtremeValueDataEncoder
- class GeneralizedExtremeValueAccumulatorFactory(name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for GeneralizedExtremeValueAccumulator.
- make()[source]
Create a fresh GEV accumulator.
- Return type:
GeneralizedExtremeValueAccumulator
- class GeneralizedExtremeValueEstimator(pseudo_count=None, suff_stat=None, min_scale=1.0e-12, xi_max=1.0 / 3.0 - 1.0e-4, xi_min=-1.0, name=None, keys=None, prior_central=None)[source]
Bases:
ParameterEstimatorMethod-of-moments estimator for GEV location, scale and shape.
This is a moment estimator, not an MLE: the shape is solved from the skewness-vs-
xirelation, and the shape is additionally constrained so the fitted support covers the observed range (see_shape_covering_range()). Whenever that constraint rewrites the shape – or the rewritten shape still scores the extreme observation catastrophically and the estimate falls back to the Gumbel limit – the returned distribution is not the raw moment fit, and the change is recorded innumerical_repairs()sofit_provenance()carries it (MXR-080-1202).The reduced moments are formed about a reference point rather than about zero whenever the accumulated statistics carry a shift-anchored payload (see
GeneralizedExtremeValueAccumulator), which makes the fit shift-equivariant:estimateonx + creturnsloc + cwithscaleandshapeunchanged. 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 GEV raw-moment statistics.
- Return type:
GeneralizedExtremeValueAccumulatorFactory