Overview of probability distributions: Bernoulli, binomial, Poisson, uniform, normal and exponential
The six most important distributions with their definitions, expected values and variances — the Galton board, the Poisson limit theorem, the 68–95–99.7 rule and when to use which distribution.
Series AI basics Part 17 of 52
- Map of artificial intelligence: what is what and how it all fits together
- A brief history of artificial intelligence: from Turing to language models
- Data, model, training, inference: the basic terms on a single example
- How to read mathematical notation: symbols, indices, sums and quantifiers
- Sets and relations: the building blocks of definitions in AI
- Functions and mappings: why every AI model is a function
- Logic and proofs: the rules AI reasons by
- Graphs and trees: the structure that both search and neural networks stand on
- Linear algebra for machine learning: vectors, matrices and why AI mostly multiplies
- Derivatives, the gradient and the chain rule: how a model finds out which way to learn
- Gradient descent: how a model learns
- What probability is: from rolling dice to the Kolmogorov axioms
- Conditional probability and Bayes’ theorem: how to update your estimate when you learn something new
- Random variables and the cumulative distribution function: one function that tells you everything about a distribution
- Probability density and probability mass functions: why a continuous variable has zero probability at a point
- Expected value, variance and covariance: where a distribution lies, how wide it is and what goes with what
- Overview of probability distributions: Bernoulli, binomial, Poisson, uniform, normal and exponential
- Law of large numbers and central limit theorem: why averages behave so predictably
- Statistics and parameter estimation: maximum likelihood, MAP and confidence intervals
- Information theory: entropy, cross-entropy and KL divergence — where loss functions come from
- State-space search: BFS, DFS, UCS and A* with animations
- Games and adversaries: minimax, alpha-beta pruning and Monte Carlo tree search
- Constraint satisfaction: backtracking, constraint propagation and AC-3 on sudoku and a map of Czech regions
- Logic and knowledge systems: forward and backward chaining, resolution and expert systems
- Planning: STRIPS, the blocks world, heuristics from relaxation and planning in AI agents
- Local search and simulated annealing: a travelling salesman through the Czech regional capitals
- Genetic algorithms: population, crossover, mutation and selection on a backpack for a hike
- Evolution strategies and genetic programming: from the one-fifth rule to Kepler’s law
- Ant colony optimization: how a pheromone trail finds a short path
- Particle swarm optimisation: inertia, personal experience and the swarm’s experience
- Neuroevolution: evolving the weights and shape of neural networks, and the NEAT algorithm
- Fuzzy sets and membership functions: how to write down “somewhat warm”
- Fuzzy logic and probability: why “somewhat warm” does not mean “probably warm”
- Fuzzy logic: t-norms, implications and IF–THEN rules
- Fuzzy control: Mamdani and Sugeno from a fan to a pole on a cart
- Fuzzy clustering: the fuzzy c-means algorithm and points between clusters
- Neuro-fuzzy systems (ANFIS): fuzzy rules that learn from data
- Markov chains: the transition matrix, the stationary distribution and PageRank
- Hidden Markov models: the Viterbi algorithm and the dishonest casino
- Bayesian networks: why the grass is wet and what it means for the sprinkler
- The Kalman filter: how to estimate where a car is and how fast it goes from imprecise measurements
- Types of machine learning: supervised, unsupervised, semi-supervised and more
- Prompts, context and RAG: how to give a model the right information
- Variational autoencoders (VAE): new images from a continuous latent space
- Generative adversarial networks (GAN): the forger versus the detective
- Diffusion models: how pure noise becomes an image
- Markov decision processes: states, actions, rewards and the Bellman equations
- Q-learning and DQN: learning the value of actions, from a table to a neural network
- Policy gradient and PPO: learning the policy directly
- How an AI agent works: a language model in a loop with tools
- Programming with AI agents: the task, tests and review
- Evaluating and securing AI systems: how to measure and how to keep watch
Full series syllabus 52 of 83 topics published
- What the Bernoulli, binomial and Poisson distributions describe and how they are related.
- When to use the uniform, normal and exponential distributions and what the 68–95–99.7 rule says.
- Which distributions are behind classification, loss functions and generative models in AI.
Useful to know first: Expected value, variance and covariance: where a distribution lies, how wide it is and what goes with what
You can always invent a distribution from scratch — but you do not have to. A handful of situations come up again and again in practice: yes/no, a number of successes, a number of events per hour, waiting, a measurement with an error. For each of them there is a ready-made distribution with a few parameters and a known expected value and variance. This part is an overview of the six most important ones — and above all of when to use which.
It builds on the parts Probability density function and Expected value and variance.
1. Bernoulli distribution
Definition — Bernoulli distribution
Let (Ω, 𝓕, P) be a probability space, X : Ω → ℝ a random variable and p ∈ [0, 1]. For x ∈ ℝ we write P(X = x) as shorthand for P({ω ∈ Ω : X(ω) = x}). The variable X has the Bernoulli distribution with parameter p, written X ~ Bernoulli(p), if and only if
P(X = 1) = p ∧ P(X = 0) = 1 − p.
Since p + (1 − p) = 1, X takes, with probability 1, only the values 0 and 1: the value 1 (“success”) with probability p, the value 0 (“failure”) with probability 1 − p.
One trial, two outcomes: it worked (1) or it did not (0). A coin toss, a click on an ad, spam or not spam. The single parameter p is the chance of success.
Both options can be written as a single formula, which will come in handy later with loss functions:
P(X = k) = pk · (1 − p)1 − k, k ∈ {0, 1}
- pk
- the chance of success; the exponent k “switches it on” only for k = 1, for k = 0 it gives p0 = 1
- (1 − p)1 − k
- the chance of failure; the exponent 1 − k, on the contrary, switches it on only for k = 0
- k ∈ {0, 1}
- the variable has no other values — outside them the probability is 0
The expected value is p and the variance is p(1 − p) — largest at p = 0.5, when the outcome is least predictable.
Example — the expected value and variance of Bernoulli(0.3)
E[X] = 0 · (1 − p) + 1 · p = p = 0.3
E[X2] = 02 · (1 − p) + 12 · p = p = 0.3 (because 02 = 0 and 12 = 1)
Var(X) = E[X2] − (E[X])2 = p − p2 = p(1 − p) = 0.3 · 0.7 = 0.21
For p = 0.5 the result would be 0.25 — a variable with values 0 and 1 cannot do better, because p(1 − p) is a parabola with its vertex at 0.5.
2. Binomial distribution
Definition — binomial distribution
Let (Ω, 𝓕, P) be a probability space, X : Ω → ℝ a random variable, n ∈ ℕ, n ≥ 1, and p ∈ [0, 1]. For k ∈ {0, 1, …, n} denote by
(n choose k) = n!/k! · (n − k)!
the binomial coefficient (the number of k-element subsets of an n-element set; m! = 1 · 2 · … · m and 0! = 1). The variable X has the binomial distribution with parameters n and p, written X ~ Bin(n, p), if and only if
∀k ∈ {0, 1, …, n} : P(X = k) = (n choose k) · pk · (1 − p)n−k.
By the binomial theorem these probabilities add up to (p + 1 − p)n = 1, so X takes, with probability 1, only the values 0, 1, …, n. Bin(1, p) is the same as Bernoulli(p).
The number of successes in n independent trials, each with the same chance p. The binomial coefficient counts the ways to spread k successes among n trials. In ten coin tosses, exactly five heads come up with probability 252/1024 ≈ 0.246 — less than once in every four tries. Eight or more heads, with probability just 56/1024 ≈ 0.055.
P(X = k) = (n choose k) · pk · (1 − p)n−k
- (n choose k)
- in how many orders you can arrive at the same number of successes — each has the same probability, so it is enough to multiply it by their count
- pk
- k successes, each with chance p; the trials are independent, which is why the probabilities multiply
- (1 − p)n−k
- the remaining n − k trials must end in failure — otherwise there would be more than k successes
Example — five and eight heads in ten tosses
(10 choose 5) = 10!/5! · 5! = 10 · 9 · 8 · 7 · 6/5 · 4 · 3 · 2 · 1 = 30,240/120 = 252
p5 · (1 − p)5 = 0.55 · 0.55 = 0.510 = 1/1024 ⇒ P(X = 5) = 252 · 1/1024 = 252/1024 ≈ 0.246
(10 choose 8) + (10 choose 9) + (10 choose 10) = 45 + 10 + 1 = 56 ⇒ P(X ≥ 8) = 56 · 1/1024 = 56/1024 ≈ 0.055
The colours match the terms of the formula above. For a coin p = 1 − p = 0.5, so the second and third terms give the same 1/1024 for every k and everything is decided by the binomial coefficient.
A binomial variable is the sum of n independent Bernoulli variables, so by linearity its expected value is np and its variance np(1 − p). The Galton board shows this nicely: at each of ten pegs a ball bounces either left or right, every bounce is one Bernoulli trial, and the bin where the ball lands is the number of bounces to the right — Bin(10, 0.5).
The balls pile up in the middle into a bell — and that shape is no accident. As we will see with the normal distribution and in the next part, the sum of many small random effects always gives a bell.
The dashed counts are 120 · P(X = k): we expect 120 · 0.246 ≈ 29.5 balls in the middle bin and 120/1024 ≈ 0.1 in the outermost ones. The expected value is np = 10 · 0.5 = 5, the variance np(1 − p) = 2.5 and the standard deviation √2.5 ≈ 1.58 bins. The simulation with 120 balls put 26 into the middle bin — it differs randomly from the expectation, as it should.
3. Poisson distribution
Definition — Poisson distribution
Let (Ω, 𝓕, P) be a probability space, X : Ω → ℝ a random variable and λ ∈ ℝ, λ > 0. Denote ℕ0 = {0, 1, 2, …}. The variable X has the Poisson distribution with parameter λ, written X ~ Pois(λ), if and only if
∀k ∈ ℕ0 : P(X = k) = e−λ · λk/k!.
Since ∑k=0∞ λk/k! = eλ, these probabilities add up to 1 and X takes, with probability 1, only values from ℕ0.
The number of events in a given time, when they arrive independently and λ of them on average in that time: e-mails per hour, requests to a server per second, typos on a page. If an e-mail arrives once every 2 minutes on average, we expect λ = 2 of them in 4 minutes. None arrives with probability e−2 ≈ 0.135, exactly two with probability 0.271.
P(X = k) = e−λ · λk/k!
- e−λ
- the probability that nothing arrives; at the same time it normalises — the sum of λk/k! over all k is eλ, so e−λ makes sure the probabilities add up to 1
- λk
- each of the k events “contributes” the average rate λ — the larger λ is, the more weight large values of k get
- k!
- the order of the events does not matter — λk would count every group of k events k! times, once for each order; in the proof below this is the k! from the binomial coefficient
Example — the number of e-mails in 4 minutes
P(X = 0) = e−2 · 20/0! = e−2 ≈ 0.135
P(X = 1) = e−2 · 2/1 ≈ 0.271
P(X = 2) = e−2 · 4/2 ≈ 0.271
P(X = 3) = e−2 · 8/6 ≈ 0.180, P(X = 4) = e−2 · 16/24 ≈ 0.090
The colours match the terms of the formula above. Each next probability is the previous one times λ/k. As long as k < λ it grows, then it falls — so for a whole-number λ the two most likely values are λ − 1 and λ.
A peculiarity of the Poisson distribution: the expected value and the variance are both equal to λ.
Theorem — Poisson limit theorem
Let λ ∈ ℝ, λ > 0, and k ∈ ℕ0 be fixed. For every n ∈ ℕ, n > λ, let Xn ~ Bin(n, λ/n) (the condition n > λ guarantees λ/n ∈ [0, 1]). Then
limn→∞ P(Xn = k) = e−λ · λk/k!.
Proof. For n ≥ k we split the binomial probability with p = λ/n into four factors:
(n choose k) · (λ/n)k · (1 − λ/n)n−k = n(n − 1)⋯(n − k + 1)/nk · λk/k! · (1 − λ/n)n · (1 − λ/n)−k
As n → ∞: the first factor is a product of k fractions n − i/n → 1 (i = 0, …, k − 1), the third → e−λ (because limn→∞ (1 + x/n)n = ex for every x ∈ ℝ) and the fourth → 1−k = 1.
What remains is λk/k! · e−λ. ∎
The Poisson distribution is a binomial one with a huge number of trials and a small chance in each. Split 4 minutes into n short slots; in each, an e-mail arrives with chance 2/n. The finer you split, the closer the binomial distribution gets to the Poisson one: the total deviation is 0.125 for 5 slots, 0.024 for 20 and 0.005 for 100.
Definition — total variation distance between two distributions
Let P, Q : ℤ → [0, 1] be two probability distributions on the set of integers ℤ, i.e. ∑k ∈ ℤ P(k) = ∑k ∈ ℤ Q(k) = 1, and for A ⊆ ℤ write P(A) = ∑k ∈ A P(k) and Q(A) = ∑k ∈ A Q(k). The total variation distance (total deviation) between P and Q is the number
d(P, Q) = 1/2 · ∑k ∈ ℤ |P(k) − Q(k)| ∈ [0, 1].
We have d(P, Q) = maxA ⊆ ℤ |P(A) − Q(A)|, and the maximum is attained for A = {k ∈ ℤ : P(k) > Q(k)}. The total deviation is thus the largest difference the two distributions can give in the probability of the same event. The half is there because whatever one distribution has in excess at some k, it lacks elsewhere — without it we would count every difference twice.
4. Uniform distribution
Definition — continuous uniform distribution
Let (Ω, 𝓕, P) be a probability space, X : Ω → ℝ a random variable and a, b ∈ ℝ, a < b. The variable X has the uniform distribution on the interval [a, b], written X ~ U(a, b), if and only if it has the density f : ℝ → [0, ∞),
f(x) = 1/b − a for x ∈ [a, b], f(x) = 0 for x ∉ [a, b].
That is, for every x ∈ ℝ, P(X ≤ x) = ∫−∞x f(t) dt; the probability of every subinterval [c, d] ⊆ [a, b] is then d − c/b − a and depends only on its length.
Every piece of the interval is equally likely — the model for “I know nothing except the bounds”. Waiting for a bus that runs every 10 minutes is U(0, 10). A computer's random number generator returns U(0, 1), and samples from every other distribution are made from exactly that.
The expected value is the midpoint of the interval, a + b/2, and the variance is (b − a)²/12. For the bus, then, you wait 5 minutes on average, with a standard deviation of √100/12 ≈ 2.89 minutes.
Example — the expected value and variance of the uniform distribution
E[X] = ∫ab x/b − a dx = b2 − a2/2(b − a) = a + b/2
E[X2] = ∫ab x2/b − a dx = b3 − a3/3(b − a) = a2 + ab + b2/3
Var(X) = a2 + ab + b2/3 − (a + b)2/4 = a2 − 2ab + b2/12 = (b − a)2/12
The bus U(0, 10): E[X] = 0 + 10/2 = 5, Var(X) = (10 − 0)2/12 = 100/12 ≈ 8.33, σ ≈ 2.89 minutes
The probability of a stretch is its length times the height 1/b − a: the probability that you wait longer than 7 minutes is 10 − 7/10 = 0.3.
How do you make a sample of another distribution from U(0, 1)? The simplest approach is the inverse transform method: a random number u from U(0, 1) is plugged into the inverse distribution function of the desired distribution. The distribution function F(x) = P(X ≤ x) grows from 0 to 1, so every u “points” to one value x — and the values where F grows steeply (where the density is high) get more of the u.
vzorek_bernoulli(p):
u ← random number from U(0, 1)
return 1 if u < p, otherwise 0 # P(u < p) = p
vzorek_exponencialni(λ):
u ← random number from U(0, 1)
return −ln(1 − u) / λ # inverse of F(x) = 1 − e^(−λx)
For λ = 0.5, u = 0.5 gives a wait of −ln 0.5/0.5 ≈ 1.39 minutes (the median) and u = 0.9 a wait of −ln 0.1/0.5 ≈ 4.61 minutes.
5. Normal distribution
Definition — normal distribution
Let (Ω, 𝓕, P) be a probability space, X : Ω → ℝ a random variable, μ ∈ ℝ and σ ∈ ℝ, σ > 0. For y ∈ ℝ we write exp(y) = ey. The variable X has the normal (Gaussian) distribution with parameters μ and σ², written X ~ N(μ, σ²), if and only if it has the density f : ℝ → (0, ∞),
f(x) = 1/σ√2π · exp(−(x − μ)²/2σ²), x ∈ ℝ.
The parameter μ is then the expected value and σ² the variance of X (σ is its standard deviation).
The famous bell curve: most values around the mean μ, symmetric on both sides and thinning out faster and faster the further you go. That is what people's heights, measurement errors and sensor noise look like — everything that arises by adding up many small independent effects.
f(x) = 1/σ√2π · exp(−(x − μ)²/2σ²)
- 1/σ√2π
- the normalising constant — the area under exp(−z²/2) alone is √2π, stretched by σ it is σ√2π; dividing by it makes the total area 1, as a density should have
- exp(−…)
- the exponential of a negative number lies between 0 and 1 and falls very quickly with the distance from the centre — which is why the “tails” of the bell hold so few values
- (x − μ)²
- the distance from the mean, squared — the square makes the curve symmetric (a deviation of −3 and of +3 give the same) and highest at x = μ
- 2σ²
- the scale — the distance is measured in multiples of σ, so a larger σ stretches the bell sideways; the two makes the variance come out exactly σ²
Example — the density of height N(175, 7²)
At the mean: (175 − 175)² = 0, so exp(0) = 1 and f(175) = 1/7 · √2π = 1/7 · 2.5066 ≈ 0.0570 per centimetre
At 189 cm: (189 − 175)²/2 · 49 = 196/98 = 2, f(189) = 0.0570 · e−2 ≈ 0.0077
The colours match the terms of the formula above.
Two σ further out the density is e−2 ≈ 7.4 times lower. Density is not probability: roughly 0.057 · 1 cm ≈ 5.7% of men are between 175 and 176 cm tall.
Definition — standard normal distribution
The normal distribution N(0, 1), i.e. with parameters μ = 0 and σ = 1, is called the standard normal distribution. Its density is denoted φ : ℝ → (0, ∞),
φ(z) = 1/√2π · exp(−z²/2), z ∈ ℝ.
Standardization. Let μ ∈ ℝ, σ > 0 and X ~ N(μ, σ²). Then the random variable
Z = X − μ/σ satisfies Z ~ N(0, 1).
All normal distributions are one and the same, only shifted and stretched. Subtract the mean from a value and divide by σ, and you get “how many standard deviations from the mean” — and for that, a single table covers them all.
The normal distribution follows the 68–95–99.7 rule: 68.27% of values fall within σ of the mean, 95.45% within 2σ and 99.73% within 3σ. If adult men's height has a mean of 175 cm and σ = 7 cm, 95% of them are between 161 and 189 cm. Chebyshev's inequality from the previous part guaranteed only 75% for 2σ — the normal distribution is much more “tightly packed”.
The density of the normal distribution has no antiderivative in closed form, so the percentages above are computed numerically — here with Simpson's rule, that is, by adding up very thin slices of area.
Definition — the distribution function Φ of the standard normal distribution
Let Z ~ N(0, 1) and let φ be the density of the standard normal distribution. The distribution function of the standard normal distribution is the function Φ : ℝ → (0, 1),
Φ(z) = P(Z ≤ z) = ∫−∞z φ(t) dt = ∫−∞z 1/√2π · exp(−t²/2) dt, z ∈ ℝ.
Let μ ∈ ℝ, σ > 0 and X ~ N(μ, σ²). From standardization and the symmetry φ(−t) = φ(t), for every x ∈ ℝ and every k > 0
P(X ≤ x) = Φ(x − μ/σ), P(|X − μ| < kσ) = Φ(k) − Φ(−k) = 2Φ(k) − 1.
Φ(z) is the area under the bell to the left of z. A height of 189 cm lies 189 − 175/7 = 2 standard deviations above the mean, 161 cm two below it, and between them lies 2Φ(2) − 1 ≈ 0.9545 — hence the 95% in the rule above.
Algorithm — Simpson's rule
Input: a function f : [a, b] → ℝ (computable at every point), bounds a, b ∈ ℝ, a < b, and an even number n ∈ ℕ, n ≥ 2 (the number of pieces).
Output: a number Sn ∈ ℝ, an approximate value of the integral ∫ab f(x) dx.
Steps:
- Piece width: h = b − a/n.
- Division points: xi = a + ih for i = 0, 1, …, n (so x0 = a, xn = b).
- On each pair of neighbouring pieces [x2j, x2j+2], j = 0, …, n/2 − 1, we replace f by the parabola through the three points (x2j, f(x2j)), (x2j+1, f(x2j+1)), (x2j+2, f(x2j+2)) and add up the areas under the parabolas; the result is Sn = h/3 · [f(x0) + 4f(x1) + 2f(x2) + 4f(x3) + … + 4f(xn−1) + f(xn)], i.e. inner points with an odd index have weight 4, with an even index weight 2, and the end points weight 1.
- Return Sn.
Termination: the algorithm always finishes, after evaluating f at n + 1 points. The accuracy is chosen in advance through the number of pieces n; for f with a continuous fourth derivative the error shrinks in proportion to h4.
simpson(f, a, b, n): # n even
h ← (b − a) / n
s ← f(a) + f(b)
for i = 1 … n − 1:
s ← s + (4 if i is odd, otherwise 2) · f(a + i·h)
return s · h / 3
P(|Z| < 1) for n = 2, h = 1: 1/3 · [φ(−1) + 4φ(0) + φ(1)] = 1/3 · [0.2420 + 1.5958 + 0.2420] ≈ 0.6932
n = 4: 0.6831, n = 10: 0.6827, n = 2000 (this website): 0.682689
φ is the density of N(0, 1). Even with two pieces the error is only about 1 percentage point, and it keeps shrinking with the fourth power of the piece width h — twice as many pieces make it roughly sixteen times smaller.
6. Exponential distribution
Definition — exponential distribution
Let (Ω, 𝓕, P) be a probability space, X : Ω → ℝ a random variable and λ ∈ ℝ, λ > 0. The variable X has the exponential distribution with parameter (rate) λ, written X ~ Exp(λ), if and only if it has the density f : ℝ → [0, ∞),
f(x) = λ e−λx for x ≥ 0, f(x) = 0 for x < 0.
Equivalently, X has the distribution function F(x) = 1 − e−λx for x ≥ 0 and F(x) = 0 for x < 0.
The waiting time until the next event, when events arrive independently, λ per unit of time on average. It is the e-mail wait from the part on density: λ = 0.5 per minute, expected value 1/λ = 2 minutes, variance 1/λ² = 4.
The exponential and the Poisson distributions describe the same process from two sides. That no e-mail arrives in 4 minutes has probability e−2 ≈ 0.135 according to Poisson — and according to the exponential distribution P(X > 4) = e−0.5 · 4, the very same number.
Theorem — memorylessness of the exponential distribution
Let λ > 0, X ~ Exp(λ) and s, t ∈ ℝ, s, t ≥ 0. Then P(X > s) > 0, so the conditional probability below is defined, and
P(X > s + t | X > s) = P(X > t).
Proof. P(X > x) = ∫x∞ λe−λu du = e−λx. The event “X > s + t” is part of the event “X > s”, so by the definition of conditional probability
P(X > s + t | X > s) = P(X > s + t)/P(X > s) = e−λ(s + t)/e−λs = e−λt = P(X > t). ∎
For λ = 0.5, s = 3, t = 2: e−2.5/e−1.5 = e−1 ≈ 0.368
The wait does not remember how long it has already lasted. You have been waiting for an e-mail for 3 minutes and nothing — the chance that you will wait at least 2 more minutes is still e−1 ≈ 0.368, just as if you were starting afresh. A bus running to a timetable is not like that; radioactive decay and the arrivals of independent requests are.
7. Cheat sheet: which distribution when
| Distribution | What it describes | E[X] | Var(X) |
|---|---|---|---|
| Bernoulli(p) | a single yes/no trial | p | p(1 − p) |
| Bin(n, p) | number of successes in n trials | np | np(1 − p) |
| Pois(λ) | number of events in a time span | λ | λ |
| U(a, b) | “anything between a and b” | a + b/2 | (b − a)²/12 |
| N(μ, σ²) | sum of many small effects | μ | σ² |
| Exp(λ) | waiting for the next event | 1/λ | 1/λ² |
8. Distributions in artificial intelligence
- Bernoulli and binary classification. Logistic regression and a network with a single output both predict the parameter p of a Bernoulli distribution — “how likely is this to be spam”. The loss function (binary cross-entropy) is the negative logarithm of its probability.
L(y, p) = −ln [ py · (1 − p)1 − y ] = −y ln p − (1 − y) ln(1 − p)
- −ln
- the logarithm turns a product over many examples into a sum, and the minus turns “as probable as possible” into “as small a loss as possible” — a probability close to 1 gives a loss close to 0
- py
- the probability the model gave to class 1 — it counts only when that class actually occurred (y = 1)
- (1 − p)1 − y
- the probability of class 0 — it counts only when that one occurred (y = 0)
- y ∈ {0, 1}
- the true class; it works as the switch from the Bernoulli formula broken down above
A model that assigns spam p = 0.9 has, for y = 1, a loss of −ln 0.9 ≈ 0.105, but if the message was not spam (y = 0), a loss of −ln (1 − 0.9) = −ln 0.1 ≈ 2.303 (colours as in the formula above) — a confident mistake costs 22 times more. The same reasoning applied to the normal distribution gives the mean squared error: −ln f(y) = (y − μ)²/2σ² + ln(σ√2π), and since the second term does not depend on μ, minimising −ln f is the same as minimising (y − μ)².
- The categorical distribution is Bernoulli for more than two options. The softmax at the end of a language model returns exactly its parameters — the probability of every word in the vocabulary.
- The normal distribution is everywhere: the initial weights of networks are drawn from N(0, σ²), the mean squared error corresponds to assuming normal noise, and diffusion models generate images by gradually denoising pure N(0, 1).
- Dropout switches off each neuron during training with a Bernoulli probability; the uniform distribution is the source of all random numbers.
- Poisson and exponential model traffic: how many requests hit a server, when the next one arrives, how many GPUs are needed.
9. Summary
- Bernoulli is a single yes/no trial; binomial is the number of successes in n independent trials.
- Poisson counts events in a time span and is the limit of the binomial for many trials with a small chance.
- Uniform gives the same density to the whole interval; exponential measures waiting and has no memory.
- The normal distribution is a bell determined by μ and σ; within ±σ, ±2σ and ±3σ lie 68.27%, 95.45% and 99.73% of values.
- Choosing a distribution means choosing a model: whatever describes the data also determines the model's loss function.
Do you see it differently? Write to support@coden-app.com.