A Bernoulli distribution models one binary outcome: exactly two possible categories, such as heads and tails or 0 and 1. Its parameter specifies the probability assigned to one outcome, with the remaining probability assigned to the other. section 2.1.7
Use the distribution as follows:
- Represent binary observations with a discrete probability distribution rather than a continuous density. section 2.1.7
- Implement the model with category labels such as heads and tails or with indices such as 0 and 1. section 2.1.7
- Distinguish the Bernoulli class from a fully specified distribution: assigning a parameter, such as 0.4, instantiates it. section 2.1.7
Pyro parameterization
In Pyro, Bernoulli(probs=0.4) creates a Bernoulli distribution whose designated outcome has probability 0.4; evaluating its log probability for 1 and exponentiating returns approximately 0.4. section 2.1.7
Listing 2.3 Canonical parameters in Pyro
import torch from pyro.distributions import Bernoulli, Categorical, Gamma, Normal #1 print(Categorical(probs=torch.tensor([.45, .30, .25]))) #2 print(Normal(loc=0.0, scale=1.0)) print(Bernoulli(probs=0.4)) print(Gamma(concentration=1.0, rate=2.0))
Inspect the canonical Pyro construction alongside categorical, normal, and gamma distributions. section 2.1.7

