Let X ∼ U ( − 1 , 1 ) X \sim U(-1, 1) X ∼ U ( − 1 , 1 ) and Y = X 2 Y = X^2 Y = X 2 . Clearly Y Y Y is dependent on X X X (in fact, Y Y Y is uniquely determined by X X X ). However, show that ρ ( X , Y ) = 0 \rho(X,Y) = 0 ρ ( X , Y ) = 0 . Hint: if X ∼ U ( a , b ) X \sim U(a, b) X ∼ U ( a , b ) then E [ X ] = ( a + b ) / 2 \mathbb{E}[X] = (a+b)/2 E [ X ] = ( a + b ) /2 and V [ X ] = ( b − a ) 2 / 12 \mathbb{V}[X] = (b-a)^2/12 V [ X ] = ( b − a ) 2 /12 .
解答:
ρ = c o r r [ X , Y ] ≜ C o v [ X , Y ] V [ X ] V [ Y ] = E [ X Y ] − E [ X ] E [ Y ] 1 3 V [ Y ] = 3 E [ X 3 ] − E [ X ] E [ X 2 ] E [ X 4 ] − E 2 [ X 2 ] \begin{aligned}
\rho&= \mathrm{corr}[X,Y]\triangleq \frac{\mathrm{Cov}[X,Y]}{\sqrt{\mathbb{V}[X]\mathbb{V}[Y]}}\\
&=\frac{\mathbb{E}[XY]-\mathbb{E}[X]\mathbb{E}[Y]}{\sqrt{\frac{1}{3}\mathbb{V}[Y]}}=\sqrt3\frac{\mathbb{E}[X^3]-\mathbb{E}[X]\mathbb{E}[X^2]}{\sqrt{\mathbb{E}[X^4]-\mathbb{E}^2[X^2]}}
\end{aligned} ρ = corr [ X , Y ] ≜ V [ X ] V [ Y ] Cov [ X , Y ] = 3 1 V [ Y ] E [ X Y ] − E [ X ] E [ Y ] = 3 E [ X 4 ] − E 2 [ X 2 ] E [ X 3 ] − E [ X ] E [ X 2 ]
易知 E [ X 2 ] = V [ X ] + E 2 [ X ] = 1 3 \mathbb{E}[X^2]=\mathbb{V}[X]+\mathbb{E}^2[X]=\frac{1}{3} E [ X 2 ] = V [ X ] + E 2 [ X ] = 3 1 ,E [ X 3 ] = ∫ − 1 1 p ( x ) x 3 d x = 0 \mathbb{E}[X^3]=\int_{-1}^1 p(x)x^3\mathrm{d}x=0 E [ X 3 ] = ∫ − 1 1 p ( x ) x 3 d x = 0 ,E [ X 4 ] = ∫ − 1 1 p ( x ) x 4 d x = 1 5 \mathbb{E}[X^4]=\int_{-1}^1p(x)x^4\mathrm{d}x=\frac{1}{5} E [ X 4 ] = ∫ − 1 1 p ( x ) x 4 d x = 5 1 ,带入上式可得 ρ = 0 \rho=0 ρ = 0 。
Exercise 3.2 [Correlation coefficient is between -1 and +1]
Prove that − 1 ≤ ρ ( X , Y ) ≤ 1 -1 \le \rho(X,Y) \le 1 − 1 ≤ ρ ( X , Y ) ≤ 1 .
ρ = E [ X Y ] − E [ X ] E [ Y ] ( E [ X 2 ] − E 2 [ X ] ) ( E [ Y 2 ] − E 2 [ Y ] ) ρ 2 = ( E [ X Y ] − E [ X ] E [ Y ] ) 2 ( E [ X 2 ] − E 2 [ X ] ) ( E [ Y 2 ] − E 2 [ Y ] ) \begin{aligned}
\rho &= \frac{\mathbb{E}[XY]-\mathbb{E}[X]\mathbb{E}[Y]}{\sqrt{(\mathbb{E}[X^2]-\mathbb{E}^2[X])(\mathbb{E}[Y^2]-\mathbb{E}^2[Y])}}\\
\rho^2 &=\frac{(\mathbb{E}[XY]-\mathbb{E}[X]\mathbb{E}[Y])^2}{(\mathbb{E}[X^2]-\mathbb{E}^2[X])(\mathbb{E}[Y^2]-\mathbb{E}^2[Y])}
\end{aligned} ρ ρ 2 = ( E [ X 2 ] − E 2 [ X ]) ( E [ Y 2 ] − E 2 [ Y ]) E [ X Y ] − E [ X ] E [ Y ] = ( E [ X 2 ] − E 2 [ X ]) ( E [ Y 2 ] − E 2 [ Y ]) ( E [ X Y ] − E [ X ] E [ Y ] ) 2
解答:
令 X ~ = X − E [ X ] , Y ~ = Y − E [ Y ] \tilde{X}=X-\mathbb{E}[X], \tilde{Y}=Y-\mathbb{E}[Y] X ~ = X − E [ X ] , Y ~ = Y − E [ Y ] ,根据定义有 V [ X ] = E [ X ~ 2 ] , V [ Y ] = E [ Y ~ 2 ] , C o v [ X , Y ] = E [ X ~ Y ~ ] \mathbb{V}[X]=\mathbb{E}[\tilde{X}^2],\mathbb{V}[Y]=\mathbb{E}[\tilde{Y}^2], \mathrm{Cov}[X,Y]=\mathbb{E}[\tilde{X}\tilde{Y}] V [ X ] = E [ X ~ 2 ] , V [ Y ] = E [ Y ~ 2 ] , Cov [ X , Y ] = E [ X ~ Y ~ ] ,引入任意实数 t t t ,有
E [ ( t X ~ + Y ~ ) 2 ] ≥ 0 t 2 E [ X ~ 2 ] + 2 t E [ X ~ Y ~ ] + E [ Y ~ 2 ] ≥ 0 \begin{aligned}
\mathbb{E}[(t\tilde{X}+\tilde{Y})^2]&\geq 0\\
t^2\mathbb{E}[\tilde{X}^2]+2t\mathbb{E}[\tilde{X}\tilde{Y}]+\mathbb{E}[\tilde{Y}^2]&\geq0\\
\end{aligned} E [( t X ~ + Y ~ ) 2 ] t 2 E [ X ~ 2 ] + 2 t E [ X ~ Y ~ ] + E [ Y ~ 2 ] ≥ 0 ≥ 0
因为关于 t t t 的一元二次函数上式恒成立,说明其判别式必须小于等于0,所以 Δ = ( 2 E [ X ~ Y ~ ] ) 2 − 4 E [ X ~ 2 ] E [ Y ~ 2 ] ≤ 0 \Delta=(2\mathbb{E}[\tilde{X}\tilde{Y}])^2-4\mathbb{E}[\tilde{X}^2]\mathbb{E}[\tilde{Y}^2]\leq 0 Δ = ( 2 E [ X ~ Y ~ ] ) 2 − 4 E [ X ~ 2 ] E [ Y ~ 2 ] ≤ 0 ,即 C o v 2 [ X , Y ] ≤ V [ X ] V [ Y ] \mathrm{Cov}^2[X,Y]\leq\mathbb{V}[X]\mathbb{V}[Y] Cov 2 [ X , Y ] ≤ V [ X ] V [ Y ] 。
Show that, if Y = a X + b Y = aX + b Y = a X + b for some parameters a > 0 a > 0 a > 0 and b b b , then ρ ( X , Y ) = 1 \rho(X,Y) = 1 ρ ( X , Y ) = 1 . Similarly show that if a < 0 a < 0 a < 0 , then ρ ( X , Y ) = − 1 \rho(X,Y) = -1 ρ ( X , Y ) = − 1 .
解答:
ρ = E [ a X 2 + b X ] − E [ X ] ⋅ ( a E [ X ] + b ) a 2 V 2 [ X ] = a ( E [ X 2 ] − E 2 [ X ] ) a V [ X ] = 1 \rho=\frac{\mathbb{E}[aX^2+bX]-\mathbb{E}[X]\cdot (a\mathbb{E}[X]+b)}{\sqrt{a^2\mathbb{V}^2[X]}}=\frac{a(\mathbb{E}[X^2]-\mathbb{E}^2[X])}{a\mathbb{V}[X]}=1 ρ = a 2 V 2 [ X ] E [ a X 2 + b X ] − E [ X ] ⋅ ( a E [ X ] + b ) = a V [ X ] a ( E [ X 2 ] − E 2 [ X ]) = 1
类似易得-1。
Exercise 3.4 [Linear combinations of random variables]
Let x x x be a random vector with mean m m m and covariance matrix Σ \Sigma Σ . Let A A A and B B B be matrices.
a. Derive the covariance matrix of A x Ax A x .
b. Show that tr ( A B ) = tr ( B A ) \text{tr}(AB) = \text{tr}(BA) tr ( A B ) = tr ( B A ) .
c. Derive an expression for E [ x T A x ] \mathbb{E}[x^TAx] E [ x T A x ] .
解答:
a. 令 x ∈ R N , A ∈ R M × N , B ∈ R N × M x\in \mathbb{R}^N, A\in\mathbb{R}^{M\times N}, B\in \mathbb{R}^{N \times M} x ∈ R N , A ∈ R M × N , B ∈ R N × M
A x = [ ∑ m = 1 A 1 , m x m , ⋯ , ∑ m = 1 A N , m x m ] ⊤ Σ A x = [ ∑ n 1 = 1 ∑ n 2 = 1 A 1 , n 1 A 1 , n 2 Σ n 1 , n 2 ⋯ ⋮ ⋱ ⋮ ⋯ ] = A Σ A ⊤ \begin{aligned}
Ax &=[\sum_{m=1} A_{1,m}x_m, \cdots, \sum_{m=1}A_{N,m}x_{m}]^{\top}\\
\Sigma_{Ax}&=\begin{bmatrix} \sum_{n_1=1}\sum_{n_2=1} A_{1,n_1} A_{1,n_2} \Sigma_{n_1,n_2} & \cdots & \\ \vdots & \ddots & \vdots \\ & \cdots & \end{bmatrix}\\
&=A\Sigma A^{\top}
\end{aligned} A x Σ A x = [ m = 1 ∑ A 1 , m x m , ⋯ , m = 1 ∑ A N , m x m ] ⊤ = ∑ n 1 = 1 ∑ n 2 = 1 A 1 , n 1 A 1 , n 2 Σ n 1 , n 2 ⋮ ⋯ ⋱ ⋯ ⋮ = A Σ A ⊤
t r ( A B ) = ∑ m = 1 ∑ n = 1 A m , n B n , m = ∑ n = 1 ∑ m = 1 B n , m A m , n = t r ( B A ) \begin{aligned}
\mathrm{tr}(AB) &= \sum_{m=1} \sum_{n=1} A_{m,n} B_{n,m} = \sum_{n=1} \sum_{m=1} B_{n,m} A_{m,n} = \mathrm{tr}(BA)
\end{aligned} tr ( A B ) = m = 1 ∑ n = 1 ∑ A m , n B n , m = n = 1 ∑ m = 1 ∑ B n , m A m , n = tr ( B A )
c. A ∈ R N × N A\in \mathbb{R}^{N\times N} A ∈ R N × N
E [ x ⊤ A x ] = ∑ n 1 = 1 ∑ n 2 = 1 A n 1 , n 2 E [ x n 1 x n 2 ] \begin{aligned}
\mathbb{E}[x^{\top}Ax] &= \sum_{n_1=1}\sum_{n_2=1} A_{n_1,n_2} \mathbb{E}[x_{n_1}x_{n_2}]
\end{aligned} E [ x ⊤ A x ] = n 1 = 1 ∑ n 2 = 1 ∑ A n 1 , n 2 E [ x n 1 x n 2 ]
⚠️ 完善:
a. E [ A x ] = A E [ x ] = A m \mathbb{E}[Ax]=A\mathbb{E}[x]=Am E [ A x ] = A E [ x ] = A m ,根据协方差的定义
Σ y = A x = C o v [ A x ] = E [ ( A x − E [ A x ] ) ( A x − E [ A x ] ) ⊤ ] = E [ A ( x − m ) ( x − m ) ⊤ A ⊤ ] = A E [ ( x − m ) ( x − m ) ⊤ ] A ⊤ = A Σ A ⊤ \begin{aligned}
\Sigma_{y=Ax}&=\mathrm{Cov}[Ax]=\mathbb{E}[(Ax-\mathbb{E}[Ax])(Ax-\mathbb{E}[Ax])^{\top}]\\
&=\mathbb{E}[A(x-m)(x-m)^{\top}A^{\top}]\\
&=A\mathbb{E}[(x-m)(x-m)^{\top}]A^{\top}\\
&=A\Sigma A^{\top}
\end{aligned} Σ y = A x = Cov [ A x ] = E [( A x − E [ A x ]) ( A x − E [ A x ] ) ⊤ ] = E [ A ( x − m ) ( x − m ) ⊤ A ⊤ ] = A E [( x − m ) ( x − m ) ⊤ ] A ⊤ = A Σ A ⊤
c. 首先由标量的迹等于其本身 x ⊤ A x = t r ( x ⊤ A x ) x^{\top}Ax=\mathrm{tr}(x^{\top}Ax) x ⊤ A x = tr ( x ⊤ A x ) ,再由 t r ( A B ) = t r ( B A ) \mathrm{tr}({AB})=\mathrm{tr}({BA}) tr ( A B ) = tr ( B A ) 可得 t r ( x ⊤ A x ) = t r ( ( A x ) x ⊤ ) = t r ( A x x ⊤ ) \mathrm{tr}(x^{\top}Ax)=\mathrm{tr}((Ax)x^{\top})=\mathrm{tr}(Axx^{\top}) tr ( x ⊤ A x ) = tr (( A x ) x ⊤ ) = tr ( A x x ⊤ ) 。
两边同时取期望,由于迹运算本质是线性求和,因此可以与期望交换顺序得
E [ x ⊤ A x ] = E [ t r ( A x x ⊤ ) ] = t r ( E [ A x x ⊤ ] ) = t r ( A E [ x x ⊤ ] ) \mathbb{E}[x^{\top}Ax]=\mathbb{E}[\mathrm{tr}(Axx^{\top})]=\mathrm{tr}(\mathbb{E}[Axx^{\top}])=\mathrm{tr}(A\mathbb{E}[xx^{\top}]) E [ x ⊤ A x ] = E [ tr ( A x x ⊤ )] = tr ( E [ A x x ⊤ ]) = tr ( A E [ x x ⊤ ])
又有协方差的定义 Σ = E [ x x ⊤ ] − E [ x ] E [ x ] ⊤ = E [ x x ⊤ ] − m m ⊤ \Sigma=\mathbb{E}[xx^{\top}]-\mathbb{E}[x]\mathbb{E}[x]^{\top}=\mathbb{E}[xx^{\top}]-mm^{\top} Σ = E [ x x ⊤ ] − E [ x ] E [ x ] ⊤ = E [ x x ⊤ ] − m m ⊤ ,可得
E [ x ⊤ A x ] = t r [ A ( Σ + m m ⊤ ) ] = t r ( A Σ ) + m ⊤ A m \mathbb{E}[x^{\top}Ax]=\mathrm{tr}[A(\Sigma+mm^{\top})]=\mathrm{tr}(A\Sigma)+m^{\top}Am E [ x ⊤ A x ] = tr [ A ( Σ + m m ⊤ )] = tr ( A Σ ) + m ⊤ A m
Exercise 3.5 [Gaussian vs jointly Gaussian]
Let X ∼ N ( 0 , 1 ) X \sim \mathcal{N}(0, 1) X ∼ N ( 0 , 1 ) and Y = W X Y = WX Y = W X , where p ( W = − 1 ) = p ( W = 1 ) = 0.5 p(W = -1) = p(W = 1) = 0.5 p ( W = − 1 ) = p ( W = 1 ) = 0.5 . It is clear that X X X and Y Y Y are not independent, since Y Y Y is a function of X X X .
a. Show Y ∼ N ( 0 , 1 ) Y \sim \mathcal{N}(0, 1) Y ∼ N ( 0 , 1 ) .
b. Show Cov [ X , Y ] = 0 \text{Cov}[X,Y] = 0 Cov [ X , Y ] = 0 . Thus X X X and Y Y Y are uncorrelated but dependent, even though they are Gaussian.
Hint: use the definition of covariance Cov [ X , Y ] = E [ X Y ] − E [ X ] E [ Y ] \text{Cov}[X,Y] = \mathbb{E}[XY] - \mathbb{E}[X]\mathbb{E}[Y] Cov [ X , Y ] = E [ X Y ] − E [ X ] E [ Y ] and the rule of iterated expectation E [ X Y ] = E [ E [ X Y ∣ W ] ] \mathbb{E}[XY] = \mathbb{E}[\mathbb{E}[XY|W]] E [ X Y ] = E [ E [ X Y ∣ W ]] .
解答:
p ( Y = y ) = p ( W X = y ) = p ( − X = y ∣ W = − 1 ) p ( W = − 1 ) + p ( X = y ∣ W = 1 ) p ( W = 1 ) = 1 2 f ( − y ) + 1 2 f ( y ) = f ( y ) = N ( 0 , 1 ) \begin{aligned}
p(Y=y)&=p(WX=y)\\
&=p(-X=y\mid W=-1)p(W=-1)+ p(X=y\mid W=1)p(W=1)\\
&=\frac{1}{2}f(-y)+\frac{1}{2}f(y)\\
&=f(y)=\mathcal{N}(0,1)
\end{aligned} p ( Y = y ) = p ( W X = y ) = p ( − X = y ∣ W = − 1 ) p ( W = − 1 ) + p ( X = y ∣ W = 1 ) p ( W = 1 ) = 2 1 f ( − y ) + 2 1 f ( y ) = f ( y ) = N ( 0 , 1 )
C o v [ X , Y ] = E [ X Y ] − E [ X ] E [ Y ] = E [ X Y ] = E [ E [ X Y ∣ W ] ] = ∑ W p ( W ) p ( X Y ∣ W ) = 1 2 p ( X 2 ) + 1 2 p ( − X 2 ) = 0 \begin{aligned}
\mathrm{Cov}[X,Y]&=\mathbb{E}[XY]-\mathbb{E}[X]\mathbb{E}[Y]\\
&=\mathbb{E}[XY]\\
&=\mathbb{E}[\mathbb{E}[XY\mid W]]\\
&=\sum_{W}p(W)p(XY\mid W)\\
&=\frac{1}{2}p(X^2)+\frac{1}{2}p(-X^2)\\
&=0
\end{aligned} Cov [ X , Y ] = E [ X Y ] − E [ X ] E [ Y ] = E [ X Y ] = E [ E [ X Y ∣ W ]] = W ∑ p ( W ) p ( X Y ∣ W ) = 2 1 p ( X 2 ) + 2 1 p ( − X 2 ) = 0
⚠️ 纠错:
E W [ E [ X Y ∣ W ] ] = p ( W = 1 ) E [ X Y ∣ W = 1 ] + p ( W = − 1 ) E [ X Y ∣ W = − 1 ] = 1 2 E [ X 2 ] + 1 2 E [ − X 2 ] = 0 \begin{aligned}
\mathbb{E}_W[\mathbb{E}[XY\mid W]]&=p(W=1)\mathbb{E}[XY\mid W=1]+p(W=-1)\mathbb{E}[XY\mid W=-1]\\
&=\frac{1}{2}\mathbb{E}[X^2]+\frac{1}{2}\mathbb{E}[-X^2]\\
&=0
\end{aligned} E W [ E [ X Y ∣ W ]] = p ( W = 1 ) E [ X Y ∣ W = 1 ] + p ( W = − 1 ) E [ X Y ∣ W = − 1 ] = 2 1 E [ X 2 ] + 2 1 E [ − X 2 ] = 0
Exercise 3.6 [Normalization constant for a multidimensional Gaussian]
Prove that the normalization constant for a d d d -dimensional Gaussian is given by
( 2 π ) d / 2 ∣ Σ ∣ 1 / 2 = ∫ exp ( − 1 2 ( x − μ ) T Σ − 1 ( x − μ ) ) d x (2\pi)^{d/2}|\Sigma|^{1/2} = \int \exp\left(-\frac{1}{2}(x- \mu)^T\Sigma^{-1}(x- \mu)\right)dx ( 2 π ) d /2 ∣Σ ∣ 1/2 = ∫ exp ( − 2 1 ( x − μ ) T Σ − 1 ( x − μ ) ) d x
Hint: diagonalize Σ \Sigma Σ and use the fact that ∣ Σ ∣ = ∏ i λ i |\Sigma| = \prod_i \lambda_i ∣Σ∣ = ∏ i λ i to write the joint pdf as a product of d d d one-dimensional Gaussians in a transformed coordinate system. (You will need the change of variables formula.) Finally, use the normalization constant for univariate Gaussians.
解答:
p ( x ) = 1 ( 2 π ) d 2 ∏ i = 1 d λ i 1 2 exp { − ∑ i = 1 d ( x i − μ i ) 2 2 λ i } \begin{aligned}
p(\mathbf{x})&=\frac{1}{(2\pi)^{\frac{d}{2}}\prod_{i=1}^d\lambda_i^{\frac{1}{2}}}\exp{\left\{-\sum_{i=1}^d\frac{(x_i -\mu_i)^2}{2\lambda_i} \right\}}\\
\end{aligned} p ( x ) = ( 2 π ) 2 d ∏ i = 1 d λ i 2 1 1 exp { − i = 1 ∑ d 2 λ i ( x i − μ i ) 2 }
⚠️ 纠错:
I = ∫ R d exp ( − 1 2 ( x − μ ) ⊤ Σ − 1 ( x − μ ) ) d x = ∫ R d exp ( − 1 2 y ⊤ Σ − 1 y ) d y substitute y = x − μ \begin{aligned}
I&=\int_{\mathbb{R}^d} \exp{\left(-\frac{1}{2}(x-\mu)^{\top}\Sigma^{-1}(x-\mu) \right)}\mathrm{d}x\\
&=\int_{\mathbb{R}^d} \exp{\left(-\frac{1}{2}y^{\top}\Sigma^{-1}y \right)}\mathrm{d}y \quad \text{substitute }y=x-\mu\\
\end{aligned} I = ∫ R d exp ( − 2 1 ( x − μ ) ⊤ Σ − 1 ( x − μ ) ) d x = ∫ R d exp ( − 2 1 y ⊤ Σ − 1 y ) d y substitute y = x − μ
因为协方差矩阵是一个对称正定矩阵,它可以被正交对角化 Σ = U Λ U T \Sigma = U \Lambda U^T Σ = U Λ U T ,其中 U U U 是正交矩阵(满足 U T U = U U T = I U^TU = UU^T = I U T U = U U T = I ),Λ = diag ( λ 1 , λ 2 , … , λ d ) \Lambda = \text{diag}(\lambda_1, \lambda_2, \dots, \lambda_d) Λ = diag ( λ 1 , λ 2 , … , λ d ) 是由其特征值组成的对角矩阵,因此 Σ − 1 = U Λ − 1 U T \Sigma^{-1} = U \Lambda^{-1} U^T Σ − 1 = U Λ − 1 U T ,由此可得
y T Σ − 1 y = y T ( U Λ − 1 U T ) y = ( U T y ) T Λ − 1 ( U T y ) y^T\Sigma^{-1}y = y^T (U \Lambda^{-1} U^T) y = (U^Ty)^T \Lambda^{-1} (U^Ty) y T Σ − 1 y = y T ( U Λ − 1 U T ) y = ( U T y ) T Λ − 1 ( U T y )
引入 z = U ⊤ y z=U^{\top}y z = U ⊤ y ,变量代换的雅可比矩阵就是 U ( ∣ det ( U ) ∣ = 1 ) U(\left|\det(U)\right|=1) U ( ∣ det ( U ) ∣ = 1 ) ,因此微元代换关系为 d y = ∣ det ( U ) ∣ d z = d z \mathrm{d}y = |\det(U)| \mathrm{d}z = \mathrm{d}z d y = ∣ det ( U ) ∣ d z = d z 。
I = ∫ R d exp ( − 1 2 z T Λ − 1 z ) d z = ∏ i = 1 d ∫ − ∞ ∞ exp ( − z i 2 2 λ i ) d z i using z T Λ − 1 z = ∑ i = 1 d z i 2 λ i = ∫ − ∞ ∞ exp ( − z i 2 2 λ i ) d z i = ( 2 π λ i ) 1 / 2 using ∫ − ∞ ∞ exp ( − x 2 2 σ 2 ) d x = 2 π σ 2 = I = ∏ i = 1 d ( 2 π ) 1 / 2 λ i 1 / 2 = ( 2 π ) d / 2 ( ∏ i = 1 d λ i ) 1 / 2 \begin{aligned}
I &= \int_{\mathbb{R}^d} \exp\left(-\frac{1}{2}z^T \Lambda^{-1} z\right) \mathrm{d}z\\
&= \prod_{i=1}^d \int_{-\infty}^{\infty} \exp\left(-\frac{z_i^2}{2\lambda_i}\right) \mathrm{d}z_i \quad \text{using } z^T \Lambda^{-1} z = \sum_{i=1}^d \frac{z_i^2}{\lambda_i}\\
&=\int_{-\infty}^{\infty} \exp\left(-\frac{z_i^2}{2\lambda_i}\right) \mathrm{d}z_i = (2\pi\lambda_i)^{1/2} \quad \text{using } \int_{-\infty}^{\infty} \exp(-\frac{x^2}{2\sigma^2})dx = \sqrt{2\pi\sigma^2} \\
&=I = \prod_{i=1}^d (2\pi)^{1/2} \lambda_i^{1/2} = (2\pi)^{d/2} \left( \prod_{i=1}^d \lambda_i \right)^{1/2}
\end{aligned} I = ∫ R d exp ( − 2 1 z T Λ − 1 z ) d z = i = 1 ∏ d ∫ − ∞ ∞ exp ( − 2 λ i z i 2 ) d z i using z T Λ − 1 z = i = 1 ∑ d λ i z i 2 = ∫ − ∞ ∞ exp ( − 2 λ i z i 2 ) d z i = ( 2 π λ i ) 1/2 using ∫ − ∞ ∞ exp ( − 2 σ 2 x 2 ) d x = 2 π σ 2 = I = i = 1 ∏ d ( 2 π ) 1/2 λ i 1/2 = ( 2 π ) d /2 ( i = 1 ∏ d λ i ) 1/2
Exercise 3.7 [Sensor fusion with known variances in 1d]
Suppose we have two sensors with known (and different) variances v 1 v_1 v 1 and v 2 v_2 v 2 , but unknown (and the same) mean μ \mu μ . Suppose we observe n 1 n_1 n 1 observations y i ( 1 ) ∼ N ( μ , v 1 ) y^{(1)}_i \sim \mathcal{N}(\mu, v_1) y i ( 1 ) ∼ N ( μ , v 1 ) from the first sensor and n 2 n_2 n 2 observations y i ( 2 ) ∼ N ( μ , v 2 ) y^{(2)}_i \sim \mathcal{N}(\mu, v_2) y i ( 2 ) ∼ N ( μ , v 2 ) from the second sensor. (For example, suppose μ \mu μ is the true temperature outside, and sensor 1 is a precise (low variance) digital thermosensing device, and sensor 2 is an imprecise (high variance) mercury thermometer.) Let D D D represent all the data from both sensors. What is the posterior p ( μ ∣ D ) p(\mu|D) p ( μ ∣ D ) , assuming a non-informative prior for μ \mu μ (which we can simulate using a Gaussian with a precision of 0)? Give an explicit expression for the posterior mean and variance.
解答:
假设 μ ∼ N ( m 0 , τ 0 − 1 ) , τ 0 → 0 + \mu \sim \mathcal{N}(m_0, \tau_0^{-1}), \tau_0 \rightarrow 0^{+} μ ∼ N ( m 0 , τ 0 − 1 ) , τ 0 → 0 + ,
p ( μ ∣ D ) ∝ p ( D ∣ μ ) p ( μ ) ∝ p ( D ∣ μ ) = p ( { y i 1 } i = 1 n 1 ∣ μ , v 1 ) p ( { y j 2 } j = 1 n 2 ∣ μ , v 2 ) ∝ exp { ∑ i = 1 n 1 − ( y i 1 − μ ) 2 2 v 1 + ∑ j = 1 n 2 − ( μ − y j 2 ) 2 2 v 2 } ∝ exp ( − μ 2 − 2 ( v 2 ∑ i = 1 n 1 y i 1 + v 1 ∑ j = 1 n 2 y j 2 ) μ 2 v 1 v 2 / ( n 1 v 2 + n 2 v 1 ) ) = N ( v 2 ∑ i = 1 n 1 y i 1 + v 1 ∑ j = 1 n 2 y j 2 n 1 v 2 + n 2 v 1 , v 1 v 2 n 1 v 2 + n 2 v 1 ) \begin{aligned}
p(\mu\mid D)&\propto p(D\mid \mu)p(\mu)\propto p(D\mid \mu)\\
&=p(\{y_i^1\}_{i=1}^{n_1}\mid \mu, v_1) p(\{y_j^2\}_{j=1}^{n_2}\mid \mu, v_2)\\
&\propto \exp{\left\{\sum_{i=1}^{n_1}-\frac{(y_i^1 - \mu)^2}{2v_1} +\sum_{j=1}^{n_2}-\frac{(\mu-y_j^2)^2}{2v_2} \right\}}\\
&\propto \exp{\left(-\frac{\mu^2 -2(v_2\sum_{i=1}^{n_1}y_i^1+v_1\sum_{j=1}^{n_2}y_j^2)\mu}{2v_1v_2 / (n_1v_2+n_2v_1)}\right)}\\
&=\mathcal{N}(\frac{v_2\sum_{i=1}^{n_1}y_i^1 + v_1\sum_{j=1}^{n_2}y_j^2}{n_1v_2+n_2v_1}, \frac{v_1v_2}{n_1v_2+n_2v_1})
\end{aligned} p ( μ ∣ D ) ∝ p ( D ∣ μ ) p ( μ ) ∝ p ( D ∣ μ ) = p ({ y i 1 } i = 1 n 1 ∣ μ , v 1 ) p ({ y j 2 } j = 1 n 2 ∣ μ , v 2 ) ∝ exp { i = 1 ∑ n 1 − 2 v 1 ( y i 1 − μ ) 2 + j = 1 ∑ n 2 − 2 v 2 ( μ − y j 2 ) 2 } ∝ exp ( − 2 v 1 v 2 / ( n 1 v 2 + n 2 v 1 ) μ 2 − 2 ( v 2 ∑ i = 1 n 1 y i 1 + v 1 ∑ j = 1 n 2 y j 2 ) μ ) = N ( n 1 v 2 + n 2 v 1 v 2 ∑ i = 1 n 1 y i 1 + v 1 ∑ j = 1 n 2 y j 2 , n 1 v 2 + n 2 v 1 v 1 v 2 )
Exercise 3.8 [Show that the Student distribution can be written as a Gaussian scale mixture]
Show that a Student distribution can be written as a Gaussian scale mixture, where we use a Gamma mixing distribution on the precision α \alpha α , i.e.
p ( x ∣ μ , a , b ) = ∫ 0 ∞ N ( x ∣ μ , α − 1 ) Ga ( α ∣ a , b ) d α p(x|\mu, a, b) = \int_0^\infty \mathcal{N}(x|\mu, \alpha^{-1})\text{Ga}(\alpha|a, b)d\alpha p ( x ∣ μ , a , b ) = ∫ 0 ∞ N ( x ∣ μ , α − 1 ) Ga ( α ∣ a , b ) d α
This can be viewed as an infinite mixture of Gaussians, with different precisions.
解答:
p ( x ∣ μ , a , b ) = ∫ 0 ∞ α 1 2 2 π exp { − α ( x − μ ) 2 2 } b a Γ ( a ) α a − 1 exp { − b α } d α = b a 2 π Γ ( a ) ∫ 0 ∞ α a − 1 2 exp { − ( x − μ ) 2 + 2 b 2 α } d α = b a 2 π Γ ( a ) ⋅ [ 2 ( x − μ ) 2 + 2 b ] a + 1 2 ∫ 0 ∞ t a − 1 2 exp { − t } d t substitue t = ( x − μ ) 2 + 2 b 2 α = b a Γ ( a + 1 2 ) 2 π Γ ( a ) [ 2 ( x − μ ) 2 + 2 b ] a + 1 2 \begin{aligned}
p(x\mid \mu,a,b) &= \int_{0}^{\infty}\frac{\alpha^{\frac{1}{2}}}{\sqrt{2\pi}} \exp{\left\{-\frac{\alpha(x-\mu)^2}{2} \right\}} \frac{b^a}{\Gamma(a)}\alpha^{a-1}\exp{\left\{-b\alpha \right\}} \mathrm{d}\alpha\\
&=\frac{b^a}{\sqrt{2\pi} \Gamma(a)}\int_{0}^{\infty}\alpha^{a-\frac{1}{2}}\exp{\left\{-\frac{(x-\mu)^2+2b}{2}\alpha \right\}}\mathrm{d}\alpha\\
&=\frac{b^a}{\sqrt{2\pi} \Gamma(a)}\cdot \left[\frac{2}{(x-\mu)^2 + 2b} \right]^{a+\frac{1}{2}}\int_{0}^{\infty}t^{a-\frac{1}{2}}\exp{\{-t\}}\mathrm{d}t \qquad \text{substitue } t=\frac{(x-\mu)^2+2b}{2}\alpha \\
&=\frac{b^a \Gamma(a+\frac{1}{2})}{\sqrt{2\pi} \Gamma(a)}\left[\frac{2}{(x-\mu)^2 + 2b} \right]^{a+\frac{1}{2}}
\end{aligned} p ( x ∣ μ , a , b ) = ∫ 0 ∞ 2 π α 2 1 exp { − 2 α ( x − μ ) 2 } Γ ( a ) b a α a − 1 exp { − b α } d α = 2 π Γ ( a ) b a ∫ 0 ∞ α a − 2 1 exp { − 2 ( x − μ ) 2 + 2 b α } d α = 2 π Γ ( a ) b a ⋅ [ ( x − μ ) 2 + 2 b 2 ] a + 2 1 ∫ 0 ∞ t a − 2 1 exp { − t } d t substitue t = 2 ( x − μ ) 2 + 2 b α = 2 π Γ ( a ) b a Γ ( a + 2 1 ) [ ( x − μ ) 2 + 2 b 2 ] a + 2 1
⚠️ 完善: 利用 2 ( x − μ ) 2 + 2 b = 2 2 b ( 1 + ( x − μ ) 2 2 b ) = 1 b ( 1 + ( x − μ ) 2 2 b ) − 1 \frac{2}{(x-\mu)^2 + 2b} = \frac{2}{2b \left(1 + \frac{(x-\mu)^2}{2b}\right)} = \frac{1}{b} \left( 1 + \frac{(x-\mu)^2}{2b} \right)^{-1} ( x − μ ) 2 + 2 b 2 = 2 b ( 1 + 2 b ( x − μ ) 2 ) 2 = b 1 ( 1 + 2 b ( x − μ ) 2 ) − 1 得到
p ( x ∣ μ , a , b ) = b a Γ ( a + 1 2 ) 2 π Γ ( a ) ⋅ b − ( a + 1 2 ) [ 1 + ( x − μ ) 2 2 b ] − ( a + 1 2 ) = Γ ( a + 1 2 ) Γ ( a ) 2 π b [ 1 + 1 2 b ( x − μ ) 2 ] − ( a + 1 2 ) \begin{aligned}
p(x\mid \mu,a,b)&= \frac{b^a \Gamma(a+\frac{1}{2})}{\sqrt{2\pi} \Gamma(a)} \cdot b^{-(a+\frac{1}{2})} \left[ 1 + \frac{(x-\mu)^2}{2b} \right]^{-(a+\frac{1}{2})}\\
&= \frac{\Gamma(a+\frac{1}{2})}{\Gamma(a)\sqrt{2\pi b}} \left[ 1 + \frac{1}{2b}(x-\mu)^2 \right]^{-(a+\frac{1}{2})}
\end{aligned} p ( x ∣ μ , a , b ) = 2 π Γ ( a ) b a Γ ( a + 2 1 ) ⋅ b − ( a + 2 1 ) [ 1 + 2 b ( x − μ ) 2 ] − ( a + 2 1 ) = Γ ( a ) 2 π b Γ ( a + 2 1 ) [ 1 + 2 b 1 ( x − μ ) 2 ] − ( a + 2 1 )
一个具有自由度 ν \nu ν (degrees of freedom)、位置参数 μ \mu μ 和精度参数 λ \lambda λ 的标准学生 t 分布的 PDF 为:
St ( x ∣ μ , λ , ν ) = Γ ( ν + 1 2 ) Γ ( ν 2 ) ( λ ν π ) 1 2 [ 1 + λ ν ( x − μ ) 2 ] − ν + 1 2 \text{St}(x\mid \mu, \lambda, \nu) = \frac{\Gamma(\frac{\nu+1}{2})}{\Gamma(\frac{\nu}{2})} \left(\frac{\lambda}{\nu \pi}\right)^{\frac{1}{2}} \left[ 1 + \frac{\lambda}{\nu}(x-\mu)^2 \right]^{-\frac{\nu+1}{2}} St ( x ∣ μ , λ , ν ) = Γ ( 2 ν ) Γ ( 2 ν + 1 ) ( ν π λ ) 2 1 [ 1 + ν λ ( x − μ ) 2 ] − 2 ν + 1
令自由度 ν = 2 a \nu = 2a ν = 2 a ,令精度参数 λ = a b \lambda = \frac{a}{b} λ = b a 即可得到上式