RelaxedBernoulli
_RelaxedFamilyRelaxedBernoulli(temperature: Tensor | float, probs: Tensor | float | None = None, logits: Tensor | float | None = None, validate_args: bool | None = None)Concrete (Gumbel-sigmoid) relaxation of the Bernoulli distribution.
RelaxedBernoulli(temperature=τ, probs=p) defines a continuous
distribution over whose samples are differentiable
surrogates for Bernoulli samples. As the distribution
concentrates on , recovering the discrete Bernoulli.
As the distribution approaches
.
The Concrete distribution (Maddison et al. 2017) / Gumbel-softmax (Jang et al. 2017) trick enables gradient-based optimisation through discrete latent variables in variational autoencoders and related models.
It is a lucid.distributions.TransformedDistribution: a
LogitRelaxedBernoulli (base_dist) pushed through a
lucid.distributions.transforms.SigmoidTransform (transforms).
Parameters
temperatureTensor | floatlogits.probs.validate_ argsbool | None= NoneTrue, validate parameter constraints at construction time.Attributes
temperatureTensorprobsTensorlogits on access.logitsTensorprobs on
access.base_ distLogitRelaxedBernoullitransformslist[Transform][SigmoidTransform()].Notes
Reparameterised sampling (Gumbel-sigmoid trick):
where is the sigmoid function. Gradients propagate through both and .
Log-PDF (Maddison et al. 2017, the binary Concrete density):
where . The first three terms are the logistic density of ; the last two are the Jacobian of the sigmoid that maps it into . A value of 0 or 1 is scored one step inside the interval, as the reference framework's inverse sigmoid does.
Examples
>>> import lucid
>>> from lucid.distributions import RelaxedBernoulli
>>> _ = lucid.manual_seed(0)
>>> dist = RelaxedBernoulli(temperature=0.5, probs=0.7)
>>> samples = dist.rsample((100,))
>>> # Samples are in (0, 1)
>>> bool(((samples > 0) & (samples < 1)).all())
TrueUsed by 1
Constructors
1__init__
→None__init__(temperature: Tensor | float, probs: Tensor | float | None = None, logits: Tensor | float | None = None, validate_args: bool | None = None)Construct a RelaxedBernoulli (Binary Concrete) distribution.
Parameters
temperatureTensor | floatlogits.probs.validate_ argsbool | None= NoneTrue, validate parameter constraints at construction time.Raises
ValueErrorprobs and logits are provided.