PML Exercise 4 Solutions

Probabilistic Machine Learning (PML) Chapter 4 Exercise Solutions.

Part of series PML Exercise Solutions (3 / 5)
  1. PML Exercise 2 Solutions
  2. PML Exercise 3 Solutions
  3. PML Exercise 4 Solutions
  4. PML Exercise 5 Solutions
  5. PML Exercise 6 Solutions

Exercise 4.1 [MLE for the univariate Gaussian †]

Show that the MLE for a univariate Gaussian is given by

μ^=1Nn=1Nyn\hat{\mu} = \frac{1}{N} \sum_{n=1}^N y_n σ^2=1Nn=1N(ynμ^)2\hat{\sigma}^2 = \frac{1}{N} \sum_{n=1}^N (y_n - \hat{\mu})^2

解答: 写出 log

logp(Dμ,σ2)=N2(log2π+logσ2)n=1N(xnμ)22σ2\log p(D\mid \mu, \sigma^2)= -\frac{N}{2}(\log2\pi+\log \sigma^2) -\sum_{n=1}^N \frac{(x_n-\mu)^2}{2\sigma^2}

logp(Dμ,σ2)μ=0,logp(Dμ,σ2)σ2=0\frac{\partial{\log p(D\mid \mu, \sigma^2)}}{\partial{\mu}}=0, \frac{\partial{\log p(D\mid \mu, \sigma^2)}}{\partial{\sigma^2}}=0,解得上式。

Exercise 4.2 [MAP estimation for 1D Gaussians †]

Consider samples x1,,xnx_1, \dots, x_n from a Gaussian random variable with known variance σ2\sigma^2 and unknown mean μ\mu. We further assume a prior distribution (also Gaussian) over the mean, μN(m,s2)\mu \sim \mathcal{N}(m, s^2), with fixed mean mm and fixed variance s2s^2. Thus the only unknown is μ\mu.

  • a. Calculate the MAP estimate μ^MAP\hat{\mu}_{MAP}. You can state the result without proof. Alternatively, with a lot more work, you can compute derivatives of the log posterior, set to zero and solve.
  • b. Show that as the number of samples nn increase, the MAP estimate converges to the maximum likelihood estimate.
  • c. Suppose nn is small and fixed. What does the MAP estimator converge to if we increase the prior variance s2s^2?
  • d. Suppose nn is small and fixed. What does the MAP estimator converge to if we decrease the prior variance s2s^2?

解答:

  • a.
μ^MAP=argmaxμp(μ,σ2D)=argmaxμp(μm,s2)p(Dμ)p(D)=argmaxμlogp(μm,s2)+logp(Dμ)=argmaxμlog{12πs2exp(μm)22s2}+log{(2πσ2)n2i=1nexp(xiμ)22σ2}=argmaxμ12log(2πs2)(μm)22s2n2log2πσ2i=1n(xiμ)22σ2=argmaxμσ2(μm)2+s2i=1n(xiμ)22s2σ2=mσ2+s2i=1nxiσ2+ns2\begin{aligned} \hat{\mu}_{MAP} &=\arg \max_{\mu} p(\mu,\sigma^2\mid D)\\ &=\arg \max_{\mu} \frac{p(\mu\mid m, s^2)p(D\mid \mu)}{p(D)}\\ &=\arg \max_{\mu} \log p(\mu\mid m, s^2)+\log p(D\mid \mu)\\ &=\arg \max_{\mu} \log{\left\{\frac{1}{\sqrt{2\pi s^2}}\exp{-\frac{(\mu -m)^2}{2s^2}} \right\}}+\log \left\{(2\pi \sigma^2)^{-\frac{n}{2}}\prod_{i=1}^n \exp{-\frac{(x_i-\mu)^2}{2\sigma^2}}\right\}\\ &=\arg \max_{\mu} -\frac{1}{2}\log (2\pi s^2)-\frac{(\mu-m)^2}{2s^2}-\frac{n}{2}\log{2\pi \sigma^2}-\sum_{i=1}^n \frac{(x_i-\mu)^2}{2\sigma^2}\\ &=\arg \max_{\mu} - \frac{\sigma^2(\mu-m)^2+s^2\sum_{i=1}^n (x_i-\mu)^2}{2s^2 \sigma^2}\\ &=\frac{m\sigma^2+s^2\sum_{i=1}^n x_i}{\sigma^2+ns^2} \end{aligned}
  • b. 随着采样数量的增加 μ^MAPi=1nxin\hat{\mu}_{MAP}\rightarrow \frac{\sum_{i=1}^n x_i}{n},即MLE。
  • c. 随着 s2s^2 增加也是收敛于 MLE。
  • d. 随着 s2s^2 减小收敛于先验均值 mm

Exercise 4.3 [Gaussian posterior credible interval]

Let XN(μ,σ2=4)X \sim \mathcal{N}(\mu, \sigma^2 = 4) where μ\mu is unknown but has prior μN(μ0,σ02=9)\mu \sim \mathcal{N}(\mu_0, \sigma^2_0 = 9). The posterior after seeing nn samples is μN(μn,σn2)\mu \sim \mathcal{N}(\mu_n, \sigma^2_n). (This is called a credible interval, and is the Bayesian analog of a confidence interval.) How big does nn have to be to ensure

p(μnuD)0.95p(\ell \le \mu_n \le u|D) \ge 0.95

where (,u)(\ell, u) is an interval (centered on μn\mu_n) of width 1 and DD is the data? Hint: recall that 95% of the probability mass of a Gaussian is within ±1.96σ\pm 1.96\sigma of the mean.

解答: 由题干可知 σn12×1.96\sigma_n\leq\frac{1}{2\times 1.96},又由习题 4.2 可知后验方差 σn2=s2σ2σ2+s2n\sigma_n^2=\frac{s^2\sigma^2}{\sigma^2+s^2n},即要求 s2σ2σ2+s2n1(2×1.96)2n61.02\frac{s^2\sigma^2}{\sigma^2+s^2n}\leq \frac{1}{(2\times 1.96)^2}\rightarrow n\geq 61.02,即要大于等于 62。

Exercise 4.4 [BIC for Gaussians †]

The Bayesian information criterion (BIC) is a penalized log-likelihood function that can be used for model selection. It is defined as

BIC=logp(Dθ^ML)d2log(N)BIC = \log p(D|\hat{\theta}_{ML}) - \frac{d}{2} \log(N)

where dd is the number of free parameters in the model and NN is the number of samples. In this question, we will see how to use this to choose between a full covariance Gaussian and a Gaussian with a diagonal covariance. Obviously a full covariance Gaussian has higher likelihood, but it may not be “worth” the extra parameters if the improvement over a diagonal covariance matrix is too small. So we use the BIC score to choose the model. We can write

logp(DΣ^,μ^)=N2tr(Σ^1S^)N2log(Σ^)\log p(D|\hat{\Sigma}, \hat{\mu}) = -\frac{N}{2} \text{tr}(\hat{\Sigma}^{-1}\hat{S}) - \frac{N}{2} \log(|\hat{\Sigma}|) S^=1Ni=1N(xixˉ)(xixˉ)T\hat{S} = \frac{1}{N} \sum_{i=1}^N (x_i - \bar{x})(x_i - \bar{x})^T

where S^\hat{S} is the scatter matrix (empirical covariance), the trace of a matrix is the sum of its diagonals, and we have used the trace trick.

  • a. Derive the BIC score for a Gaussian in DD dimensions with full covariance matrix. Simplify your answer as much as possible, exploiting the form of the MLE. Be sure to specify the number of free parameters dd.
  • b. Derive the BIC score for a Gaussian in DD dimensions with a diagonal covariance matrix. Be sure to specify the number of free parameters dd. Hint: for the digaonal case, the ML estimate of Σ\Sigma is the same as Σ^ML\hat{\Sigma}_{ML} except the off-diagonal terms are zero:
Σ^diag=diag(Σ^ML(1,1),,Σ^ML(D,D))\hat{\Sigma}_{diag} = \text{diag}(\hat{\Sigma}_{ML}(1, 1), \dots, \hat{\Sigma}_{ML}(D,D))

解答:

  • a. DD 维高斯分布的 BIC 得分
BIC=logp(DΣ^,μ^)d2log(N)=N2tr(Σ^1S^)N2log(Σ^)d2log(N)=N2N2log(Σ^)D(D+1)2log(N)\begin{aligned} \text{BIC} &=\log p(D\mid \hat{\Sigma},\hat{\mu})-\frac{d}{2}\log(N)\\ &=-\frac{N}{2}\mathrm{tr}(\hat{\Sigma}^{-1}\hat{S})-\frac{N}{2}\log (\lvert\hat{\Sigma}\rvert) - \frac{d}{2}\log (N)\\ &=-\frac{N}{2}-\frac{N}{2}\log (\lvert\hat{\Sigma}\rvert)-\frac{D(D+1)}{2}\log (N) \end{aligned}
  • b.
BIC=N2tr(Σ^1S^)N2log(Σ^)d2log(N)=N2N2log(Σ^)Dlog(N)\begin{aligned} \text{BIC}&=-\frac{N}{2}\mathrm{tr}(\hat{\Sigma}^{-1}\hat{S})-\frac{N}{2}\log (\lvert\hat{\Sigma}\rvert) - \frac{d}{2}\log (N)\\ &=-\frac{N}{2}-\frac{N}{2}\log (\lvert\hat{\Sigma}\rvert)-D\log(N) \end{aligned}

⚠️ 修正:

  • a.
BICfull=logp(DΣ^ML,μ^)d2log(N)=N2tr(Σ^ML1S^)N2log(Σ^ML)D(D+3)4log(N)协方差矩阵上三角元素个数和均值个数=ND2N2log(Σ^ML)D(D+3)4log(N)\begin{aligned} \text{BIC}_{full} &= \log p(D\mid \hat{\Sigma}_{ML},\hat{\mu}) - \frac{d}{2}\log(N)\\ &= -\frac{N}{2}\text{tr}(\hat{\Sigma}_{ML}^{-1}\hat{S}) - \frac{N}{2}\log(|\hat{\Sigma}_{ML}|) - \frac{D(D+3)}{4}\log(N) \quad \text{协方差矩阵上三角元素个数和均值个数}\\ &= -\frac{ND}{2} - \frac{N}{2}\log(|\hat{\Sigma}_{ML}|) - \frac{D(D+3)}{4}\log(N) \end{aligned}
  • b.
BICdiag=logp(DΣ^diag,μ^)d2log(N)=N2tr(Σ^diag1S^)N2log(Σ^diag)2D2log(N)=ND2N2log(Σ^diag)Dlog(N)\begin{aligned} \text{BIC}_{diag} &= \log p(D\mid \hat{\Sigma}_{diag},\hat{\mu}) - \frac{d}{2}\log(N)\\ &= -\frac{N}{2}\text{tr}(\hat{\Sigma}_{diag}^{-1}\hat{S}) - \frac{N}{2}\log(|\hat{\Sigma}_{diag}|) - \frac{2D}{2}\log(N) \\ &= -\frac{ND}{2} - \frac{N}{2}\log(|\hat{\Sigma}_{diag}|) - D\log(N) \end{aligned}

Exercise 4.5 [BIC for a 2d discrete distribution]

Let x{0,1}x \in \{0, 1\} denote the result of a coin toss (x=0x = 0 for tails, x=1x = 1 for heads). The coin is potentially biased, so that heads occurs with probability θ1\theta_1. Suppose that someone else observes the coin flip and reports to you the outcome, yy. But this person is unreliable and only reports the result correctly with probability θ2\theta_2; i.e., p(yx,θ2)p(y|x, \theta_2) is given by

y=0y = 0y=1y = 1
x=0x = 0θ2\theta_21θ21 - \theta_2
x=1x = 11θ21 - \theta_2θ2\theta_2

Assume that θ2\theta_2 is independent of xx and θ1\theta_1.

  • a. Write down the joint probability distribution p(x,yθ)p(x, y|\theta) as a 2x2 table, in terms of θ=(θ1,θ2)\theta = (\theta_1, \theta_2).
  • b. Suppose have the following dataset: x=(1,1,0,1,1,0,0)x = (1, 1, 0, 1, 1, 0, 0), y=(1,0,0,0,1,0,1)y = (1, 0, 0, 0, 1, 0, 1). What are the MLEs for θ1\theta_1 and θ2\theta_2? Justify your answer. Hint: note that the likelihood function factorizes,
p(x,yθ)=p(yx,θ2)p(xθ1)p(x, y|\theta) = p(y|x, \theta_2)p(x|\theta_1)

What is p(Dθ^,M2)p(D|\hat{\theta}, M_2) where M2M_2 denotes this 2-parameter model? (You may leave your answer in fractional form if you wish.)

  • c. Now consider a model with 4 parameters, θ=(θ0,0,θ0,1,θ1,0,θ1,1)\theta = (\theta_{0,0}, \theta_{0,1}, \theta_{1,0}, \theta_{1,1}), representing p(x,yθ)=θx,yp(x, y|\theta) = \theta_{x,y}. (Only 3 of these parameters are free to vary, since they must sum to one.) What is the MLE of θ\theta? What is p(Dθ^,M4)p(D|\hat{\theta}, M_4) where M4M_4 denotes this 4-parameter model?
  • d. Suppose we are not sure which model is correct. We compute the leave-one-out cross validated log likelihood of the 2-parameter model and the 4-parameter model as follows:
L(m)=i=1nlogp(xi,yim,θ^(Di))L(m) = \sum_{i=1}^n \log p(x_i, y_i|m, \hat{\theta}(D_{-i}))

and θ^(Di)\hat{\theta}(D_{-i}) denotes the MLE computed on DD excluding row ii. Which model will CV pick and why? Hint: notice how the table of counts changes when you omit each training case one at a time.

  • e. Recall that an alternative to CV is to use the BIC score, defined as
BIC(M,D)logp(Dθ^MLE)dof(M)2logNBIC(M,D) \triangleq \log p(D|\hat{\theta}_{MLE}) - \frac{\text{dof}(M)}{2} \log N

where dof(M)\text{dof}(M) is the number of free parameters in the model, Compute the BIC scores for both models (use log base ee). Which model does BIC prefer?

解答:

  • a. p(x=0,y=0θ)=θ2(1θ1),p(x=1,y=0θ)=(1θ2)θ1,p(x=0,y=1)=(1θ2)(1θ1),p(x=1,y=1θ)=θ2θ1p(x=0,y=0\mid\theta)=\theta_2(1-\theta_1), p(x=1,y=0\mid \theta)=(1-\theta_2)\theta_1, p(x=0,y=1)=(1-\theta_2)(1-\theta_1), p(x=1,y=1\mid \theta)=\theta_2\theta_1
  • b.
p({xn,yn}n=1Nθ)=θ14(1θ1)3θ24(1θ2)3p(\{x_n, y_n\}_{n=1}^N\mid \theta)=\theta_1^4(1-\theta_1)^3\theta_2^4(1-\theta_2)^3

易得 θ1=θ2=47\theta_1=\theta_2=\frac{4}{7},同时求得 p(Dθ^,M2)=(47)8(37)6p(D|\hat{\theta}, M_2)=(\frac{4}{7})^8 (\frac{3}{7})^6

  • c.
logp({xn,yn}n=1Nθ)=logθ0,02θ0,11θ1,02θ1,12θ0,0=argmaxθ0,0logp({xn,yn}n=1Nθ) s.t. θ0,0+θ0,1+θ1,0+θ1,1=1θ0,0=argmaxθ0,02logθ0,0+α(θ0,0+θ0,1+θ1,0+θ1,11)\begin{aligned} \log p(\{x_n, y_n\}_{n=1}^N\mid \theta)&=\log\theta_{0,0}^2\theta_{0,1}^1\theta_{1,0}^2\theta_{1,1}^2\\ \theta_{0,0} &=\arg \max_{\theta_{0,0}} \log p(\{x_n, y_n\}_{n=1}^N\mid \theta) \text{ s.t. } \theta_{0,0}+\theta_{0,1}+\theta_{1,0}+\theta_{1,1}=1\\ \theta_{0,0}&= \arg \max_{\theta_{0,0}} 2\log \theta_{0,0}+\alpha(\theta_{0,0}+\theta_{0,1}+\theta_{1,0}+\theta_{1,1}-1)\\ \end{aligned}

易得 θ0,0=θ1,0=θ1,1=27,θ0,1=17\theta_{0,0}=\theta_{1,0}=\theta_{1,1}=\frac{2}{7},\theta_{0,1}=\frac{1}{7},同时求得 p(Dθ^,M4)=(27)617p(D\mid \hat{\theta},M_4)=(\frac{2}{7})^6\frac{1}{7}

  • d.
L(M2)=2logp(x=0,y=0M2,θ^(D(0,0)))+2logp(x=1,y=0)+logp(x=0,y=1)+2logp(x=1,y=1)=2logp(x=0,y=0θ1=23,θ2=12)+=2log6+去掉(0,1)会出现无穷大\begin{aligned} L(M_2)&=2 \log p(x=0,y=0\mid M_2, \hat{\theta}(D_{-(0,0)}))+2\log p(x=1,y=0)+\log p(x=0,y=1)+2\log p(x=1, y=1)\\ &=2\log p(x=0,y=0\mid \theta_1=\frac{2}{3},\theta_2=\frac{1}{2})+\cdots\\ &=-2 \log 6 +\cdots \quad \text{去掉(0,1)会出现无穷大} \end{aligned} L(M4)=2logp(x=0,y=0M4,θ^(D(0,0)))+2logp(x=1,y=0)+logp(x=0,y=1)+2logp(x=1,y=1)=2logp(x=0,y=0θ0,0=16,θ0,1=16,θ1,0=13,θ1,1=13)+=2log6+\begin{aligned} L(M_4)&=2 \log p(x=0,y=0\mid M_4, \hat{\theta}(D_{-(0,0)}))+2\log p(x=1,y=0)+\log p(x=0,y=1)+2\log p(x=1, y=1)\\ &=2\log p(x=0,y=0\mid \theta_{0,0}=\frac{1}{6}, \theta_{0,1}=\frac{1}{6}, \theta_{1,0}=\frac{1}{3}, \theta_{1,1}=\frac{1}{3})+\cdots\\ &=-2\log 6+\cdots \end{aligned}
  • e.
BIC(M2,D)=log((47)8(37)6)log7\text{BIC}(M_2, D)=\log \left((\frac{4}{7})^8 (\frac{3}{7})^6\right)-\log 7 BIC(M4,D)=log((27)617)2log7\text{BIC}(M_4,D)=\log \left((\frac{2}{7})^6\frac{1}{7} \right)-2\log7

⚠️ 纠正:

  • e. 四参数模型参数和要求为1,所以自由参数为 41=34-1=3,最终答案为 BIC(M4,D)=log((27)617)32log7\text{BIC}(M_4,D)=\log \left((\frac{2}{7})^6\frac{1}{7} \right)-\frac{3}{2}\log7

Exercise 4.6 [A mixture of conjugate priors is conjugate †]

Consider a mixture prior

p(θ)=kp(z=k)p(θz=k)p(\theta) = \sum_k p(z = k)p(\theta|z = k)

where each p(θz=k)p(\theta|z = k) is conjugate to the likelihood. Prove that this is a conjugate prior.

解答: 已知 p(θD)=p(θ)p(Dθ)p(D)p(\theta \mid D) = \frac{p(\theta)p(D \mid \theta)}{p(D)},代入混合先验

p(θD)=(kp(z=k)p(θz=k))p(Dθ)p(D)=kp(z=k)[p(θz=k)p(Dθ)]p(D)\begin{aligned} p(\theta \mid D) &= \frac{\left( \sum_k p(z=k)p(\theta \mid z=k) \right) p(D \mid \theta)}{p(D)}\\ &= \frac{\sum_k p(z=k) \left[ p(\theta \mid z=k) p(D \mid \theta) \right]}{p(D)} \end{aligned}

又有在给定隐变量下的后验分布

p(θD,z=k)=p(θz=k)p(Dθ)p(Dz=k)p(θz=k)p(Dθ)=p(θD,z=k)p(Dz=k)p(θD)=kp(z=k)p(Dz=k)p(θD,z=k)p(D)代入混合先验=k(p(z=k)p(Dz=k)p(D))p(θD,z=k)=kp(z=kD)p(θD,z=k)\begin{aligned} p(\theta \mid D, z=k)& = \frac{p(\theta \mid z=k) p(D \mid \theta)}{p(D \mid z=k)}\\ p(\theta \mid z=k) p(D \mid \theta)& = p(\theta \mid D, z=k) p(D \mid z=k)\\ p(\theta \mid D) &= \frac{\sum_k p(z=k) p(D \mid z=k) p(\theta \mid D, z=k)}{p(D)} \quad \text{代入混合先验}\\ &= \sum_k \left( \frac{p(z=k) p(D \mid z=k)}{p(D)} \right) p(\theta \mid D, z=k)\\ &= \sum_k p(z=k \mid D) p(\theta \mid D, z=k) \end{aligned}

因为组件的先验 p(θz=k)p(\theta \mid z=k) 是共轭的,所以当它乘上似然 p(Dθ)p(D \mid \theta) 后,计算出的组件的后验 p(θD,z=k)p(\theta \mid D, z=k),在数学形式上,必定与它原来的组件的先验 p(θz=k)p(\theta \mid z=k) 属于同一个分布族。

Exercise 4.7 [ML estimator σmle2\sigma^2_{mle} is biased]

Show that σ^MLE2=1Nn=1N(xnμ^)2\hat{\sigma}^2_{MLE} = \frac{1}{N} \sum_{n=1}^N(x_n - \hat{\mu})^2 is a biased estimator of σ2\sigma^2, i.e., show

EX1,,XnN(μ,σ2)[σ^2(X1,,Xn)]σ2\mathbb{E}_{X_1,\dots,X_n \sim \mathcal{N}(\mu,\sigma^2)}[\hat{\sigma}^2(X_1, \dots, X_n)] \neq \sigma^2

Hint: note that X1,,XNX_1, \dots, X_N are independent, and use the fact that the expectation of a product of independent random variables is the product of the expectations.

解答:

EX1,,XnN(μ,σ2)[σ^2(X1,,Xn)]=E[1Nn=1N(Xnμ^)2]=E[1N(n=1NXn2+1N2(n=1NXn)22N(n=1NXn)2)]=1NE[n=1NXn2]+1N3E[(n=1NXn)2]2N2E[(n=1NXn)2]=σ2+μ2+12NN3E[(n=1NXn)2]=σ2+μ2+12NN3[N(N1)μ2+N(σ2+μ2)]=N22N+1N2σ2+1NNμ2\begin{aligned} \mathbb{E}_{X_1,\dots,X_n\sim \mathcal{N}(\mu,\sigma^2)}[\hat{\sigma}^2(X_1,\dots, X_n)]&=\mathbb{E}[\frac{1}{N}\sum_{n=1}^N (X_n -\hat{\mu})^2]\\ &=\mathbb{E}[\frac{1}{N}(\sum_{n=1}^N X_n^2+\frac{1}{N^2}(\sum_{n=1}^NX_n)^2-\frac{2}{N}(\sum_{n=1}^NX_n)^2)]\\ &=\frac{1}{N}\mathbb{E}[\sum_{n=1}^N X_n^2]+\frac{1}{N^3}\mathbb{E}[(\sum_{n=1}^NX_n)^2]-\frac{2}{N^2}\mathbb{E}[(\sum_{n=1}^NX_n)^2] \\ &=\sigma^2+\mu^2+\frac{1-2N}{N^3}\mathbb{E}[(\sum_{n=1}^NX_n)^2]\\ &=\sigma^2+\mu^2+\frac{1-2N}{N^3}[N(N-1)\mu^2+N(\sigma^2+\mu^2)]\\ &=\frac{N^2-2N+1}{N^2}\sigma^2+\frac{1-N}{N}\mu^2 \end{aligned}

⚠️ 纠错: 第二行展开错误

E[σ^2]=(σ2+μ2)(μ2+σ2N)=σ2σ2N=N1Nσ2\begin{aligned} \mathbb{E}[\hat{\sigma}^2] &= (\sigma^2 + \mu^2) - \left(\mu^2 + \frac{\sigma^2}{N}\right)\\ &= \sigma^2 - \frac{\sigma^2}{N} = \frac{N-1}{N}\sigma^2 \end{aligned}

Exercise 4.8 [Estimation of σ2\sigma^2 when μ\mu is known †]

Suppose we sample x1,,xNN(μ,σ2)x_1, \dots, x_N \sim \mathcal{N}(\mu, \sigma^2) where μ\mu is a known constant. Derive an expression for the MLE for σ2\sigma^2 in this case. Is it unbiased?

解答:

σ^2=argmaxσ2n=1N[12log2π12logσ2(xnμ)22σ2]=argmaxσ2N2logσ212σ2n=1N(xnμ)2=n=1N(xnμ)22N\begin{aligned} \hat{\sigma}^2&=\arg \max_{\sigma^2} \sum_{n=1}^N [-\frac{1}{2}\log{2\pi}-\frac{1}{2}\log{\sigma^2}-\frac{(x_n-\mu)^2}{2\sigma^2}]\\ &=\arg \max_{\sigma^2} -\frac{N}{2}\log \sigma^2-\frac{1}{2\sigma^2}\sum_{n=1}^N(x_n-\mu)^2\\ &=\frac{\sum_{n=1}^N (x_n-\mu)^2}{2N} \end{aligned}

仍然是有偏的

⚠️ 纠正: 求导时犯错,应为 n=1N(xnμ)2N\frac{\sum_{n=1}^N (x_n-\mu)^2}{N},并且在这个特定场景下(μ\mu 是已知的常数),它是无偏估计。

E[σ^2]=E[1Nn=1N(Xnμ)2]=1Nn=1NE[(Xnμ)2]\begin{aligned} \mathbb{E}[\hat{\sigma}^2] &= \mathbb{E}\left[ \frac{1}{N}\sum_{n=1}^N (X_n-\mu)^2 \right] \\ &= \frac{1}{N}\sum_{n=1}^N \mathbb{E}[(X_n-\mu)^2] \end{aligned}

由于题目已知 μ\mu 就是真实的总体均值,所以根据方差的严格数学定义,E[(Xnμ)2]\mathbb{E}[(X_n-\mu)^2] 就是 XnX_n 的真实方差 σ2\sigma^2

Exercise 4.9 [Variance and MSE of estimators for Gaussian variance †]

Prove that the standard error for the MLE for a Gaussian variance is

V[σmle2]=2(N1)N2σ2\sqrt{\mathbb{V}[\sigma^2_{mle}]} = \sqrt{\frac{2(N - 1)}{N^2}} \sigma^2

Hint: use the fact that

N1σ2σunb2χN12\frac{N - 1}{\sigma^2} \sigma^2_{unb} \sim \chi^2_{N-1}

and that V[χN12]=2(N1)\mathbb{V}[\chi^2_{N-1}] = 2(N - 1). Finally, show that MSE(σunb2)=2N1σ4MSE(\sigma^2_{unb}) = \frac{2}{N-1} \sigma^4 and MSE(σmle2)=2N1N2σ4MSE(\sigma^2_{mle}) = \frac{2N-1}{N^2}\sigma^4.

解答: 已知 σmle2=N1Nσunb2\sigma_{mle}^2=\frac{N-1}{N}\sigma_{unb}^2,因此 Nσ2σmle2χN12\frac{N}{\sigma^2}\sigma_{mle}^2\sim\chi_{N-1}^2,可得 V[σmle2]=2(N1)N2σ2\sqrt{\mathbb{V}[\sigma^2_{mle}]} = \sqrt{\frac{2(N - 1)}{N^2}} \sigma^2

⚠️ 补充: 利用偏差-方差分解公式:

MSE(θ^)=V[θ^]+(Bias(θ^))2\text{MSE}(\hat{\theta}) = \mathbb{V}[\hat{\theta}] + (\text{Bias}(\hat{\theta}))^2 (N1)2σ4V[σunb2]=2(N1)    V[σunb2]=2N1σ4MSE(σunb2)=2N1σ4+02=2N1σ4\begin{aligned} \frac{(N-1)^2}{\sigma^4} \mathbb{V}[\sigma^2_{unb}] &= 2(N-1) \implies \mathbb{V}[\sigma^2_{unb}] = \frac{2}{N-1}\sigma^4\\ \text{MSE}(\sigma^2_{unb}) &= \frac{2}{N-1}\sigma^4 + 0^2 = \frac{2}{N-1}\sigma^4 \end{aligned}

由习题 4.7 可知偏差为:

Bias(σmle2)=E[σmle2]σ2=N1Nσ2σ2=1Nσ2\text{Bias}(\sigma^2_{mle}) = \mathbb{E}[\sigma^2_{mle}] - \sigma^2 = \frac{N-1}{N}\sigma^2 - \sigma^2 = -\frac{1}{N}\sigma^2

又由前半部分结论 V[σmle2]=2(N1)N2σ4\mathbb{V}[\sigma_{mle}^2] = \frac{2(N-1)}{N^2} \sigma^4,可得

MSE(σmle2)=2N2N2σ4+1N2σ4=2N1N2σ4\text{MSE}(\sigma^2_{mle}) = \frac{2N-2}{N^2} \sigma^4 + \frac{1}{N^2}\sigma^4 = \frac{2N-1}{N^2} \sigma^4