class

Gumbel

extendsDistribution
Gumbel(loc: Tensor | float, scale: Tensor | float, validate_args: bool | None = None)
source

Gumbel (Type-I extreme value) distribution on R\mathbb{R}.

Continuous distribution that models the maximum (or minimum) of a sample drawn from a number of distributions with exponential-like tails. It is the limiting distribution of the maximum of IID exponential-tailed variables (Fisher–Tippett–Gnedenko theorem) and is the basis of the celebrated Gumbel-max trick for differentiable sampling from categorical distributions.

Parameters

locTensor or float
Location parameter μR\mu \in \mathbb{R} (mode of the density).
scaleTensor or float
Scale parameter s>0s > 0.
validate_argsbool= None
If True, validate parameter constraints at construction time.

Notes

Probability density (with z=(xμ)/sz = (x - \mu)/s):

p(x;μ,s)=1sexp ⁣((z+ez))p(x; \mu, s) = \frac{1}{s} \exp\!\bigl(-(z + e^{-z})\bigr)

Cumulative distribution:

F(x;μ,s)=exp ⁣(ez)F(x; \mu, s) = \exp\!\bigl(-e^{-z}\bigr)

Moments:

E[X]=μ+sγE,Var[X]=π2s26\mathbb{E}[X] = \mu + s\,\gamma_{\mathrm{E}}, \qquad \mathrm{Var}[X] = \frac{\pi^2 s^2}{6}

where γE0.5772\gamma_{\mathrm{E}} \approx 0.5772 is the Euler–Mascheroni constant. The mode is μ\mu and the entropy is logs+γE+1\log s + \gamma_{\mathrm{E}} + 1.

Gumbel-softmax trick: if giGumbel(0,1)g_i \sim \mathrm{Gumbel}(0, 1) IID and πi\pi_i are category probabilities, then argmaxi(logπi+gi)\arg\max_i (\log \pi_i + g_i) is a sample from Categorical(π)\mathrm{Categorical}(\pi). Replacing the argmax with a softmax yields a continuous relaxation that supports gradient flow through discrete choices (Jang et al., 2017; Maddison et al., 2017).

Examples

>>> import lucid
>>> from lucid.distributions import Gumbel
>>> d = Gumbel(loc=0.0, scale=1.0)
>>> d.rsample((4,))
Tensor([...])
>>> d.log_prob(lucid.tensor(0.0))
Tensor(-1.0)

Methods (7)

dunder

__init__

None
__init__(loc: Tensor | float, scale: Tensor | float, validate_args: bool | None = None)
source

Initialise a Gumbel distribution.

Parameters

locTensor | float
Location parameter μR\mu \in \mathbb{R}. Shifts the distribution along the real line.
scaleTensor | float
Scale parameter s>0s > 0. Stretches the distribution.
validate_argsbool | None= None
If True, validate parameter constraints at construction time.
prop

mean

Tensor
mean: Tensor
source

μ + s · γ where γ is the Euler–Mascheroni constant.

prop

variance

Tensor
variance: Tensor
source

(π · s)² / 6.

prop

mode

Tensor
mode: Tensor
source

Mode of the Gumbel distribution.

Returns

Tensor

The location parameter μ\mu, which coincides with the mode of the Gumbel PDF.

fn

rsample

Tensor
rsample(sample_shape: tuple[int, ...] = ())
source

Reparameterised sample via the Gumbel icdf: μ − s · log(−log U).

fn

log_prob

Tensor
log_prob(value: Tensor)
source

Log-probability density of the Gumbel distribution.

Parameters

valueTensor
Point(s) xRx \in \mathbb{R} at which to evaluate the density.

Returns

Tensor

Log-density logp(x)=(z+ez)logs\log p(x) = -(z + e^{-z}) - \log s where z=(xμ)/sz = (x - \mu) / s.

fn

entropy

Tensor
entropy()
source

log(s) + γ + 1.