RelaxedOneHotCategorical
_RelaxedFamilyRelaxedOneHotCategorical(temperature: Tensor | float, probs: Tensor | None = None, logits: Tensor | None = None, validate_args: bool | None = None)Concrete distribution — a continuous relaxation of OneHotCategorical.
RelaxedOneHotCategorical(temperature=τ, probs=p) defines a
distribution over the open -simplex whose samples are
differentiable surrogates for one-hot categorical samples. As
the distribution concentrates on the
vertices of the simplex (recovering one-hot samples); as
samples approach the uniform distribution over
the simplex.
This is the Gumbel-softmax distribution of Jang et al. (2017) and the Concrete distribution of Maddison et al. (2017).
It is a lucid.distributions.TransformedDistribution: an
ExpRelaxedCategorical (base_dist) pushed through an
lucid.distributions.transforms.ExpTransform (transforms).
Parameters
temperatureTensor | float(..., K). Normalised internally.
Mutually exclusive with logits.(..., K).
Mutually exclusive with probs.validate_ argsbool | None= NoneTrue, validate parameter constraints at construction time.Attributes
temperatureTensorprobsTensorlogits on access.logitsTensorprobs
on access.base_ distExpRelaxedCategoricaltransformslist[Transform][ExpTransform()].Notes
Reparameterised sampling (Gumbel-softmax trick):
The result (open simplex) is differentiable w.r.t. and .
Log-PDF (Maddison et al. 2017, Eq. 1):
Examples
>>> import lucid
>>> from lucid.distributions import RelaxedOneHotCategorical
>>> dist = RelaxedOneHotCategorical(
... temperature=0.5,
... probs=lucid.tensor([0.1, 0.4, 0.5]),
... )
>>> samples = dist.rsample((50,))
>>> samples.shape # (50, 3) — lies on the open simplex
(50, 3)
>>> bool(((samples.sum(dim=-1) - 1.0).abs() < 1e-5).all()) # each row sums to ~1
TrueUsed by 1
Constructors
1__init__
→None__init__(temperature: Tensor | float, probs: Tensor | None = None, logits: Tensor | None = None, validate_args: bool | None = None)Construct a RelaxedOneHotCategorical (Concrete) distribution.
Parameters
temperatureTensor | float(..., K) on the K-simplex.
Rows are automatically normalised to sum to 1. Mutually exclusive
with logits.(..., K). Mutually
exclusive with probs.validate_ argsbool | None= NoneTrue, validate parameter constraints at construction time.Raises
ValueErrorprobs and logits are provided.