# 推导2

$$\gamma_{jk}$$代表第j个观测值是否选择了第k个模型，1：是，0：否\
$$\hat \gamma_{jk} = E(\gamma_{jk}|y,\theta)$$代表在y和$$\theta$$已知的情况下$$\gamma_{jk}$$的条件期望。

$$
\begin{aligned}
\hat \gamma_{jk} & = E(\gamma_{jk}|y,\theta) \\
& = P(\gamma_{jk}=1|y,\theta) && {1} \\
& = \frac{P(\gamma_{jk}=1, y_j | \theta)}{\sum_kP(\gamma_{jk}=1, y_j | \theta)} && {2} \\
& = \frac{P(y_j | \gamma_{jk}=1, \theta)P(\gamma_{jk}=1|\theta)}{\sum_kP(y_j | \gamma_{jk}=1, \theta)P(\gamma_{jk}=1|\theta)} && {3} \\
& = \frac{a_k\phi(y_j|\theta_k)}{\sum_k a_k\phi(y_j|\theta_k)}  && {4}
\end{aligned}
$$

关于以上公式的说明：\
（1）：离散变量\gamma\_{jk}的取值范围为0和1。根据[离散型变量的期望公式](https://windmising.gitbook.io/mathematics-basic-for-ml/gai-shuai-lun/expectation_variance)，得：

$$
E(\gamma_{jk}|y,\theta) = 1 * P(\gamma_{jk}=1|y,\theta) + 0 * P(\gamma_{jk}=0|y,\theta)
$$

（2）：

$$
\begin{aligned}
P(\gamma_{jk}=1|y,\theta) & = P(\gamma_{jk}=1|y_j,\theta) & \text{只有}y_j\text{与}P(\gamma_{jk})\text{有关,其它y都可以忽略} \\
& = \frac{P(\gamma_{jk}=1|y_j,\theta)}{\sum_k P(\gamma_{jk}|y_j=1,\theta)} & \text{根据}\gamma_{jk}\text{的定义,}\sum_k P(\gamma_{jk}=1) = 1,\text{与}y_j\text{和}\theta\text{无关}  \\
& = \frac{P(\gamma_{jk}=1|y_j,\theta)P(y_j|\theta)}{\sum_k P(\gamma_{jk}|y_j=1,\theta)P(y_j|\theta)} & \text{分子分母同乘以}P(y_j|\theta)  \\
& = \frac{P(\gamma_{jk}=1, y_j|\theta)}{\sum_k P(\gamma_{jk}=1, y_j|\theta)} & \text{贝叶斯公式,}P(A|B)P(B) = P(A, B)
\end{aligned}
$$

（3）：贝叶斯公式，P(A, B) = P(B|A)P(A)\
（4）：$$P(\gamma_{jk}=1|\theta)$$代表选择模型k的概率，为ak\
$$P(y_j | \gamma_{jk}=1, \theta)$$代表通过第k的模型得到yj的概率，为$$\phi(y_j|\theta_k)$$
