3A
  • Portfolio Top
  • Categories
  • Tags
  • Archives

HMMのスケーリング

HMMを実装する際に課題となるのが、forward-algorithm で \(\alpha\) を再帰的に求める際に、\(\alpha\left(\mathbf{z}_{n-1}\right)\) に \(p(\mathbf{z}_n|\mathbf{z}_{n-1})\) と \(p(\mathbf{x}_n|\mathbf{z}_n)\) をかけるため、値が非常に小さくなり、計算機のダイナミックレンジを超えてしまうことです。

そこで、ここでは \(\alpha\left(\mathbf{z}_{n}\right)\) と \(\beta\left(\mathbf{z}_{n}\right)\) にスケーリングを施し、それらの値が \(1\) のオーダーに止まるようにする手法を説明します。

forward-backward \(\alpha,\beta\)

forward-backward algorithm で用いられていた \(\alpha,\beta\) は以下のように定義されていました。

$$ \begin{aligned} \alpha\left(\mathbf{z}_{n}\right) & \equiv p\left(\mathbf{x}_{1}, \ldots, \mathbf{x}_{n}, \mathbf{z}_{n}\right) & (13.34)\\ \beta\left(\mathbf{z}_{n}\right) & \equiv p\left(\mathbf{x}_{n+1}, \ldots, \mathbf{x}_{N} | \mathbf{z}_{n}\right) & (13.35) \end{aligned} $$

Scaling factors

まず、スケーリングされた \(\alpha,\beta\) は以下のように表されます。スケーリングによって、\(\alpha\) は高々 \(K\) 個の変数上の確率分布、\(\beta\) は2つの条件付き確率の比になることがわかります。

$$ \begin{aligned} \widehat{\alpha}\left(\mathbf{z}_{n}\right) &=p\left(\mathbf{z}_{n} | \mathbf{x}_{1}, \ldots, \mathbf{x}_{n}\right)=\frac{\alpha\left(\mathbf{z}_{n}\right)}{p\left(\mathbf{x}_{1}, \ldots, \mathbf{x}_{n}\right)} & (13.55)\\ \widehat{\beta}\left(\mathbf{z}_{n}\right) &=\frac{p\left(\mathbf{x}_{n+1}, \ldots, \mathbf{x}_{N} | \mathbf{z}_{n}\right)}{p\left(\mathbf{x}_{n+1}, \ldots, \mathbf{x}_{N} | \mathbf{x}_{1}, \ldots, \mathbf{x}_{n}\right)}=\frac{\beta\left(\mathbf{z}_{n}\right)}{p\left(\mathbf{x}_{n+1}, \ldots, \mathbf{x}_{N} | \mathbf{x}_{1}, \ldots, \mathbf{x}_{n}\right)} & (13.61) \end{aligned} $$

ここで、これらと \(\alpha,\beta\) を関連付けるためのスケーリング係数 \(c\) を導入します。

$$ c_{n}=p\left(\mathbf{x}_{n} | \mathbf{x}_{1}, \ldots, \mathbf{x}_{n-1}\right)\qquad (13.56) $$

すると、

$$ \begin{aligned} p\left(\mathbf{x}_1,\ldots,\mathbf{x}_n\right) &= p\left(\mathbf{x}_n | \mathbf{x}_1,\ldots,\mathbf{x}_{n-1}\right)\cdots p\left(\mathbf{x}_3 | \mathbf{x}_1,\mathbf{x}_{2}\right)p\left(\mathbf{x}_2 | \mathbf{x}_1\right)p(\mathbf{x}_1)\\ &= c_n\cdots c_3c_2c_1\\ &= \prod_{m=1}^{n} c_{m} \end{aligned}\qquad (13.58) $$

と展開することができるので、

$$ \begin{aligned} \alpha\left(\mathbf{z}_{n}\right)&=p\left(\mathbf{z}_{n} | \mathbf{x}_{1}, \ldots, \mathbf{x}_{n}\right) p\left(\mathbf{x}_{1}, \ldots, \mathbf{x}_{n}\right)=\left(\prod_{m=1}^{n} c_{m}\right) \widehat{\alpha}\left(\mathbf{z}_{n}\right) & (13.58)\\ \beta\left(\mathbf{z}_{n}\right)&=p\left(\mathbf{x}_{n+1}, \ldots, \mathbf{x}_{N} | \mathbf{x}_{1}, \ldots, \mathbf{x}_{n}\right)\widehat{\beta}\left(\mathbf{z}_{n}\right) = \left(\prod_{m=n+1}^{N} c_{m}\right) \widehat{\beta}\left(\mathbf{z}_{n}\right) & (13.60) \end{aligned} $$

と対応関係がわかります。

\(\gamma,\xi\)

続いて、\(\gamma,\xi\) と \(\widehat{\alpha},\widehat{\beta}\) の対応関係を求めます。

\(\alpha,\beta\)

\(\alpha,\beta\) を用いると、以下のように表されていました。

$$ \begin{aligned} \gamma\left(\mathbf{z}_{n}\right) &= \frac{\alpha\left(\mathbf{z}_{n}\right) \beta\left(\mathbf{z}_{n}\right)}{p(\mathbf{X})} & (13.33)\\ \xi\left(\mathbf{z}_{n-1}, \mathbf{z}_{n}\right) &=\frac{\alpha\left(\mathbf{z}_{n-1}\right) p\left(\mathbf{x}_{n} | \mathbf{z}_{n}\right) p\left(\mathbf{z}_{n} | \mathbf{z}_{n-1}\right) \beta\left(\mathbf{z}_{n}\right)}{p(\mathbf{X})} &(13.43) \end{aligned}$$

\(\widehat{\alpha},\widehat{\beta}\)

先の対応関係を用いれば、\(\widehat{\alpha},\widehat{\beta}\) を用いると、

$$ \begin{aligned} \gamma\left(\mathbf{z}_{n}\right) &=\widehat{\alpha}\left(\mathbf{z}_{n}\right) \widehat{\beta}\left(\mathbf{z}_{n}\right) & (13.64)\\ \xi\left(\mathbf{z}_{n-1}, \mathbf{z}_{n}\right) &=\left(c_{n}\right)^{-1} \widehat{\alpha}\left(\mathbf{z}_{n-1}\right) p\left(\mathbf{x}_{n} | \mathbf{z}_{n}\right) p\left(\mathbf{z}_{n} | \mathbf{z}_{n-1}\right) \widehat{\beta}\left(\mathbf{z}_{n}\right) & (13.65) \end{aligned} $$

と表されることがわかります。

Recursion

最後に、再帰式の対応関係も求めます。

\(\alpha,\beta\)

$$ \begin{aligned} \alpha\left(\mathbf{z}_{n}\right) &=p\left(\mathbf{x}_{n} | \mathbf{z}_{n}\right) \sum_{\mathbf{z}_{n-1}} \alpha\left(\mathbf{z}_{n-1}\right) p\left(\mathbf{z}_{n} | \mathbf{z}_{n-1}\right) & (13.36)\\ \alpha\left(\mathbf{z}_{1}\right) &=p\left(\mathbf{x}_{1}, \mathbf{z}_{1}\right)=p\left(\mathbf{z}_{1}\right) p\left(\mathbf{x}_{1} | \mathbf{z}_{1}\right)=\prod_{k=1}^{K}\left\{\pi_{k} p\left(\mathbf{x}_{1} | \boldsymbol{\phi}_{k}\right)\right\}^{z_{1 k}} & (13.37)\\ \beta\left(\mathbf{z}_{n}\right) &=\sum_{\mathbf{z}_{n+1}} \beta\left(\mathbf{z}_{n+1}\right) p\left(\mathbf{x}_{n+1} | \mathbf{z}_{n+1}\right) p\left(\mathbf{z}_{n+1} | \mathbf{z}_{n}\right) & (13.38)\\ \beta\left(\mathbf{z}_{N}\right) &= \frac{\gamma\left(\mathbf{z}_N\right)p\left(\mathbf{X}\right)}{\alpha\left(\mathbf{z}_N\right)} = \frac{p\left(\mathbf{z}_{N} | \mathbf{X}\right)p(\mathbf{X})}{p\left(\mathbf{X}, \mathbf{z}_{N}\right)} = 1 & (13.30) \end{aligned} $$

\(\widehat{\alpha},\widehat{\beta}\)

$$ \begin{aligned} c_{n} \widehat{\alpha}\left(\mathbf{z}_{n}\right) &=p\left(\mathbf{x}_{n} | \mathbf{z}_{n}\right) \sum_{\mathbf{z}_{n-1}} \widehat{\alpha}\left(\mathbf{z}_{n-1}\right) p\left(\mathbf{z}_{n} | \mathbf{z}_{n-1}\right) & (13.58)\\ \widehat{\alpha}\left(\mathbf{z}_{1}\right) &=p\left(\mathbf{z}_{1}| \mathbf{x}_{1}\right)=\frac{p\left(\mathbf{z}_{1}\right)p\left(\mathbf{x}_{1}| \mathbf{z}_{1}\right)}{p\left(\mathbf{x}_{1}\right)} = \frac{\prod_{k=1}^{K}\left\{\pi_{k} p\left(\mathbf{x}_{1} | \boldsymbol{\phi}_{k}\right)\right\}^{z_{1 k}}}{p\left(\mathbf{x}_{1}\right)}\\ c_{n+1} \widehat{\beta}\left(\mathbf{z}_{n}\right) &=\sum_{\mathbf{z}_{n+1}} \widehat{\beta}\left(\mathbf{z}_{n+1}\right) p\left(\mathbf{x}_{n+1} | \mathbf{z}_{n+1}\right) p\left(\mathbf{z}_{n+1} | \mathbf{z}_{n}\right) &(13.62)\\ \widehat{\beta}\left(\mathbf{z}_{N}\right) &= \frac{\gamma\left(\mathbf{z}_N\right)}{\widehat{\alpha}\left(\mathbf{z}_N\right)} = \frac{p\left(\mathbf{z}_{N} | \mathbf{X}\right)}{p\left(\mathbf{z}_{n} | \mathbf{x}_{1}, \ldots, \mathbf{x}_{n}\right)} = 1 & (13.30) \end{aligned} $$

なお、ここで \((13.58)\) でどのようにして \(c_n\) を求めるかですが、

$$ \begin{aligned} \mathrm{R.H.S}\ (13.58) &= p\left(\mathbf{x}_{n} | \mathbf{z}_{n}\right) \sum_{\mathbf{z}_{n-1}} \widehat{\alpha}\left(\mathbf{z}_{n-1}\right) p\left(\mathbf{z}_{n} | \mathbf{z}_{n-1}\right)\\ &= p\left(\mathbf{x}_{n} | \mathbf{z}_{n}\right) \sum_{\mathbf{z}_{n-1}}p\left(\mathbf{z}_{n-1}|\mathbf{x}_1,\ldots,\mathbf{x}_{n-1}\right) p\left(\mathbf{z}_{n} | \mathbf{z}_{n-1}\right)\\ &= p\left(\mathbf{x}_{n} | \mathbf{z}_{n}\right) p\left(\mathbf{z}_{n}|\mathbf{x}_1,\ldots,\mathbf{x}_{n-1}\right)\\ &=p\left(\mathbf{x}_{n},\mathbf{z}_{n}|\mathbf{x}_1,\ldots,\mathbf{x}_{n-1}\right) \end{aligned} $$

となることから、\((13.58)\) の右辺を \(\mathbf{z}_n\) について周辺化すれば、

$$\sum_{\mathbf{z}_{n}}p\left(\mathbf{x}_{n},\mathbf{z}_{n}|\mathbf{x}_1,\ldots,\mathbf{x}_{n-1}\right) = p\left(\mathbf{x}_{n}|\mathbf{x}_1,\ldots,\mathbf{x}_{n-1}\right) = c_n$$

となるので、\(c_n\) が求められることがわかります。

おまけ(尤度関数)

尤度関数はスケーリング係数 \(c\) を用いるだけで簡単に求められることがわかります。

$$p(\mathbf{X})=\prod_{n=1}^{N} c_{n}\qquad (13.63)$$

  • « HMMの最尤推定の計算過程
  • 生物統計論 第0回 »
hidden
Table of Contents
Published
Sep 26, 2019
Last Updated
Sep 26, 2019
Category
情報基礎実験(浅井)
Tags
  • 3A 127
  • 情報基礎実験(浅井) 13
Contact
Other contents
  • Home
  • Blog
  • Front-End
  • Kerasy
  • Python-Charmers
  • Translation-Gummy
    • 3A - Shuto's Notes
    • MIT
    • Powered by Pelican. Theme: Elegant