hiden-cubistのブログ

機械学習などの技術や投資に関する情報を記事にしています。

ベイズ推定とグラフィカルモデル Section6 Worksheet

ベイズ推定とグラフィカルモデルの略解をまとめています。あくまで個人のメモですので、必ずしも正しい保証はありません。もしミスがある場合は教えていただければ幸いです。Section5にはWorksheetが無いため、次はSection6です。

以下、


P(w|x, \theta)=Norm_w[\phi_0+\phi_1 x, \sigma^2]\\
\displaystyle \bar{w}=\sum_{i=1}^I w_i,\quad
\bar{x}=\sum_{i=1}^I x_i,\quad
\bar{x^2}=\sum_{i=1}^I x_i^2,\quad
\bar{xw}=\sum_{i=1}^I x_i w_i\\
\theta=\{\phi_0, \phi_1, \sigma^2\}

とする。

1. 識別モデルを用いた最尤推定による線形回帰の導出


\newcommand{\argmax}{\mathop{\rm arg~max}\limits}
\hat{\theta}\\
\displaystyle =\argmax_{\theta} \prod_{i=1}^I Norm_{w_i}[\phi_0+\phi_1 x, \sigma^2]\\
\displaystyle =\argmax_{\theta} \sum_{i=1}^I \log[Norm_{w_i}[\phi_0+\phi_1 x, \sigma^2]]\\
\displaystyle L=\sum_{i=1}^I \log[Norm_{w_i}[\phi_0+\phi_1 x, \sigma^2]]

\frac{\partial L}{\partial \phi_0}=0, \frac{\partial L}{\partial \phi_1}=0 を解いて、


\left(
  \begin{array}{cc}
  I & \bar{x} \\
  \bar{x} & \bar{x^2}
  \end{array}
  \right)
  \left(
  \begin{array}{c}
  \hat\phi_0 \\
  \hat\phi_1
  \end{array}
  \right)
  =
  \left(
  \begin{array}{l}
  \bar{w}\\
  \bar{xw}
  \end{array}
  \right)

\frac{\partial L}{\partial \sigma^2}=0 を解いて、


\displaystyle \hat{\sigma^2} = \frac{\sum_{i=1}^I \{w_i-(\phi_0+\phi_1 x_i)\}^2}{I}

2. 識別モデルを用いたMAP推定による線形回帰の導出(事前分布: P(\theta)=\kappa Norm_{\phi_0}[\mu_0, \sigma_0^2] Norm_{\phi_1}[\mu_1, \sigma_1^2]\)


\newcommand{\argmax}{\mathop{\rm arg~max}\limits}
\hat{\theta}\\
\displaystyle =\argmax_{\theta} \prod_{i=1}^I Norm_{w_i}[\phi_0+\phi_1 x, \sigma^2]\kappa Norm_{\phi_0}[\mu_0, \sigma_0^2] Norm_{\phi_1}[\mu_1, \sigma_1^2]\\
\displaystyle =\argmax_{\theta} \sum_{i=1}^I \log[Norm_{w_i}[\phi_0+\phi_1 x, \sigma^2]]+log[\kappa]+log[Norm_{\phi_0}[\mu_0, \sigma_0^2]]+log[Norm_{\phi_1}[\mu_1, \sigma_1^2]]\\
\displaystyle L=\sum_{i=1}^I \log[Norm_{w_i}[\phi_0+\phi_1 x, \sigma^2]]+log[\kappa]+log[Norm_{\phi_0}[\mu_0, \sigma_0^2]]+log[Norm_{\phi_1}[\mu_1, \sigma_1^2]]

\frac{\partial L}{\partial \phi_0}=0, \frac{\partial L}{\partial \phi_1}=0 を解いて、


\left(
  \begin{array}{cc}
  I+\frac{\sigma^2}{\sigma_0^2} & \bar{x} \\
  \bar{x} & \bar{x^2}+\frac{\sigma^2}{\sigma_1^2}
  \end{array}
  \right)
  \left(
  \begin{array}{c}
  \hat\phi_0 \\
  \hat\phi_1
  \end{array}
  \right)
  =
  \left(
  \begin{array}{l}
  \bar{w}+\mu_0\frac{\sigma^2}{\sigma_0^2}\\
  \bar{xw}+\mu_1\frac{\sigma^2}{\sigma_1^2}
  \end{array}
  \right)

\frac{\partial L}{\partial \sigma^2}=0 を解いて、


\displaystyle \hat{\sigma^2} = \frac{\sum_{i=1}^I \{w_i-(\phi_0+\phi_1 x_i)\}^2}{I}


以下、


P(x|w, \theta)=Norm_x[\phi_0+\phi_1 w, \sigma^2]\\
P(w)=Norm_w[\mu_p, \sigma_p^2]\\
\hat\theta=\{\hat\phi_0, \hat\phi_1, \hat\sigma^2\}

とする。

3. 生成モデルによる線形回帰の事後分布の導出


P(w|x)\\
\displaystyle \propto Norm_x[\hat\phi_0+\hat\phi_1w, \hat\sigma^2]Norm_w[\mu_p, \sigma_p^2]\\
\displaystyle \propto Norm_w[\frac{x-\hat\phi_0}{\hat\phi_1}, \frac{\hat\sigma^2}{\hat\phi_1^2}]Norm_w[\mu_p, \sigma_p^2]\\
\displaystyle \propto Norm_w[\frac{\hat\phi_1(x-\hat\phi_0)\sigma_p^2+\mu_p\hat\sigma^2}{\hat\phi_1^2\sigma_p^2+\hat\sigma^2}, \frac{\hat\sigma^2\sigma_p^2}{\hat\phi_1^2\sigma_p^2+\hat\sigma^2}]\\
\displaystyle P(w|x)
=Norm_w[\frac{\hat\phi_1(x-\hat\phi_0)\sigma_p^2+\mu_p\hat\sigma^2}{\hat\phi_1^2\sigma_p^2+\hat\sigma^2}, \frac{\hat\sigma^2\sigma_p^2}{\hat\phi_1^2\sigma_p^2+\hat\sigma^2}]

4. 2. 3.に関する考察

問2の識別モデルで \sigma_0^2\rightarrow\infty, \sigma_1^2\rightarrow\inftyとしたとき、事前分布の分散が無限大であるため、パラメータは最尤推定値である問1の結果と一致する。また、問3の生成モデルで \sigma_p^2\rightarrow\inftyとしたとき


\displaystyle P(w|x)=Norm_w[\frac{x-\hat\phi_0}{\hat\phi_1}, \frac{\hat\sigma^2}{\hat\phi_1^2} ]

となり、事後確率は生成モデルの変数xwを反転させた分布に一致する。