torch.distributions.RelaxedBernoulli
class RelaxedBernoulli extends Distributionnew RelaxedBernoulli(temperature: number | Tensor, options: {
probs?: number | number[] | Tensor;
logits?: number | number[] | Tensor;
} & DistributionOptions)
- readonly
temperature(Tensor) - – Temperature parameter controlling the relaxation. Lower temperature = more discrete-like.
- readonly
arg_constraints(unknown) - readonly
support(unknown) - readonly
has_rsample(unknown) - readonly
probs(Tensor) - – Get probability of success.
- readonly
logits(Tensor) - – Get log-odds.
- readonly
mean(Tensor) - readonly
mode(Tensor) - readonly
variance(Tensor)
Relaxed Bernoulli distribution: continuous relaxation of Bernoulli via Concrete/Gumbel-Softmax.
The RelaxedBernoulli is a continuous relaxation of the Bernoulli distribution using the Gumbel-Softmax (Concrete) trick. Essential for:
- Reparameterized gradients through discrete-like samples
- Differentiable discrete sampling
- Variational inference with discrete variables
- Annealing from continuous to discrete (temperature scheduling)
- Neural network architecture search
As temperature → 0, the distribution approaches a Bernoulli. At temperature = 1, the distribution is more uniform.
Examples
const m = new RelaxedBernoulli(0.5, { probs: torch.tensor([0.7]) });
m.sample(); // relaxed sample in (0, 1)