Introduction
In this part, we will define some basics of probability theory that are essential for understanding advanced probabilistic machine learning.
Firstly, some notation.
Notation
Vectors: Bold lowercase, e.g., x \mathbf{x} x
Matrices: Bold uppercase, e.g., X \mathbf{X} X
Random variables, vectors, and matrices: Sansserif font, e.g., X \mathsf{X} X , x \mathsf{\mathbf{x}} x , X \mathsf{\mathbf{X}} X
Sets: Calligraphic font, e.g., X \mathcal{X} X
Definition 1 (Discrete Random Variable) Probability mass function, p x ( x ) = p ( x ) p_{\mathsf{x}}(x) = p(x) p x ( x ) = p ( x ) , with,
0 ≤ p ( x ) ≤ 1 , ∑ x ∈ X p ( x ) = 1 0 \leq p(x) \leq 1, \quad \sum_{x \in \mathcal{X}} p(x) = 1 0 ≤ p ( x ) ≤ 1 , x ∈ X ∑ p ( x ) = 1 The joint distribution of two discrete random variables x \mathsf{x} x and y \mathsf{y} y is defined as,
p x , y ( x , y ) = p ( x , y ) p_{\mathsf{x},\mathsf{y}}(x, y) = p(x, y) p x , y ( x , y ) = p ( x , y ) The conditional distribution of x \mathsf{x} x given y \mathsf{y} y is defined as,
p x ∣ y ( x ∣ y ) = p ( x ∣ y ) p_{\mathsf{x} \mid \mathsf{y}}(x \mid y) = p(x \mid y) p x ∣ y ( x ∣ y ) = p ( x ∣ y ) The marginal probability distribution of x \mathsf{x} x can be found from the joint distribution as,
p ( x ) = ∑ y ∈ Y p ( x , y ) p(x) = \sum_{y \in \mathcal{Y}} p(x, y) p ( x ) = y ∈ Y ∑ p ( x , y ) In general,
p ( x 1 , … , x i − 1 , x i + 1 , … , x n ) = ∑ x i ∈ X i p ( x 1 , … , x n ) p(x_1, \ldots, x_{i - 1}, x_{i + 1}, \ldots, x_n) = \sum_{x_i \in \mathcal{X}_i} p(x_1, \ldots, x_n) p ( x 1 , … , x i − 1 , x i + 1 , … , x n ) = x i ∈ X i ∑ p ( x 1 , … , x n ) Lastly, Bayes’ theorem states that,
p ( x ∣ y ) ≔ p ( y ∣ x ) p ( x ) p ( y ) p(x \mid y) \coloneqq \frac{p(y \mid x) p(x)}{p(y)} p ( x ∣ y ) : = p ( y ) p ( y ∣ x ) p ( x )
Definition 2 (Continuous Random Variable) Probability density function: Describes the probability of the value of a continuous random variable x \mathsf{x} x falling within a given interval.
The probability that x \mathsf{x} x falls within the interval [ a , b ] [a, b] [ a , b ] is,
p ( a ≤ x ≤ b ) = ∫ a b p ( x ) d x p(a \leq \mathsf{x} \leq b) = \int_{a}^{b} p(x) \, dx p ( a ≤ x ≤ b ) = ∫ a b p ( x ) d x Moreover, the following properties (must) hold,
p ( x ) ≥ 0 , ∫ − ∞ ∞ p ( x ) d x = 1 p(x) \geq 0, \quad \int_{-\infty}^{\infty} p(x) \, dx = 1 p ( x ) ≥ 0 , ∫ − ∞ ∞ p ( x ) d x = 1 Marginalizatio of p ( x , y ) p(x, y) p ( x , y ) with respect to y y y gives,
p ( x ) = ∫ y p ( x , y ) d y p(x) = \int_y p(x, y) \, dy p ( x ) = ∫ y p ( x , y ) d y
Recall (Expectation, Variance, and Covariance) The expectation (or, the average value of f ( x ) f(x) f ( x ) under probability distribution p ( x ) p(x) p ( x ) ) is defined as,
E x [ f ( x ) ] ≔ E [ f ( x ) ] = ∑ x p ( x ) f ( x ) (discrete case) E x [ f ( x ) ] ≔ E [ f ( x ) ] = ∫ p ( x ) f ( x ) d x (continuous case) \begin{align*}
\mathbb{E}_{\mathsf{x}}[f(\mathsf{x})] & \coloneqq \mathbb{E}[f(\mathsf{x})] = \sum_x p(x) f(x) \quad \text{(discrete case)} \newline
\mathbb{E}_{\mathsf{x}}[f(\mathsf{x})] & \coloneqq \mathbb{E}[f(\mathsf{x})] = \int p(x) f(x) \, dx \quad \text{(continuous case)}
\end{align*} E x [ f ( x )] E x [ f ( x )] : = E [ f ( x )] = x ∑ p ( x ) f ( x ) (discrete case) : = E [ f ( x )] = ∫ p ( x ) f ( x ) d x (continuous case) The sample mean, given N N N points { x i } \{x_i\} { x i } drawn from p ( x ) p(x) p ( x ) , is defined as,
E [ f ( x ) ] ≃ 1 N ∑ i = 1 N f ( x i ) \mathbb{E}[f(\mathsf{x})] \simeq \frac{1}{N} \sum_{i=1}^{N} f(x_i) E [ f ( x )] ≃ N 1 i = 1 ∑ N f ( x i ) with,
lim N → ∞ 1 N ∑ i = 1 N f ( x i ) = E [ f ( x ) ] \lim_{N \to \infty} \frac{1}{N} \sum_{i=1}^{N} f(x_i) = \mathbb{E}[f(\mathsf{x})] N → ∞ lim N 1 i = 1 ∑ N f ( x i ) = E [ f ( x )] For expectations of functions of several variables, we will keep the subscript to indicate the variable averaged over, e.g.,
E x [ f ( x , y ) ] or E x ∼ p ( x ) [ f ( x , y ) ] \mathbb{E}_{\mathsf{x}}[f(\mathsf{x}, \mathsf{y})] \quad \text{or} \quad \mathbb{E}_{\mathsf{x} \sim p(x)}[f(\mathsf{x}, \mathsf{y})] E x [ f ( x , y )] or E x ∼ p ( x ) [ f ( x , y )] Further, the conditional expectation is defined as,
E x ∼ p ( x ∣ y ) [ f ( x ∣ y ) ] ≔ ∑ x p ( x ∣ y ) f ( x ∣ y ) \mathbb{E}_{\mathsf{x} \sim p(x \mid y)}[f(\mathsf{x} \mid y)] \coloneqq \sum_x p(x \mid y) f(x \mid y) E x ∼ p ( x ∣ y ) [ f ( x ∣ y )] : = x ∑ p ( x ∣ y ) f ( x ∣ y ) The variance (how much variability there is in f ( x ) f(x) f ( x ) around its expected value) is defined as,
V a r [ f ( x ) ] ≔ E [ ( f ( x ) − E [ f ( x ) ] ) 2 ] \mathrm{Var}[f(\mathsf{x})] \coloneqq \mathbb{E}[(f(\mathsf{x}) - \mathbb{E}[f(\mathsf{x})])^2] Var [ f ( x )] : = E [( f ( x ) − E [ f ( x )] ) 2 ] Thus, the variance of x \mathsf{x} x is,
V a r [ x ] = E [ x 2 ] − ( E [ x ] ) 2 \mathrm{Var}[\mathsf{x}] = \mathbb{E}[\mathsf{x}^2] - (\mathbb{E}[\mathsf{x}])^2 Var [ x ] = E [ x 2 ] − ( E [ x ] ) 2 Finally, the covariance of x \mathsf{x} x and y \mathsf{y} y (the extent to which x \mathsf{x} x and y \mathsf{y} y vary together) is defined as,
C o v [ x , y ] ≔ E x , y [ ( x − E [ x ] ) ( y − E [ y ] ) ] = E x , y [ x y ] − E [ x ] E [ y ] \begin{align*}
\mathrm{Cov}[\mathsf{x}, \mathsf{y}] & \coloneqq \mathbb{E}_{\mathsf{x}, \mathsf{y}}[(\mathsf{x} - \mathbb{E}[\mathsf{x}])(\mathsf{y} - \mathbb{E}[\mathsf{y}])] \newline
& = \mathbb{E}_{\mathsf{x}, \mathsf{y}}[\mathsf{x} \mathsf{y}] - \mathbb{E}[\mathsf{x}] \mathbb{E}[\mathsf{y}]
\end{align*} Cov [ x , y ] : = E x , y [( x − E [ x ]) ( y − E [ y ])] = E x , y [ xy ] − E [ x ] E [ y ] The covariance of two random vectors is defined as,
C o v [ x , y ] ≔ E x , y [ ( x − E [ x ] ) ( y T − E [ y T ] ) ] \mathrm{Cov}[\mathsf{\mathbf{x}}, \mathsf{\mathbf{y}}] \coloneqq \mathbb{E}_{\mathsf{\mathbf{x}}, \mathsf{\mathbf{y}}}[(\mathsf{\mathbf{x}} - \mathbb{E}[\mathsf{\mathbf{x}}])(\mathsf{\mathbf{y}^T} - \mathbb{E}[\mathsf{\mathbf{y}^T}])] Cov [ x , y ] : = E x , y [( x − E [ x ]) ( y T − E [ y T ])]
Probabilities: Frequentist VS. Bayesian
In the frequentist interpretation, the relative frequency of occurrence of an outcome after repeating an experiment a large number of times defines the probability of that outcome,
p ≔ lim N → ∞ k N p \coloneqq \lim_{N \to \infty} \frac{k}{N} p : = N → ∞ lim N k
Only repeatable random events have probabilities in this interpretation!
However, in the Bayesian interpretation, it quantifies the uncertainty of events happening.
The probability is a measure of the belief or confidence regarding the occurrence of an event. The prior belief about an event will likely change when new information is revealed.
Example 1 Assume that 90% of people with Creutzfeldt-Jakob (KJ) disease 1 ate hamburgers.
The probability of an individual to have KJ is one in 100,000.
Assuming half of the population eat hamburgers, what is the probability that a hamburger eater will have KJ disease?
Firstly, we define the events having KJ disease as K J KJ K J and eating hamburgers as H H H .
Thus, we want to know p ( K J = yes ∣ H = yes ) p(KJ = \text{yes} \mid H = \text{yes}) p ( K J = yes ∣ H = yes ) .
Consider the following population of one million people.
Table 1: Hamburger consumption and KJ disease in a population of one million.
H = yes H = \text{yes} H = yes
H = no H = \text{no} H = no
K J = yes KJ = \text{yes} K J = yes
9
1
K J = no KJ = \text{no} K J = no
499,991
499,999
From the table we see that,
p ( K J = yes ) = 10 6 × 1 10 5 = 10 p ( H = yes ∣ K J = yes ) = 9 10 = 0.9 p ( H = yes ) = 50 % ⟹ 500 , 000 people \begin{align*}
p(KJ = \text{yes}) & = 10^6 \times \frac{1}{10^5} = 10 \newline
p(H = \text{yes} \mid KJ = \text{yes}) & = \frac{9}{10} = 0.9 \newline
p(H = \text{yes}) & = 50\% \implies 500,000 \text{ people}
\end{align*} p ( K J = yes ) p ( H = yes ∣ K J = yes ) p ( H = yes ) = 1 0 6 × 1 0 5 1 = 10 = 10 9 = 0.9 = 50% ⟹ 500 , 000 people Now,
p ( K J = yes ∣ H = yes ) = p ( H = yes ∣ K J = yes ) p ( K J = yes ) p ( H = yes ) = 0.9 × 10 500 , 000 = 0.000018 = 1.8 × 10 − 5 \begin{align*}
p(KJ = \text{yes} \mid H = \text{yes}) & = \frac{p(H = \text{yes} \mid KJ = \text{yes}) \, p(KJ = \text{yes})}{p(H = \text{yes})} \newline
& = \frac{0.9 \times 10}{500,000} = 0.000018 = 1.8 \times 10^{-5}
\end{align*} p ( K J = yes ∣ H = yes ) = p ( H = yes ) p ( H = yes ∣ K J = yes ) p ( K J = yes ) = 500 , 000 0.9 × 10 = 0.000018 = 1.8 × 1 0 − 5
Intuition (Bayesian Approach) In the Bayesian approach, we start with our hypothesis x \mathsf{x} x (e.g., patient has a disease or not) and our data y \mathsf{y} y (e.g., test result or patient symptoms).
p ( x ∣ y ) = p ( y ∣ x ) p ( x ) p ( y ) p(\mathsf{x} \mid \mathsf{y}) = \frac{p(\mathsf{y} \mid \mathsf{x}) p(\mathsf{x})}{p(\mathsf{y})} p ( x ∣ y ) = p ( y ) p ( y ∣ x ) p ( x ) We call p ( x ) p(\mathsf{x}) p ( x ) our prior belief in the hypothesis before looking at any data.
p ( y ∣ x ) p(\mathsf{y} \mid \mathsf{x}) p ( y ∣ x ) is the likelihood of the data if the hypothesis is true.
p ( y ) p(\mathsf{y}) p ( y ) is called the marginal likelihood (commonness of the data).
Finally, p ( x ∣ y ) p(\mathsf{x} \mid \mathsf{y}) p ( x ∣ y ) is our posterior belief in the hypothesis after seeing the data.
Consider the following setup. Let D ≔ { x 1 , … , x N } \mathcal{D} \coloneqq \{\mathbf{x}_1, \ldots, \mathbf{x}_N\} D : = { x 1 , … , x N } be our observed variables (the data) and θ ≔ ( θ 1 , … , θ M ) \boldsymbol{\theta} \coloneqq (\theta_1, \ldots, \theta_M) θ : = ( θ 1 , … , θ M ) be our latent variables (the parameters we want to learn/find).
In probabilistic modeling, we treat both observed and latent variables as random variables.
Can we model a relationship between D \mathcal{D} D and θ \boldsymbol{\theta} θ via p ( D ∣ θ ) p(\mathcal{D} \mid \boldsymbol{\theta}) p ( D ∣ θ ) ?
Many inference problems are of the form,
p ( θ ∣ D ) = p ( D ∣ θ ) p ( θ ) p ( D ) p(\boldsymbol{\theta} \mid \mathcal{D}) = \frac{p(\mathcal{D} \mid \boldsymbol{\theta}) p(\boldsymbol{\theta})}{p(\mathcal{D})} p ( θ ∣ D ) = p ( D ) p ( D ∣ θ ) p ( θ ) Seeing quantities as functions of θ \boldsymbol{\theta} θ , p ( D ) p(\mathcal{D}) p ( D ) can be viewed as a normalization constant and we can rewrite the equation as,
p ( θ ∣ D ) ∝ p ( D ∣ θ ) p ( θ ) p(\boldsymbol{\theta} \mid \mathcal{D}) \propto p(\mathcal{D} \mid \boldsymbol{\theta}) p(\boldsymbol{\theta}) p ( θ ∣ D ) ∝ p ( D ∣ θ ) p ( θ ) Most probable a posterior (maximum a posterior, MAP) setting,
θ MAP ⋆ = arg max θ p ( θ ∣ D ) . \boldsymbol{\theta}^{\star}_{\text{MAP}} = \underset{\boldsymbol{\theta}}{\arg \max} p(\boldsymbol{\theta} \mid \mathcal{D}). θ MAP ⋆ = θ arg max p ( θ ∣ D ) . If p ( θ ) p(\boldsymbol{\theta}) p ( θ ) is constant (i.e., uniform prior), then the MAP estimate reduces to the maximum likelihood (ML) estimate,
θ ML ⋆ = arg max θ p ( D ∣ θ ) . \boldsymbol{\theta}^{\star}_{\text{ML}} = \underset{\boldsymbol{\theta}}{\arg \max} p(\mathcal{D} \mid \boldsymbol{\theta}). θ ML ⋆ = θ arg max p ( D ∣ θ ) .
Example 2 (Tossing a Biased Coin) Imagine we have a random variable x ∈ { 0 , 1 } \mathsf{x} \in \{0, 1\} x ∈ { 0 , 1 } representing the outcome of tossing a (biased) coin flip (0 = tails, 1 = heads) with unknown bias μ ∈ [ 0 , 1 ] \mu \in [0, 1] μ ∈ [ 0 , 1 ] (i.e., the probability of getting heads).
p ( x = 1 ) = μ , p ( x = 0 ) = 1 − μ p(\mathsf{x} = 1) = \mu, \quad p(\mathsf{x} = 0) = 1 - \mu p ( x = 1 ) = μ , p ( x = 0 ) = 1 − μ Thus, the goal is, given a data set D = { x 1 , … , x N } \mathcal{D} = \{x_1, \ldots, x_N\} D = { x 1 , … , x N } estimate μ \mu μ , i.e., the probability that a toss will result in heads, p ( μ ∣ D ) p(\mu \mid \mathcal{D}) p ( μ ∣ D ) .
By applying Bayes’ theorem, we have,
p ( μ ∣ D ) = p ( D ∣ μ ) p ( μ ) p ( D ) ∝ p ( D ∣ μ ) p ( μ ) p(\mu \mid \mathcal{D}) = \frac{p(\mathcal{D} \mid \mu) p(\mu)}{p(\mathcal{D})} \propto p(\mathcal{D} \mid \mu) p(\mu) p ( μ ∣ D ) = p ( D ) p ( D ∣ μ ) p ( μ ) ∝ p ( D ∣ μ ) p ( μ ) We note that a single coin toss corresponds to a Bernoulli random variable,
p ( x ∣ μ ) = B e r n ( x ; μ ) = μ x ( 1 − μ ) 1 − x p(\mathsf{x} \mid \mu) = \mathrm{Bern}(\mathsf{x}; \mu) = \mu^{\mathsf{x}} (1 - \mu)^{1 - \mathsf{x}} p ( x ∣ μ ) = Bern ( x ; μ ) = μ x ( 1 − μ ) 1 − x with,
E [ x ] = μ V a r [ x ] = μ ( 1 − μ ) \begin{align*}
\mathbb{E}[\mathsf{x}] & = \mu \newline
\mathrm{Var}[\mathsf{x}] & = \mu (1 - \mu)
\end{align*} E [ x ] Var [ x ] = μ = μ ( 1 − μ ) Thus, for N N N independent coin tosses,
p ( D ∣ μ ) = ∏ i = 1 N p ( x i ∣ μ ) = ∏ i = 1 N μ x i ( 1 − μ ) 1 − x i = μ ∑ i = 1 N x i ( 1 − μ ) N − ∑ i = 1 N x i = μ h ( 1 − μ ) N − h \begin{align*}
p(\mathcal{D} \mid \mu) & = \prod_{i=1}^{N} p(x_i \mid \mu) \newline
& = \prod_{i=1}^{N} \mu^{x_i} (1 - \mu)^{1 - x_i} \newline
& = \mu^{\sum_{i=1}^{N} x_i} (1 - \mu)^{N - \sum_{i=1}^{N} x_i} \newline
& = \mu^{h} (1 - \mu)^{N - h}
\end{align*} p ( D ∣ μ ) = i = 1 ∏ N p ( x i ∣ μ ) = i = 1 ∏ N μ x i ( 1 − μ ) 1 − x i = μ ∑ i = 1 N x i ( 1 − μ ) N − ∑ i = 1 N x i = μ h ( 1 − μ ) N − h where h h h is the number of heads observed in the data set D \mathcal{D} D . To be explicit, how we went from a product to a sum is by taking the logarithm of the product,
Now, in the frequentist approach, we can estimate μ \mu μ by maximizing p ( D ∣ μ ) p(\mathcal{D} \mid \mu) p ( D ∣ μ ) , i.e., the maximum likelihood estimate 2 ,
log p ( D ∣ μ ) = ∑ i = 1 N log p ( x i ∣ μ ) = ∑ i = 1 N log ( μ x i ( 1 − μ ) 1 − x i ) = ∑ i = 1 N ( x i log μ + ( 1 − x i ) log ( 1 − μ ) ) = ∑ i = 1 N x i log μ + ∑ i = 1 N ( 1 − x i ) log ( 1 − μ ) \begin{align*}
\log p(\mathcal{D} \mid \mu) & = \sum_{i=1}^{N} \log p(x_i \mid \mu) \newline
& = \sum_{i=1}^{N} \log \left( \mu^{x_i} (1 - \mu)^{1 - x_i} \right) \newline
& = \sum_{i=1}^{N} \left( x_i \log \mu + (1 - x_i) \log(1 - \mu) \right) \newline
& = \sum_{i=1}^{N} x_i \log \mu + \sum_{i=1}^{N} (1 - x_i) \log(1 - \mu) \newline
\end{align*} log p ( D ∣ μ ) = i = 1 ∑ N log p ( x i ∣ μ ) = i = 1 ∑ N log ( μ x i ( 1 − μ ) 1 − x i ) = i = 1 ∑ N ( x i log μ + ( 1 − x i ) log ( 1 − μ ) ) = i = 1 ∑ N x i log μ + i = 1 ∑ N ( 1 − x i ) log ( 1 − μ ) By differentiating and equating to zero, we obtain the ML estimator,
μ ML ⋆ = 1 N ∑ i = 1 N x i = h N \mu^{\star}_{\text{ML}} = \frac{1}{N} \sum_{i=1}^{N} x_i = \frac{h}{N} μ ML ⋆ = N 1 i = 1 ∑ N x i = N h i.e., the fraction of heads observed in the data set.
In the Bayesian approach,
p ( μ ∣ D ) ≔ p ( D ∣ μ ) p ( μ ) p ( D ) ∝ p ( D ∣ μ ) p ( μ ) p(\mu \mid \mathcal{D}) \coloneqq \frac{p(\mathcal{D} \mid \mu) p(\mu)}{p(\mathcal{D})} \propto p(\mathcal{D} \mid \mu) p(\mu) p ( μ ∣ D ) : = p ( D ) p ( D ∣ μ ) p ( μ ) ∝ p ( D ∣ μ ) p ( μ ) with p ( D ∣ μ ) = μ h ( 1 − μ ) N − h p(\mathcal{D} \mid \mu) = \mu^{h} (1 - \mu)^{N - h} p ( D ∣ μ ) = μ h ( 1 − μ ) N − h as before.
In this setting, we need to specify a prior for p ( μ ) p(\mu) p ( μ ) !
Assume μ ∈ { 0.1 , 0.5 , 0.8 } \mu \in \{0.1, 0.5, 0.8\} μ ∈ { 0.1 , 0.5 , 0.8 } with,
p ( μ = 0.1 ) = 0.15 , p ( μ = 0.5 ) = 0.80 , p ( μ = 0.8 ) = 0.05 p(\mu = 0.1) = 0.15, \quad p(\mu = 0.5) = 0.80, \quad p(\mu = 0.8) = 0.05 p ( μ = 0.1 ) = 0.15 , p ( μ = 0.5 ) = 0.80 , p ( μ = 0.8 ) = 0.05 for N = 10 N = 10 N = 10 and 2 heads and 8 tails observed, i.e., h = 2 h = 2 h = 2 ,
p ( μ = 0.1 ∣ D ) = 0.4525 , p ( μ = 0.5 ∣ D ) = 0.5475 , p ( μ = 0.8 ∣ D ) = 0.00001 p(\mu = 0.1 \mid \mathcal{D}) = 0.4525, \quad p(\mu = 0.5 \mid \mathcal{D}) = 0.5475, \quad p(\mu = 0.8 \mid \mathcal{D}) = 0.00001 p ( μ = 0.1 ∣ D ) = 0.4525 , p ( μ = 0.5 ∣ D ) = 0.5475 , p ( μ = 0.8 ∣ D ) = 0.00001 for N = 100 N = 100 N = 100 with 20 heads and 80 tails observed, i.e., h = 20 h = 20 h = 20 ,
p ( μ = 0.1 ∣ D ) = 0.99999807 , p ( μ = 0.5 ∣ D ) = 1.93 × 10 − 6 , p ( μ = 0.8 ∣ D ) = 2.13 × 10 − 35 p(\mu = 0.1 \mid \mathcal{D}) = 0.99999807, \quad p(\mu = 0.5 \mid \mathcal{D}) = 1.93 \times 10^{-6}, \quad p(\mu = 0.8 \mid \mathcal{D}) = 2.13 \times 10^{-35} p ( μ = 0.1 ∣ D ) = 0.99999807 , p ( μ = 0.5 ∣ D ) = 1.93 × 1 0 − 6 , p ( μ = 0.8 ∣ D ) = 2.13 × 1 0 − 35 As we can see, as we gather more data, the influence of the prior diminishes and the posterior is dominated by the likelihood.
Now, if we now consider a continuum of parameters?
A flat (uniform) prior p ( μ ) = k p(\mu) = k p ( μ ) = k ,
∫ p ( μ ) d μ = 1 ⟹ ∫ 0 1 p ( μ ) d μ = k = 1 \int p(\mu) \, d\mu = 1 \implies \int_0^1 p(\mu) \, d\mu = k = 1 ∫ p ( μ ) d μ = 1 ⟹ ∫ 0 1 p ( μ ) d μ = k = 1 Since,
p ( μ ∣ D ) ∝ p ( D ∣ μ ) p ( μ ) = μ h ( 1 − μ ) N − h ⋅ 1 = μ h ( 1 − μ ) N − h p(\mu \mid \mathcal{D}) \propto p(\mathcal{D} \mid \mu) p(\mu) = \mu^{h} (1 - \mu)^{N - h} \cdot 1 = \mu^{h} (1 - \mu)^{N - h} p ( μ ∣ D ) ∝ p ( D ∣ μ ) p ( μ ) = μ h ( 1 − μ ) N − h ⋅ 1 = μ h ( 1 − μ ) N − h We want p ( μ ∣ D ) p(\mu \mid \mathcal{D}) p ( μ ∣ D ) to be a distribution,
p ( μ ∣ D ) = 1 c p ( D ∣ μ ) p ( μ ) = 1 c μ h ( 1 − μ ) N − h p(\mu \mid \mathcal{D}) = \frac{1}{c} p(\mathcal{D} \mid \mu) p(\mu) = \frac{1}{c} \mu^{h} (1 - \mu)^{N - h} p ( μ ∣ D ) = c 1 p ( D ∣ μ ) p ( μ ) = c 1 μ h ( 1 − μ ) N − h where the constant c c c is obtained as,
c = ∫ 0 1 μ h ( 1 − μ ) N − h d μ ≡ B ( h + 1 , N − h + 1 ) c = \int_0^1 \mu^{h} (1 - \mu)^{N - h} \, d\mu \equiv \mathrm{B}(h + 1, N - h + 1) c = ∫ 0 1 μ h ( 1 − μ ) N − h d μ ≡ B ( h + 1 , N − h + 1 ) which is the Beta distribution normalization constant.
Figure 1: Different Realizations of the Beta DistributionThe beta function is defined as,
B ( α , β ) = ∫ 0 1 μ α − 1 ( 1 − μ ) β − 1 d t \mathrm{B}(\alpha, \beta) = \int_0^1 \mu^{\alpha - 1} (1 - \mu)^{\beta - 1} \, dt B ( α , β ) = ∫ 0 1 μ α − 1 ( 1 − μ ) β − 1 d t and the corresponding beta distribution is defined as,
B e t a ( μ ; α , β ) = 1 B ( α , β ) μ α − 1 ( 1 − μ ) β − 1 = Γ ( α + β ) Γ ( α ) Γ ( β ) μ α − 1 ( 1 − μ ) β − 1 \begin{align*}
\mathrm{Beta}(\mu; \alpha, \beta) & = \frac{1}{\mathrm{B}(\alpha, \beta)} \mu^{\alpha - 1} (1 - \mu)^{\beta - 1} \newline
& = \frac{\Gamma(\alpha + \beta)}{\Gamma(\alpha) \Gamma(\beta)} \mu^{\alpha - 1} (1 - \mu)^{\beta - 1}
\end{align*} Beta ( μ ; α , β ) = B ( α , β ) 1 μ α − 1 ( 1 − μ ) β − 1 = Γ ( α ) Γ ( β ) Γ ( α + β ) μ α − 1 ( 1 − μ ) β − 1 where Γ ( ⋅ ) \Gamma(\cdot) Γ ( ⋅ ) is the gamma function 3 .
Further, we can see that, if a prior is proportional to powers of μ \mu μ and ( 1 − μ ) (1 - \mu) ( 1 − μ ) , then the posterior distribution will have the same functional form as the prior!
A conjugate prior (posterior will be of same functional form as prior),
p ( μ ) = B e t a ( μ ; α , β ) = Γ ( α + β ) Γ ( α ) Γ ( β ) μ α − 1 ( 1 − μ ) β − 1 p(\mu) = \mathrm{Beta}(\mu; \alpha, \beta) = \frac{\Gamma(\alpha + \beta)}{\Gamma(\alpha) \Gamma(\beta)} \mu^{\alpha - 1} (1 - \mu)^{\beta - 1} p ( μ ) = Beta ( μ ; α , β ) = Γ ( α ) Γ ( β ) Γ ( α + β ) μ α − 1 ( 1 − μ ) β − 1 Then,
p ( μ ∣ D ) ∝ p ( D ∣ μ ) p ( μ ) ∝ μ h ( 1 − μ ) N − h ⋅ μ a − 1 ( 1 − μ ) b − 1 = μ h + a − 1 ( 1 − μ ) N − h + b − 1 \begin{align*}
p(\mu \mid \mathcal{D}) & \propto p(\mathcal{D} \mid \mu) p(\mu) \newline
& \propto \mu^{h} (1 - \mu)^{N - h} \cdot \mu^{a - 1} (1 - \mu)^{b - 1} \newline
& = \mu^{h + a - 1} (1 - \mu)^{N - h + b - 1}
\end{align*} p ( μ ∣ D ) ∝ p ( D ∣ μ ) p ( μ ) ∝ μ h ( 1 − μ ) N − h ⋅ μ a − 1 ( 1 − μ ) b − 1 = μ h + a − 1 ( 1 − μ ) N − h + b − 1 Thus, the posterior is also a beta distribution!
p ( μ ∣ D ) = B e t a ( μ ; a ′ , b ′ ) p(\mu \mid \mathcal{D}) = \mathrm{Beta}(\mu; a^{\prime}, b^{\prime}) p ( μ ∣ D ) = Beta ( μ ; a ′ , b ′ ) where a ′ = h + a a^{\prime} = h + a a ′ = h + a and b ′ = N − h + b b^{\prime} = N - h + b b ′ = N − h + b .
If we do not know anything about the coin, we can choose a uniform prior,
Figure 2: The Prior, Likelihood, and Posterior Distributions of our Example; Prior: Beta(1, 1), Likelihood: μ 4 ( 1 − μ ) \mu^{4}(1 - \mu) μ 4 ( 1 − μ ) , Posterior: Beta(5, 2)However, our posterior can act as a prior if we subsequently observe additional data, i.e., sequential inference.
Figure 3: The Prior, Likelihood, and Posterior Distributions of our Example; Prior: Beta(5, 2), Likelihood: μ 4 ( 1 − μ ) \mu^{4}(1 - \mu) μ 4 ( 1 − μ ) , Posterior: Beta(9, 3)
Summary
Summary We conclude this by (re)stating the definition of probabilistic machine learning.
We treat models and its parameters as random variables.
Learning does not provide a single model, but a distribution of likely models.
Can incorporate prior knowledge on model and parameters.