The binomial distribution models the number of successes in n independent trials when every trial has the same success probability π. It turns aggregate success statistics into probabilities for count outcomes, a useful perspective when a system predicts chances rather than inspecting each observation directly. section 5.9.3 section 5.0
Build the probability from elementary trial outcomes:
- A success has probability π, while a failure has probability 1 − π. section 5.9.3
- For one particular sequence containing k successes and n − k failures, multiply the corresponding probabilities: π^k(1 − π)^(n − k). section 5.9.3
- Because the k successes can occupy multiple positions, multiply by the number of such arrangements, C(n,k), giving P(X = k) = C(n,k)π^k(1 − π)^(n − k). section 5.9.3
- The expected count is nπ and the variance is nπ(1 − π). section 5.9.3
Three celebrity-photo trials
If 20% of photos contain a celebrity, then π = 0.2. For three randomly selected photos, the probability of exactly two celebrity photos is 0.8 × 0.2 × 0.2 + 0.2 × 0.8 × 0.2 + 0.2 × 0.2 × 0.8 = 0.096. The three terms represent the possible positions of the single failure. section 5.9.3
Table 5.8 All possible combinations of three trials
| Event Id |
Event |
Probability |
|---|---|---|
| 0 |
{F, F, F} |
(1−π) × (1−π) × (1−π) = 0.8 × 0.8 × 0.8 |
| 1 |
{F, F, S} |
(1−π) × (1−π) × π = 0.8 × 0.8 × 0.2 |
| 2 |
{F, S, F} |
(1−π) × π × (1−π) = 0.8 × 0.2 × 0.8 |
| 3 |
{F, S, S} |
(1−π) × π × π = 0.8 × 0.2 × 0.2 |
| 4 |
{S, F, F} |
π × (1−π) × (1−π) = 0.2 × 0.8 × 0.8 |
| 5 |
{S, F, S} |
π × (1−π) × π = 0.2 × 0.8 × 0.2 |
| 6 |
{S, S, F} |
π × π × (1−π) = 0.2 × 0.2 × 0.8 |
| 7 |
{S, S, S} |
π × π × π = 0.2 × 0.2 × 0.2 |
Use the table to inspect all eight success–failure sequences for three trials and see how sequences with the same success count combine. section 5.9.3
PyTorch provides torch.distributions.Binomial. Its log_prob(X) can be checked against a direct implementation using factorial-based C(n,k), powers of π and 1 − π, and a logarithm. Sampling many values also checks the theoretical mean and variance. section 5.9.3





