§3.4–3.9.1Marginals · Conditionals · Chain Rule · Independence · Expectation, Variance, Covariance · Bernoulli

Part I DL pp. 58–62 · ~5 min read

  • marginal probability
  • conditional probability
  • chain rule of probability
  • independence
  • conditional independence
  • expectation
  • variance
  • covariance
  • covariance matrix
  • bernoulli distribution

§3.4 Marginal probability

Given a joint distribution over several variables, the distribution of just a subset is the marginal probability distribution, found with the sum rule:

Term by term

xx,  P(x=x)=yP(x=x,y=y)\forall x \in \mathrm{x},\; P(\mathrm{x} = x) = \sum_y P(\mathrm{x} = x, \mathrm{y} = y)
P(x,y)P(x, y)the joint — how likely each COMBINATION of states isa grid of numbers
y\sum_ysum a whole row: every way y could turn out while x = xcollapse one axis
P(x)P(x)the marginal — written, historically, in the MARGIN of the paper grid; hence the nameone number per row

(Continuous variables integrate instead: p(x)=p(x,y)dyp(x) = \int p(x, y)\,dy.) The etymology is literal — try it:

A joint P(weather, activity) — marginals in the margins; click a row to condition
dependent: cells deviate from P(x)·P(y)
a=walka=caféa=museumP(w) →w=rain0.050.150.200.40w=sun0.350.150.100.600.400.300.30P(a) ↓

click a row label to condition on it — the margins already show both marginals

§3.5 Conditional probability

The probability of an event given that another has happened is a conditional probability :

Term by term

P(y=yx=x)=P(y=y,x=x)P(x=x)P(\mathrm{y} = y \mid \mathrm{x} = x) = \frac{P(\mathrm{y} = y, \mathrm{x} = x)}{P(\mathrm{x} = x)}
P(y,x)P(y, x)how often y AND x happen togetherjoint cell
P(x)P(x)how often the condition happens at all — must be > 0, or the conditional is undefinedrow marginal
P(yx)P(y \mid x)zoom into the world where x happened, renormalize so that world sums to 1renormalized row

In the widget above, clicking a row performs exactly this renormalization.

Aside — conditioning is not intervening

P(German citizen | speaks German) is high — but teaching a random person German does not move them to Germany. Computing the consequences of an action is an intervention query, the domain of causal modeling, which this book does not cover. Conditioning only filters observations.

§3.6 The chain rule of conditional probabilities

Any joint distribution factors into one-variable conditionals — the chain rule (or product rule): P(x(1),,x(n))=P(x(1))i=2nP(x(i)x(1),,x(i1))P(\mathrm{x}^{(1)}, \dots, \mathrm{x}^{(n)}) = P(\mathrm{x}^{(1)}) \prod_{i=2}^n P(\mathrm{x}^{(i)} \mid \mathrm{x}^{(1)}, \dots, \mathrm{x}^{(i-1)}). It falls straight out of the definition, applied repeatedly:

The book's three-variable example — two applications of the definition
P(a,b,c)=P(ab,c)P(b,c)P(\mathrm{a}, \mathrm{b}, \mathrm{c}) = P(\mathrm{a} \mid \mathrm{b}, \mathrm{c})\, P(\mathrm{b}, \mathrm{c})

step 1/3: Apply the conditional-probability definition once, treating (b, c) as a block.

§3.7 Independence and conditional independence

Two variables are independent (xy\mathrm{x} \bot \mathrm{y}) when their joint factorizes: p(x,y)=p(x)p(y)p(x, y) = p(x)\,p(y) for every pair of values — the grid becomes an outer product of its margins (flip the widget above to its independent version: same marginals, different joint!). They are conditionally independent given z\mathrm{z} (xyz\mathrm{x} \bot \mathrm{y} \mid \mathrm{z}) when the factorization holds within every slice zz.

§3.8 Expectation, variance and covariance

The expectation (expected value) of f(x)f(x) under PP is the average value ff takes when xx is drawn from PP:

Expectation — the average under a distribution

ExP[f(x)]=xP(x)f(x)(or  p(x)f(x)dx)\mathbb{E}_{\mathrm{x} \sim P}[f(x)] = \sum_x P(x)\, f(x) \quad\text{(or}\; \int p(x) f(x)\, dx\text{)}
f(x)f(x)any function of the random variableper-state value
P(x)P(x)the weight each state contributesprobability
E[]\mathbb{E}[\cdot]LINEAR: E[αf + βg] = αE[f] + βE[g] — the property everything later leans onweighted average

The variance Var(f(x))=E[(f(x)E[f(x)])2]\mathrm{Var}(f(x)) = \mathbb{E}\big[(f(x) - \mathbb{E}[f(x)])^2\big] measures spread around the mean (low variance = values cluster); its square root is the standard deviation. The covariance Cov(f(x),g(y))=E[(f(x)E[f(x)])(g(y)E[g(y)])]\mathrm{Cov}(f(x), g(y)) = \mathbb{E}\big[(f(x) - \mathbb{E}[f(x)])(g(y) - \mathbb{E}[g(y)])\big] measures linear co-variation (and carries the variables’ scales; correlation normalizes the scales away).

Worked example — a two-coin expectation

Let x\mathrm{x} be a die roll, f(x)=xf(x) = x. Then E[x]=i=1616i=3.5\mathbb{E}[x] = \sum_{i=1}^6 \tfrac{1}{6} i = 3.5, and Var(x)=16(i3.5)2=35122.92\mathrm{Var}(x) = \sum \tfrac{1}{6}(i - 3.5)^2 = \tfrac{35}{12} \approx 2.92, so the standard deviation is 1.71\approx 1.71: rolls typically land a couple of pips from 3.5.

Covariance is NOT dependence. Independence ⟹ zero covariance, and nonzero covariance ⟹ dependence — but zero covariance does not imply independence, because covariance only sees linear relationships:

x ∼ U(−1, 1); s = ±1 with probability ½ each; y = s·x

x fully determines the magnitude of y — maximal dependence — yet the two branches cancel: Cov(x, y) = 0. Independence is the stronger property; it excludes nonlinear relationships too.

For a random vector xRn\mathbf{x} \in \mathbb{R}^n, the covariance matrix collects everything: Cov(x)i,j=Cov(xi,xj)\mathrm{Cov}(\mathbf{x})_{i,j} = \mathrm{Cov}(x_i, x_j), with the variances Var(xi)\mathrm{Var}(x_i) on the diagonal — the object the multivariate Gaussian is built around.

§3.9.1 The Bernoulli distribution

The Bernoulli distribution covers a single binary variable via one parameter ϕ[0,1]\phi \in [0, 1]: P(x=1)=ϕP(\mathrm{x} = 1) = \phi, P(x=0)=1ϕP(\mathrm{x} = 0) = 1 - \phi — compactly P(x=x)=ϕx(1ϕ)1xP(\mathrm{x} = x) = \phi^x (1-\phi)^{1-x} — with E[x]=ϕ\mathbb{E}[\mathrm{x}] = \phi and Var(x)=ϕ(1ϕ)\mathrm{Var}(\mathrm{x}) = \phi(1 - \phi):

Bernoulli — one slider, whole distribution; variance peaks at φ = ½
0.80P(x)x = 00.30x = 10.70

mean = φ = 0.70, variance = φ(1−φ) = 0.210 (largest at φ = ½)

Check yourself — marginals to Bernoulli

1.In the JointGrid, where does the name 'marginal probability' come from?

2.You click the 'rain' row (marginal 0.40) whose cells are [0.05, 0.15, 0.20]. Predict the conditional P(activity | rain).

3.The widget's independent table has the SAME marginals as the dependent one. What changed?

4.In the y = s·x construction (scatter figure), why is Cov(x, y) = 0 despite total dependence?

5.In the Bernoulli explorer, where is the variance φ(1−φ) largest, and why does that make intuitive sense?

5 questions