7 Estimation

Given indepedent observations X1,…,XnX_1, \ldots, X_n that come from some unknown, true probability distribution PP, how do we infer PP?

  1. Moment Estimation: Estimate the mean and variance of the data.

  2. Finding the full mathematical curve (the distribution) that best fits your dataset, bu tuning parameters. By learning this underlying shape, AI models can sample from it to generate new, realistic synthetic data.

  3. Regression/Classification: Supervised learning, where the observations come in pairs. An input and its corresponding label, denoted as (Xi,Yi)(X_{i}, Y_{i}). The goal is to estimate the relationship between them, such as predicting the conditional probability of a label given an input (PY|XP_{Y|X}) or the expected value (𝔼[Y|X]\mathbb{E}[Y|X]).

7.1 Estimator/Estimate

The primary goal of statistical inference (or learning) is to construct an estimator for θ*\theta_{*}.
This θ*\theta_{*} represents a true, unknown parameter associated with a probability distribution PP.
Examples of this parameter include the mean, the variance, or the parameter of a probabilistic model, pθp_{\theta}.
Estimator vs Estimate:

The 4 criteria to evaluate if an estimator is good:

7.1.1 Bias-variance decomposition

When we create an estimator (θ̂\hat{\theta}) to guess a true, unknown parameter (θ*\theta_*), we need a way to mathematically measure how "good" that guess is.
The motivation: Suppose you have independent data points X1,X2,...,XnX_1, X_2, ..., X_n and you want to estimate the true mean.

  1. θ̂1=1n∑i=1nXi\hat{\theta}_1 = \frac{1}{n} \sum_{i=1}^n X_i (The sample mean, averaging nn data points).

  2. θ̂2=X1\hat{\theta}_2 = X_1 (Just the first data point).

Both estimators are unbiased, i.e. if you repeat the experiment infinitely many times, both will eventually average out to the true mean.
However, intuitively, θ̂1\hat{\theta}_1 is a much better estimator, as it uses all the data, meaning it will fluctuate much less from sample to sample. θ̂2\hat{\theta}_2 will wildly jump around depending on what that first data point happens to be. (𝕍[hatθ1]=𝕍[hatθ2]n\mathbb{V}[hat{\theta}_1] = \frac{\mathbb{V}[hat{\theta}_2]}{n}).

The standard way to measure the quality of estimators by calculating the Expected Squared Error: 𝔼[||θ̂−θ*||2]\mathbb{E}[||\hat{\theta} - \theta_*||^2]. In other words, on average, how far away is our estimator’s guess from the actual true parameter? We can break this ESE into two separate parts: 𝔼[||θ̂−θ*||2]=𝔼[||θ̂−𝔼[θ̂]||2]+||𝔼[θ̂]−θ*||2\mathbb{E}[||\hat{\theta} - \theta_*||^2] = \mathbb{E}[||\hat{\theta} - \mathbb{E}[\hat{\theta}]||^2] + ||\mathbb{E}[\hat{\theta}] - \theta_*||^2 Notice that this translates to: Total Error = Variance + (Bias)2(\text{Bias})^2.

  1. Variance 𝕍[θ̂]\mathbb{V}[\hat{\theta}]: The first term (𝔼[||θ̂−𝔼[θ̂]||2]\mathbb{E}[||\hat{\theta} - \mathbb{E}[\hat{\theta}]||^2]) measures how much the estimator’s predictions bounce around its own average. It represents the estimator’s sensitivity to the specific random sample of data you pulled.

  2. Bias Squared ||𝔼[θ̂]−θ*||2||\mathbb{E}[\hat{\theta}] - \theta_*||^2: measures the difference between the estimator’s average prediction and the actual true parameter. It tells you if your estimator is systematically missing the mark.

What this means for statistical inference: If an estimator is completely unbiased, its Bias term is exactly 0. Therefore, its total Expected Squared Error is equal only to its Variance (𝔼[||θ̂−θ*||2]=𝕍[θ̂]\mathbb{E}[||\hat{\theta} - \theta_*||^2] = \mathbb{V}[\hat{\theta}]).
An Efficient Estimator is thus one that is unbiased AND has the minimum variance.

7.1.2 Fisher Information and Cramér-Rao Lower Bound

To find an efficient estimator, we need a mathematical floor for the absolute minimum variance.
Firstly, the Fisher Information, denoted as ℐ(θ*)\mathcal{I}(\theta_*) quantifies the amount of information that an observable random variable XX carries about an unknown parameter θ*\theta_*.
If changing the true parameter drastically changes the probability of our data, the data carries a lot of Fisher information.
It is defined as the expected value of the squared derivative of the log-likelihood: ℐ(θ*)=𝔼[(∂∂θlogpθ(X))2]\mathcal{I}(\theta_*) = \mathbb{E} \left[ \left( \frac{\partial}{\partial \theta} \log p_\theta(X) \right)^2 \right] Next, the Cramér-Rao Inequality states that the variance of any unbiased estimator θ̂\hat{\theta} cannot possibly be smaller than the inverse of the total Fisher Information provided by the nn data points. 𝕍[θ̂]≥1n⋅ℐ(θ*)\mathbb{V}[\hat{\theta}] \ge \frac{1}{n \cdot \mathcal{I}(\theta_*)} Note that as n→∞n \to \infty or the data is highly informative (ℐ(θ*)\mathcal{I}(\theta_*) is large), the Cramér-Rao lower bound gets close to zero, meaning it becomes mathematically possible to create a highly precise estimator with very little variance.

7.2 Mean Estimation

Given independent observations X1,…,Xn∼PX_1, \ldots, X_n \sim P, find the unknown, true mean of the distribution, μ1=𝔼[X1]\mu_1 = \mathbb{E}[X_1].
Define an estimator, the sample mean μ̂1=1n∑i=1nXi\hat{\mu}_1 = \frac{1}{n} \sum_{i=1}^n X_i The sample mean is itself a random variable.
Note that μ1\mu_1 refers to the first moment of the distribution, and X1,…,XnX_1, \ldots, X_n is i.i.d.
Three properties of a good estimator:

  1. Unbiased: 𝔼[μ̂1]=μ1\mathbb{E}[\hat{\mu}_{1}]=\mu_{1}.

  2. Variance shrinks with data: 𝕍[μ̂1]=𝕍[X1]n\mathbb{V}[\hat{\mu}_{1}]=\frac{\mathbb{V}[X_{1}]}{n}. Shows Effictivity and proves Consistency.

  3. Consistent: ∀ϵ>0\forall\epsilon>0, lim⁡n→∞P(|μ̂1−μ1|≤ϵ)=1\lim_{n\rightarrow\infty}P(|\hat{\mu}_{1}-\mu_{1}|\le\epsilon)=1.

7.2.0.1 Example

For some distributions, their parameter is equal to the theoretical mean.

Since we know the sample mean is a great estimator for the theoretical mean, we just find the sample mean to estimate the parameters.

7.3 Variance Estimation

Given independent observations X1,…,Xn∼PX_1, \ldots, X_n \sim P, estimate the variance σ2=𝔼[(X1−μ1)2]\sigma^2 = \mathbb{E}[(X_1 - \mu_1)^2].
Define an estimator, the sample variance σ̂12=1n∑i=1n(Xi−μ̂1)2\hat{\sigma}_{1}^{2}=\frac{1}{n}\sum_{i=1}^{n}(X_{i}-\hat{\mu}_{1})^{2} This estimator is biased, i.e. 𝔼[σ̂12]=n−1nσ12\mathbb{E}[\hat{\sigma}_1^2] = \frac{n-1}{n} \sigma_1^2.
Proof. 𝔼[σ̂12]=𝔼[1n∑i=1n(Xi−μ̂1)2]=1n𝔼[∑i=1n((Xi−μ1)−(μ̂1−μ1))2][Inject true mean μ1]=1n𝔼[∑i=1n(Xi−μ1)2−2(μ̂1−μ1)∑i=1n(Xi−μ1)+n(μ̂1−μ1)2][Expand quadratic]=1n𝔼[∑i=1n(Xi−μ1)2−2n(μ̂1−μ1)2+n(μ̂1−μ1)2][∑(Xi−μ1)=n(μ̂1−μ1)]=1n𝔼[∑i=1n(Xi−μ1)2−n(μ̂1−μ1)2]=1n[∑i=1n𝔼[(Xi−μ1)2]−n𝔼[(μ̂1−μ1)2]](Linearity of expectation)=1n[nσ12−n𝕍[μ̂1]](Definitions of σ2 and 𝕍[μ̂1])=1n[nσ12−n(σ12n)](Substitute 𝕍[μ̂1]=σ12n)=1n[nσ12−σ12]=n−1nσ12\begin{align*} \mathbb{E}[\hat{\sigma}_1^2] &= \mathbb{E}\left[ \frac{1}{n} \sum_{i=1}^n (X_i - \hat{\mu}_1)^2 \right] \\ &= \frac{1}{n} \mathbb{E}\left[ \sum_{i=1}^n ((X_i - \mu_1) - (\hat{\mu}_1 - \mu_1))^2 \right] && \text{[Inject true mean } \mu_1 \text{]} \\ &= \frac{1}{n} \mathbb{E}\left[ \sum_{i=1}^n (X_i - \mu_1)^2 - 2(\hat{\mu}_1 - \mu_1)\sum_{i=1}^n(X_i - \mu_1) + n(\hat{\mu}_1 - \mu_1)^2 \right] && \text{[Expand quadratic]} \\ &= \frac{1}{n} \mathbb{E}\left[ \sum_{i=1}^n (X_i - \mu_1)^2 - 2n(\hat{\mu}_1 - \mu_1)^2 + n(\hat{\mu}_1 - \mu_1)^2 \right] && \left[\sum(X_i - \mu_1) = n(\hat{\mu}_1 - \mu_1)\right] \\ &= \frac{1}{n} \mathbb{E}\left[ \sum_{i=1}^n (X_i - \mu_1)^2 - n(\hat{\mu}_1 - \mu_1)^2 \right] \\ &= \frac{1}{n} \left[ \sum_{i=1}^n \mathbb{E}[(X_i - \mu_1)^2] - n\mathbb{E}[(\hat{\mu}_1 - \mu_1)^2] \right] && \text{(Linearity of expectation)} \\ &= \frac{1}{n} \left[ n\sigma_1^2 - n\mathbb{V}[\hat{\mu}_1] \right] && \text{(Definitions of } \sigma^2 \text{ and } \mathbb{V}[\hat{\mu}_1]\text{)} \\ &= \frac{1}{n} \left[ n\sigma_1^2 - n\left(\frac{\sigma_1^2}{n}\right) \right] && \text{(Substitute } \mathbb{V}[\hat{\mu}_1] = \frac{\sigma_1^2}{n}\text{)} \\ &= \frac{1}{n} [n\sigma_1^2 - \sigma_1^2] \\ &= \frac{n-1}{n}\sigma_1^2 \end{align*} Define a corrected estimator: τ̂2=nn−1σ̂12=1n−1∑i=1n(Xi−μ̂1)2\hat{\tau}^{2}=\frac{n}{n-1}\hat{\sigma}_{1}^{2}=\frac{1}{n-1}\sum_{i=1}^{n}(X_{i}-\hat{\mu}_{1})^{2} 𝔼[τ̂2]=1n−1(n−1)σ12=σ12\mathbb{E}[\hat{\tau}^{2}]= \frac{1}{n-1}(n-1)\sigma_1^2 = \sigma_1^2 Consistency: Both σ̂12\hat{\sigma}_1^2 and τ̂2\hat{\tau}^2 are consistent. As n→∞n \to \infty, the difference between dividing by nn versus n−1n-1 becomes negligible, and both converge to the true variance.

7.4 Probability Density Estimation

Given training data/observations D={Xi}i=1nD = \{X_i\}_{i=1}^n, Xi∼PX_i \sim P, we choose a probabilistic model (hypothesis class of PDFs) ℱ={pθ}θ∈Θ\mathcal{F} = \{p_\theta\}_{\theta \in \Theta}.
We want to find the specific parameters θ\theta that make the model pθp_\theta the best possible approximation of the true distribution PP by fitting it to the training data.
For example, a common template to use is the Gaussian distribution. The parameters to tune are the mean and the variance, so as to fit the data.
Another example, Generative AI. Training the model entails analyzing existing examples to find the underlying probability distribution that generated them. Then during generation phase, the model draws new data samples from those estimated distributions. This random sample becomes a brand-new, synthetic image or piece of text that looks authentic because it follows the probability rules of the original data.

The model samples from the estimated distribution.

7.4.1 Maximum Likelihood Estimation (MLE)

We want to find the parameter θ\theta that makes the occurrence of {X1,…,Xn}\{X_1, \dots, X_n\} as likely as possible, i.e. maxθpθ(X1,…,Xn)\max_{\theta} p_\theta(X_1, \dots, X_n) Since we assume the observations are i.i.d., pθ(X1,…,Xn)=∏i=1npθ(Xi)p_\theta(X_1, \dots, X_n) = \prod_{i=1}^{n} p_\theta(X_i) If nn is huge, this number is very small and computers cannot handle it. Hence we take logarithm (recall the property log⁡(A×B)=log⁡A+log⁡B\log(A \times B) = \log A + \log B).
Hence, MLE is solving for maxθ∈Θ∑i=1nlog⁡pθ(Xi)\max_{\theta\in\Theta}\sum_{i=1}^{n}\log p_{\theta}(X_{i}) For very complex distributions (like deep neural networks), solving this maximization problem directly is often impossible (intractable).
Hence, use approximation methods like EM algorithm, variational Bayes / variational autoencoders (VAEs), diffusion models.

7.4.2 Kullback–Leibler (KL) divergence

KL divergence is a statistical measure that quantifies how one probability distribution differs from a second, reference probability distribution.
In estimation context, KL divergence shows how closely our estimated model qq matches the true data distribution pp.
For continuous probability densities pp and qq, the KL divergence between them is DKL(p||q)=∫p(x)log⁡p(x)q(x)dx=𝔼X∼p[logp(X)q(X)]D_{KL}(p||q) = \int p(x) \log \frac{p(x)}{q(x)} dx = \mathbb{E}_{X \sim p} \left[ \log \frac{p(X)}{q(X)} \right] Two properties of KL divergence:

  1. Non-negativity: DKL(p||q)≥0D_{KL}(p||q) \ge 0.

  2. Identity: DKL(p||q)=0D_{KL}(p||q) = 0 if and only if the two distributions are identical (p=qp = q).

7.4.3 Connection between MLE & KL divergence

From the standard MLE sum, multiply by 1n\frac{1}{n} to get the empirical average: maxθ1n∑i=1nlog⁡pθ(Xi)\max_{\theta} \frac{1}{n} \sum_{i=1}^{n} \log p_{\theta}(X_{i}) As n→∞n \to \infty, the empirical average converges to the theoretical expected value over the true data distribution pp, by Law of Large Numbers, maxθ𝔼X∼p[log⁡pθ(X)]\max_{\theta} \mathbb{E}_{X \sim p}[\log p_{\theta}(X)] To connect this to KL divergence, first subtract a constant. 𝔼X∼p[log⁡pθ(X)]∼𝔼X∼p[log⁡pθ(X)]−𝔼X∼p[log⁡p(X)]=𝔼X∼p[logpθ(X)p(X)]=−DKL(p||pθ)\begin{align*} \mathbb{E}_{X \sim p}[\log p_{\theta}(X)] &\sim \mathbb{E}_{X \sim p}[\log p_{\theta}(X)] - \mathbb{E}_{X \sim p}[\log p(X)] \\ &= \mathbb{E}_{X \sim p}\left[ \log \frac{p_{\theta}(X)}{p(X)} \right] \\ &= -D_{KL}(p || p_{\theta}) \end{align*} Maximising the log-likehood minimises the KL divergence.

7.4.4 Example - Bernoulli Distribution

Given random variable X∼Ber(θ)X \sim Ber(\theta), Pθ(X=1)=θP_\theta(X = 1) = \theta, Pθ(X=0)=1−θP\theta(X = 0) = 1 - \theta, Pθ(X)=θX⋅(1−θ)1−XP_\theta(X) = \theta^X \cdot (1 - \theta)^{1 - X} Observations are Xi∼PX_i \sim P, (i=1,2,…,ni = 1, 2, \ldots, n), which are i.i.d. The likelihood function is L(θ)=∏i=1nθXi(1−θ)1−XiL(\theta) = \prod_{i=1}^{n} \theta^{X_i} (1-\theta)^{1-X_i} Since the product is hard to calculate, the log likelihood function is ℒ(θ)=∑i=1n[Xilog(θ)+(1−Xi)log(1−θ)]\mathcal{L}(\theta) = \sum_{i=1}^{n} \left[ X_i \log(\theta) + (1-X_i) \log(1-\theta) \right] To find θ\theta that maximises the function, take the derivative wrt θ\theta and set to 0: dℒdθ=1θ∑i=1nXi−11−θ∑i=1n(1−Xi)=0\frac{d\mathcal{L}}{d\theta} = \frac{1}{\theta} \sum_{i=1}^{n} X_i - \frac{1}{1-\theta} \sum_{i=1}^{n} (1-X_i) = 0 Solving, we get θ̂=1n∑i=1nXi\hat{\theta} = \frac{1}{n} \sum_{i=1}^{n} X_i The most optimal way to estimate the probability here is just the sample mean.
For example, given 10 coin flips, D={1,1,0,1,1,1,0,1,1,0}D = \{1, 1, 0, 1, 1, 1, 0, 1, 1, 0\}, θ̂=0.7\hat{\theta} = 0.7.
Interpretation: The parameter that makes this specific dataset the most mathematically likely to occur is θ=0.7\theta = 0.7.

Is this estimator efficient? (has the lowest possible variance)
For a Bernoulli distribution, the variance of a single trial XiX_i is known to be 𝕍[Xi]=θ*(1−θ*)\mathbb{V}[X_i] = \theta_*(1-\theta_*). Then, 𝕍[θ̂]=𝕍[1n∑i=1nXi]=1n2∑i=1n𝕍[Xi]=θ*(1−θ*)n\begin{align*} \mathbb{V}[\hat{\theta}] &= \mathbb{V}\left[\frac{1}{n}\sum_{i=1}^n X_i\right] \\ &= \frac{1}{n^2} \sum_{i=1}^n \mathbb{V}[X_i] \\ &= \frac{\theta_*(1-\theta_*)}{n} \end{align*} We start with the log-likelihood of a single Bernoulli trial: log⁡P(X|θ*)=Xlog⁡(θ*)+(1−X)log⁡(1−θ*)\log P(X|\theta_*) = X\log(\theta_*) + (1-X)\log(1-\theta_*) Using the definition of Fisher information: ℐ(θ*)=𝔼[(∂∂θ*logP(X|θ*))2]=𝔼[(Xθ*−1−X1−θ*)2]=𝔼[X2θ*2−2X(1−X)θ*(1−θ*)+(1−X)2(1−θ*)2]=𝔼[Xθ*2−0+1−X(1−θ*)2]=𝔼[X]θ*2+𝔼[1−X](1−θ*)2=θ*θ*2+1−θ*(1−θ*)2=1θ*(1−θ*)\begin{align*} \mathcal{I}(\theta_*) &= \mathbb{E}\left[\left(\frac{\partial}{\partial \theta_*} \log P(X|\theta_*)\right)^2\right] \\ &= \mathbb{E}\left[\left(\frac{X}{\theta_*} - \frac{1-X}{1-\theta_*}\right)^2\right] \\ &= \mathbb{E}\left[\frac{X^2}{\theta_*^2} - 2\frac{X(1-X)}{\theta_*(1-\theta_*)} + \frac{(1-X)^2}{(1-\theta_*)^2}\right] \\ &= \mathbb{E}\left[ \frac{X}{\theta_*^2} - 0 + \frac{1-X}{(1-\theta_*)^2} \right] \\ &= \frac{\mathbb{E}[X]}{\theta_*^2} + \frac{\mathbb{E}[1-X]}{(1-\theta_*)^2} \\ &= \frac{\theta_*}{\theta_*^2} + \frac{1-\theta_*}{(1-\theta_*)^2} \\ &= \frac{1}{\theta_*(1-\theta_*)} \end{align*} Then the Cramér-Rao Lower Bound is: CRLB=1n⋅ℐ(θ*)=1n⋅(1θ*(1−θ*))=θ*(1−θ*)n=𝕍[θ̂]\begin{align*} \text{CRLB} &= \frac{1}{n \cdot \mathcal{I}(\theta_*)} \\ &= \frac{1}{n \cdot \left(\frac{1}{\theta_*(1-\theta_*)}\right)} \\ &= \frac{\theta_*(1-\theta_*)}{n} \\ &= \mathbb{V}[\hat{\theta}] \end{align*} The implication: θ̂=1n∑Xi\hat{\theta} = \frac{1}{n}\sum X_i is an efficient estimator.

7.4.5 Example - Multivariate Gaussian Distribution

Moving from just a single variable xx, we now consider data points in dd-dimensional space ℝd\mathbb{R}^d.
Define the mean vector μ\mu, which is a vector that contains the average value for every single dimension, and μ=𝔼X∼pθ[X]\mu = \mathbb{E}_{X \sim p_\theta}[X].
Also, define the covariance matrix Σ∈ℝd×d\Sigma \in \mathbb{R}^{d \times d}, which is a square matrix that captures the variance. Here, Σ=𝔼X∼pθ[(X−μ)(X−μ)⊤]\Sigma = \mathbb{E}_{X \sim p_\theta}[(X - \mu)(X - \mu)^\top]. It tells us the variance of each individual dimension and how all the dimensions correlate with one another.
Recall the dd-variate Gaussian PDF: pθ(x)=1(2π)d/2det⁡Σexp⁡(−12(x−μ)⊤Σ−1(x−μ))p_\theta(x) = \frac{1}{(2\pi)^{d/2}\sqrt{\det \Sigma}} \exp\left(-\frac{1}{2}(x - \mu)^\top \Sigma^{-1} (x - \mu)\right) with the normalisation constant in the front, and the term in the exponent calculating the "distance" of point xx from the mean μ\mu, scaled by the covariance.
The goal is to use MLE to calculate μ\mu and Σ\Sigma that best fit the data.
ℒ(μ,Σ)=log⁡∏i=1n1(2π)d/2|Σ|1/2exp⁡(−12(Xi−μ)⊤Σ−1(Xi−μ))(Log of the joint PDF)=∑i=1n[−d2log(2π)−12log|Σ|−12(Xi−μ)⊤Σ−1(Xi−μ)](Log rules: product to sum)=−nd2log⁡(2π)−n2log⁡|Σ|−12∑i=1n(Xi−μ)⊤Σ−1(Xi−μ)(Factor constants out of sum)\begin{align*} \mathcal{L}(\mu, \Sigma) &= \log \prod_{i=1}^{n} \frac{1}{(2\pi)^{d/2} |\Sigma|^{1/2}} \exp\left(-\frac{1}{2}(X_i - \mu)^\top \Sigma^{-1} (X_i - \mu)\right) && \text{(Log of the joint PDF)} \\ &= \sum_{i=1}^{n} \left[ -\frac{d}{2}\log(2\pi) - \frac{1}{2}\log|\Sigma| - \frac{1}{2}(X_i - \mu)^\top \Sigma^{-1} (X_i - \mu) \right] && \text{(Log rules: product to sum)} \\ &= -\frac{nd}{2}\log(2\pi) - \frac{n}{2}\log|\Sigma| - \frac{1}{2}\sum_{i=1}^{n} (X_i - \mu)^\top \Sigma^{-1} (X_i - \mu) && \text{(Factor constants out of sum)} \end{align*} (μ̂,Σ̂)=arg⁡maxμ∈ℝd,Σ∈ℝd×d−n2log⁡(det⁡Σ)−12∑i=1n(Xi−μ)⊤Σ−1(Xi−μ)(\hat{\mu}, \hat{\Sigma}) = \arg\max_{\mu \in \mathbb{R}^d, \Sigma \in \mathbb{R}^{d \times d}} -\frac{n}{2}\log(\det\Sigma) - \frac{1}{2}\sum_{i=1}^{n}(X_i - \mu)^\top\Sigma^{-1}(X_i - \mu) Taking derivative of this function w.r.t. to μ\mu and Σ\Sigma and setting it to zero,

Conclusion: Applying MLE to a multivariate Gaussian distribution gives us the sample mean and the sample covariance matrix as our optimal estimators. As the number of samples increases, these calculated estimates will converge to the true, underlying parameters μ\mu and Σ\Sigma of the distribution.

7.5 Bayesian Inference

Methods like MLE treated the parameter θ\theta as a fixed, absolute, but unknown constant to solve for.
Bayesian Inference instead considers a probability distribution of θ\theta. θ\theta is treated a random variable with its own probability distribution, and we can update our entire belief about the parameter as we gather more data.
The probabilistic structure is:

The goal is to infer θ\theta by calcuting the posterior distribution using Bayes’ Theorem: p(θ|X1,...,Xn)=p(X1,...,Xn|θ)p(θ)p(X1,...,Xn)=∏ip(Xi|θ)p(θ)∫∏ip(Xi|θ′)p(θ′)dθ′p(\theta|X_1, ..., X_n) = \frac{p(X_1, ..., X_n|\theta)p(\theta)}{p(X_1, ..., X_n)} = \frac{\prod_i p(X_i|\theta)p(\theta)}{\int \prod_i p(X_i|\theta')p(\theta')d\theta'} The numerator can be written as the product of individual likelihoods since the observations are independent. The θ\theta here represents the specific hypothesis we are currently testing.
The denominator calculates the total marginal probability of observing this specific set of data. We use the dummy variable θ′\theta' here to show that this integral sweeps across every possible value of the parameter to calculate a grand total. Because it integrates out the parameter, the denominator evaluates to a flat constant number.
With this updated belief, we want to make a prediction about new, unseen data. In other words, given all the past data observations X1,...,XnX_1, ..., X_n I have already seen, what is the probability of observing a completely new data point xx?
We want to solve for p̂(x)\hat{p}(x), the posterior predictive distribution. p̂(x)=𝔼θ∼p(θ|X1,...,Xn)[p(x|θ)]\hat{p}(x) = \mathbb{E}_{\theta\sim p(\theta|X_1, ..., X_n)}[p(x|\theta)] The expected value is calculating the weighted average of the likelihood p(x|θ)p(x|\theta), where the "weights" are determined by how plausible each θ\theta is according to your posterior distribution p(θ|X1,...,Xn)p(\theta|X_1, ..., X_n).
Recall that if we used MLE, we would have calculated the single best parameter θ̂MLE\hat{\theta}_{MLE}, and to predict a new data point, we just plug it into p(x|θ̂MLE)p(x|\hat{\theta}_{MLE}).

The expected value of a continuous function is found by integrating it over the probability distribution. Multiplying (p(x|θ)p(x|\theta)) by the weights (p(θ|X1,...,Xn)p(\theta|X_1, ..., X_n)) and integrating over θ\theta, p̂(x)=∫p(x|θ)⋅p(θ|X1,...,Xn)dθ=∫p(x|θ)[∏ip(Xi|θ)p(θ)∫∏ip(Xi|θ′)p(θ′)dθ′]dθ=∫p(x|θ)∏ip(Xi|θ)p(θ)dθ∫∏ip(Xi|θ′)p(θ′)dθ′\begin{align*} \hat{p}(x) &= \int p(x|\theta) \cdot p(\theta|X_1, ..., X_n) d\theta \\ &= \int p(x|\theta) \left[ \frac{\prod_i p(X_i|\theta)p(\theta)}{\int \prod_i p(X_i|\theta')p(\theta')d\theta'} \right] d\theta \\ &= \frac{\int p(x|\theta) \prod_i p(X_i|\theta)p(\theta)d\theta}{\int \prod_i p(X_i|\theta')p(\theta')d\theta'} \end{align*} Conclusion: Because Bayesian inference averages over all possible parameters rather than relying on a single estimate, its predictions are much safer, especially when you have very little data. If your dataset is small, your posterior distribution will be wide (highly uncertain). The integral naturally accounts for this uncertainty, preventing you from making overconfident predictions based on a small sample size. As you gather more data (n→∞n \rightarrow \infty), your posterior distribution becomes an incredibly narrow spike around the true parameter, and this massive integral mathematically simplifies down to become virtually identical to the MLE approach.

7.5.1 Bayesian Inference with Gaussian Distribution

Calculating that massive integral in the denominator to find the posterior is often computationally impossible for complex distributions.
Instead, we can the use a property of Gaussians: if your prior is a Gaussian, and your likelihood is a Gaussian, your resulting posterior is guaranteed to also be a Gaussian.
First, model the prior and likelihood by Gaussian distributions:

After observing nn data points, the belief updates. The posterior variance σ̂n2\hat{\sigma}_n^2 and posterior mean μ̂n\hat{\mu}_n are σ̂n2=σ2σ02nσ02+σ2μ̂n=σ2σ02nσ02+σ2(∑i=1nXiσ2+μ0σ02)\hat{\sigma}_n^2 = \frac{\sigma^2 \sigma_0^2}{n\sigma_0^2 + \sigma^2} \quad \hat{\mu}_n = \frac{\sigma^2\sigma_0^2}{n\sigma_0^2 + \sigma^2} \left( \frac{\sum_{i=1}^{n}X_i}{\sigma^2} + \frac{\mu_0}{\sigma_0^2} \right) As n→∞n \to \infty, limn→∞σ̂n2=0limn→∞μ̂n=∑i=1nXin\lim_{n \rightarrow \infty} \hat{\sigma}_n^2 = 0 \quad \lim_{n \rightarrow \infty} \hat{\mu}_n = \frac{\sum_{i=1}^{n}X_i}{n} The uncertainty drops to 0, and the mean becomes exactly equal to the sample mean, ignoring the initial belief.

Conclusion: Recall that the sample mean ∑Xin\frac{\sum X_i}{n} is the exact solution you get when you use MLE.
Bayesian Inference is asymptotically equivalent to MLE.
In small data regime (we have little data), MLE is vulnerable to extreme outliers and overfitting. Bayesian inference instead anchors the prediction to your prior belief.
In large data regime, the sheer volume of evidence overwhelms whatever initial bias or belief you had. The prior’s influence vanishes, and the Bayesian approach perfectly mathematically aligns with the Frequentist (MLE) approach.

7.5.2 Maximum a Posteriori Estimation

In Bayesian inference, the perfect way to make a prediction is to calculate p̂(x)=𝔼θ∼p(θ|X1,...,Xn)[p(x|θ)]\hat{p}(x) = \mathbb{E}_{\theta \sim p(\theta|X_1, ..., X_n)}[p(x|\theta)].
However, this is intractable. This means that for complex, real-world models (like deep neural networks), the integrals required to calculate the full posterior and the expected value are too complicated and computationally heavy for a computer to actually solve.
Instead of averaging all possible parameters, MAP Estimation simply finds the single most likely parameter value at the very peak of the posterior distribution curve.
This value is denoted as θ̂MAP\hat{\theta}_{MAP}, and it is found by taking the arg⁡max\arg\max of the posterior: θ̂MAP=arg⁡maxθp(θ|X1,...,Xn)\hat{\theta}_{MAP} = \arg\max_\theta p(\theta|X_1, ..., X_n) Specifically, the core MAP equation is maxθ∈Θ{∑i=1nlogp(Xi|θ)+logp(θ)}\max_{\theta \in \Theta} \left\{ \sum_{i=1}^n \log p(X_i|\theta) + \log p(\theta) \right\} There are two distinct parts in this equation:

  1. The data likelihood ∑i=1nlog⁡p(Xi|θ)\sum_{i=1}^n \log p(X_i|\theta): This is the same log-likelihood term we maximized in standard Maximum Likelihood Estimation (MLE). It pushes the model to pick parameters that fit the observed data well.

  2. The prior as a penalisation term log⁡p(θ)\log p(\theta): This is the log of your prior distribution acting as a penalisation term. If the MLE part tries to pick an extreme parameter that perfectly fits the data but goes against your initial beliefs, this prior term will mathematically penalize (reduce) the overall score.

Because of this added prior term, this problem is also called penalized maximum likelihood estimation.
Also, as n→∞n \to \infty, the data likelihood term (which is a sum) becomes massive, completely overwhelming the single, static log⁡p(θ)\log p(\theta) prior term. With enough data, MAP becomes identical to MLE.

After finding this single best parameter, we can use it to make predictions as p(x|θ̂MAP)p(x|\hat{\theta}_{MAP}).
MAP uses Bayesian logic (incorporating a prior belief) but outputs a single parameter like the Frequentist MLE approach.