Probability & Statistics
Chapter: 1.3 Probability & Statistics Difficulty: Level 5 — Mastery (cross-domain: math + inference + coding) Time limit: 90 minutes Total marks: 60
Instructions: Answer all THREE questions. Show every derivation. Where code is requested, pseudo-code or Python/NumPy is acceptable but must be correct and runnable in spirit. Use for mathematics.
Question 1 — From Bayes to MAP, and the Gaussian bridge (20 marks)
A sensor measures a scalar physical quantity (e.g., a voltage). You obtain i.i.d. noisy readings with known. Your prior belief about the true value is .
(a) Derive the maximum likelihood estimator of from the data . Show the log-likelihood and the stationarity condition. (4)
(b) Derive the full posterior . Show it is Gaussian and give closed-form expressions for its posterior mean and variance . Hence write . (7)
(c) Express as a precision-weighted average of the prior mean and the sample mean. Prove that as , , and interpret this in terms of the influence of the prior. (4)
(d) Write a short vectorized function posterior(x, sigma2, mu0, tau2) returning , and state (with justification) how the posterior variance behaves as . (5)
Question 2 — Estimator quality, CLT, and a confidence interval you must build (20 marks)
Let be i.i.d. from an Exponential distribution with rate , density for .
(a) Show and . Derive the MLE from a sample. (5)
(b) Using the Central Limit Theorem, state the approximate sampling distribution of the sample mean for large . Then use the delta method to find the approximate distribution of , i.e. give its asymptotic variance. (6)
(c) Construct an approximate two-sided confidence interval for based on part (b). A dataset of readings gives . Compute the numeric interval (use ). (5)
(d) Explain precisely what the phrase " confidence" means (and does not mean) in the frequentist sense, contrasting it with a Bayesian credible interval. (4)
Question 3 — Entropy, cross-entropy, and why ML minimizes KL (20 marks)
Let be a true discrete distribution over classes and a model distribution.
(a) Define Shannon entropy , cross-entropy , and KL divergence . Prove the identity (4)
(b) Prove that with equality iff . (Gibbs' inequality — use Jensen's inequality on the concave function .) (6)
(c) For a classifier trained on data with empirical label distribution, show that minimizing average cross-entropy loss over the training set is equivalent to maximum likelihood estimation. Make the argument precise with the negative log-likelihood. (6)
(d) Compute a concrete value: for with true and model , compute , , and in bits (log base 2). Verify your identity from (a) numerically. (4)
Answer keyMark scheme & solutions
Question 1
(a) MLE (4) Likelihood: . (1) Log-likelihood: . (1) Stationarity: . (1) (second derivative , so maximum). (1)
(b) Posterior (7) . (1) Exponent . (1) Collect quadratic in : coefficient of is , so (2) Linear term gives mean (2) Posterior is Gaussian ; since Gaussian mode = mean, . (1)
(c) Precision weighting & limit (4) Write prior precision , data precision . Then (2) a precision-weighted average of prior mean and sample mean. As , dominates, so . (1) The prior's fixed precision becomes negligible against growing data precision — data overwhelms the prior. (1)
(d) Code + variance (5)
import numpy as np
def posterior(x, sigma2, mu0, tau2):
n = x.size
xbar = x.mean()
prec = n/sigma2 + 1/tau2 # posterior precision
sigma_n2 = 1.0/prec # posterior variance
mu_n = sigma_n2*(n*xbar/sigma2 + mu0/tau2)
return mu_n, sigma_n2(3 for correct formulas/vectorization) As : like . (1) Interpretation: infinite data certainty about ; posterior collapses to a point at . (1)
Question 2
(a) Moments & MLE (5) . (1) . (1) Log-likelihood . (1) . (2)
(b) CLT + delta method (6) CLT: (variance ). (2) Delta method with , , evaluated at : . (2) Asymptotic variance . (1) So . (1)
(c) Confidence interval (5) Standard error (plug-in). (1) CI: . (1) . (1) SE . Margin . (1) CI . (1)
(d) Interpretation (4) " confidence" is a statement about the procedure: if we repeated the experiment many times, about of the intervals so constructed would contain the fixed true . (2) It does not mean there is a probability that lies in this particular computed interval — is a fixed constant, and the realized interval either does or does not contain it. (1) A Bayesian credible interval, by contrast, does assign probability to lying in the interval given the data (treating as random via a prior). (1)
Question 3
(a) Identity (4) ; ; . (2) Then . (2)
(b) Gibbs (6) . (1) By Jensen (log concave, with under ): (2) (2) Hence . Equality iff constant (strict concavity of ), i.e. . (1)
(c) Cross-entropy = MLE (6) Given data with model , negative log-likelihood is (2) Using one-hot targets (indicator of true class), the per-sample cross-entropy is . (2) So average cross-entropy . (1) Minimizing average cross-entropy over is therefore identical (up to the positive constant ) to maximizing the log-likelihood — i.e. MLE. (1)
(d) Numeric (4) bit. (1) bits. (1) bits. (1) Check: . ✓ (1)
[
{"claim":"Q1 posterior mean is precision-weighted average; with n=4, xbar=3, sigma2=1, mu0=0, tau2=1 gives mu_n=12/5",
"code":"n=4; sigma2=1; tau2=1; mu0=0; xbar=3; sig_n2=1/(Rational(n,sigma2)+Rational(1,tau2)); mu_n=sig_n2*(Rational(n*xbar,sigma2)+Rational(mu0,tau2)); result=(mu_n==Rational(12,5) and sig_n2==Rational(1,5))"},
{"claim":"Q2 delta-method asymptotic variance of 1/Xbar is lambda**2/n",
"code":"lam,n,t=symbols('lam n t',positive=True); g=1/t; gp=diff(g,t).subs(t,1/lam); varXbar=1/(n*lam**2); asympt=simplify(gp**2*varXbar); result=simplify(asympt-lam**2/n)==0"},
{"claim":"Q2c CI endpoints for xbar=2,n=100,z=1.96 are [0.402,0.598]",
"code":"lh=Rational(1,2); se=lh/sqrt(100); lo=lh-Rational(196,100)*se; hi=lh+Rational(196,100)*se; result=(lo==Rational(402,1000) and hi==Rational(598,1000))"},
{"claim":"Q3d identity H(p,q)=H(p)+KL in bits for p=(.5,.5), q=(.8,.2)",
"code":"p=[Rational(1,2),Rational(1,2)]; q=[Rational(4,5),Rational(1,5)]; Hp=-sum(pi*log(pi,2) for pi in p); Hpq=-sum(pi*log(qi,2) for pi,qi in zip(p,q)); KL=sum(pi*log(pi/qi,2) for pi,qi in zip(p,q)); result=simplify(Hpq-(Hp+KL))==0"}
]