Processing math: 0%

2018年3月11日日曜日

強化学習 〜Fisher情報行列と自然勾配法〜

はじめに


 先のページで方策勾配定理を導いた。すなわち、時間ステップt=0から始める状態価値関数J(\theta;s_0)に対して次式が成り立つことを示した。 \begin{equation} \frac{\partial J(\theta;s_0)}{\partial \theta} = {\bf E}\left[\frac{\partial \ln{\pi_{\theta}(a|s)}}{\partial \theta}\;Q(s,a)\right] \end{equation} 今回は、\thetaをベクトル\vec{\theta}に拡張した式 \begin{equation} \vec{\nabla}_{\theta}J(\vec{\theta};s_0) = {\bf E} \left[ \vec{\nabla}_{\theta} \ln{\pi_{\theta}(a|s)}\;Q(s,a) \right] \label{eq2} \end{equation} を考え、J(\vec{\theta};s_0)を勾配法で最大化する過程で用いられる手法をまとめる。以降、J(\vec{\theta};s_0)J(\vec{\theta})と書く。

Fisher情報行列の導出


 2つの確率分布P(w),Q(w)を考え、これらの間のKullback-Leibler divergenceを考える。 \begin{equation} D(P,Q)=\int dw\; P(w) \ln{\frac{P(w)}{Q(w)}} \end{equation} この量を対称化して、2つの確率分布間の「距離」を表すことができるようにする。 \begin{eqnarray} D_s(P,Q) &=&\int dw\; P(w) \ln{\frac{P(w)}{Q(w)}}+\int dw\; Q(w) \ln{\frac{Q(w)}{P(w)}}\\ &=&\int dw\; \left(P(w)-Q(w)\right) \ln{\frac{P(w)}{Q(w)}} \end{eqnarray} いま、パラメータ\vec{\theta}を持つモデルで表現された確率分布P(w|\vec{\theta})を考え、パラメータをわずかに変えた後の分布P(w|\vec{\theta}+d\vec{\theta})との間の距離D_sを計算する。 \begin{eqnarray} D_s(P(w|\vec{\theta}+d\vec{\theta}),P(w|\vec{\theta})) &=&\int dw\; \left(P(w|\vec{\theta}+d\vec{\theta})-P(w|\vec{\theta})\right) \ln{\frac{P(w|\vec{\theta}+d\vec{\theta})}{P(w|\vec{\theta})}} \\ &=&\int dw\; \delta(w|\vec{\theta}) \ln{\frac{\delta(w|\vec{\theta})+P(w|\vec{\theta})}{P(w|\vec{\theta})}} \label{eq0} \end{eqnarray} ここで、 \begin{equation} \delta(w|\vec{\theta})\equiv P(w|\vec{\theta}+d\vec{\theta})-P(w|\vec{\theta}) \end{equation} と置いた。式(\ref{eq0})は\delta(w|\vec{\theta})が微小量であることに注意すると以下のように変形することができる。 \begin{eqnarray} D_s(P(w|\vec{\theta}+d\vec{\theta}),P(w|\vec{\theta})) &=&\int dw\; \delta(w|\vec{\theta}) \ln{\frac{\delta(w|\vec{\theta})+P(w|\vec{\theta})}{P(w|\vec{\theta})}} \\ &=&\int dw\; \delta(w|\vec{\theta}) \ln{\left(1+\frac{\delta(w|\vec{\theta})}{P(w|\vec{\theta})}\right)} \\ &\simeq&\int dw\; \delta(w|\vec{\theta}) \frac{\delta(w|\vec{\theta})}{P(w|\vec{\theta})} \label{eq1} \end{eqnarray} ところで、\delta(w|\vec{\theta})は次のように計算される。 \begin{eqnarray} \delta(w|\vec{\theta}) &=&P(w|\vec{\theta}+d\vec{\theta})-P(w|\vec{\theta}) \\ &\simeq&\sum_i\;\frac{\partial P(w|\vec{\theta})}{\partial \theta_i} d\theta_i \\ &=&P(w|\vec{\theta})\sum_i\;\frac{\partial\ln{ P(w|\vec{\theta})} }{\partial\theta_i}d\theta_i \end{eqnarray} これを式(\ref{eq1})に代入する。 \begin{eqnarray} D_s(P(w|\vec{\theta}+d\vec{\theta}),P(w|\vec{\theta})) &\simeq& \int dw\; \left[P(w|\vec{\theta})\sum_i\;\frac{\partial\ln{ P(w|\vec{\theta})} }{\partial\theta_i}d\theta_i\right] \frac{P(w|\vec{\theta})\sum_j\;\frac{\partial\ln{ P(w|\vec{\theta})} }{\partial\theta_j}d\theta_j}{P(w|\vec{\theta})} \\ &=& \int dw\; \left[P(w|\vec{\theta})\sum_i\;\frac{\partial\ln{ P(w|\vec{\theta})} }{\partial\theta_i}d\theta_i\right] \sum_j\;\frac{\partial\ln{ P(w|\vec{\theta})} }{\partial\theta_j}d\theta_j \\ &=& \sum_{i,j}\;d\theta_i \left[\int dw\; P(w|\vec{\theta}) \frac{\partial\ln{ P(w|\vec{\theta})} }{\partial\theta_i} \frac{\partial\ln{ P(w|\vec{\theta})} }{\partial\theta_j}\right] d\theta_j \\ &=& \sum_{i,j}\;d\theta_i\; {\bf E}\left[ \frac{\partial\ln{ P(w|\vec{\theta})} }{\partial\theta_i} \frac{\partial\ln{ P(w|\vec{\theta})} }{\partial\theta_j}\right] d\theta_j \end{eqnarray} ここで、{\bf E}[\cdot]は確率P(w|\vec{\theta})の下での期待値を表す。いま \begin{equation} F_{i,j}(\vec{\theta})\equiv {\bf E}\left[ \frac{\partial\ln{ P(w|\vec{\theta})} }{\partial\theta_i} \frac{\partial\ln{ P(w|\vec{\theta})} }{\partial\theta_j}\right] \label{eq4} \end{equation} と置くと \begin{eqnarray} D_s(P(w|\vec{\theta}+d\vec{\theta}),P(w|\vec{\theta})) &\simeq& \sum_{i,j}\;d\theta_i\;F_{i,j}(\vec{\theta})\;d\theta_j\\ &=&d\vec{\theta}^{T}F(\vec{\theta})\;d\vec{\theta} \end{eqnarray} を得る。F(\vec{\theta})をFisher情報行列と呼ぶ。D_sは微小距離の2乗に相当する量である。従って、F(\vec{\theta})は今考えているパラメータ空間(リーマン空間)における計量テンソルと見ることができる。

自然勾配法


 パラメータ\vec{\theta}=(\theta_1,\cdots,\theta_n)の張る空間上の関数f(\vec{\theta})を考える。f(\vec{\theta})の微小変化は次式で与えられる。 \begin{equation} \delta f\equiv f(\vec{\theta}+d\vec{\theta})-f(\vec{\theta})=\vec{\nabla}f^T d\vec{\theta} \end{equation} \delta fが最大となる向きd\vec{\theta}を、\|d\vec{\theta}\|^2=\epsilon^2の条件の下で考える。ここで、\epsilonは微小な定数である。ところで、リーマン空間において 、\|d\vec{\theta}\|^2は計量テンソルG(\vec{\theta})を用いて、次のように書くことができる。 \begin{equation} \|d\vec{\theta}\|^2=d\vec{\theta}^{T}G(\vec{\theta})\;d\vec{\theta} \end{equation} 従って、\delta fが最大となる向きは、Lagrangeの未定乗数法を用いて、次を最大化することで求めることができる。 \begin{equation} L=\vec{\nabla}f^T d\vec{\theta} -\lambda\left(d\vec{\theta}^{T}G(\vec{\theta})\;d\vec{\theta}-\epsilon^2 \right) \end{equation} d\theta_iで偏微分して0と置く。 \begin{equation} \frac{\partial L}{\partial d\theta_i}=\frac{\partial f}{\partial \theta_i}-2\lambda\sum_j\;G_{i,j}(\vec{\theta})d\theta_j=0 \end{equation} これより \begin{equation} \vec{\nabla}f = 2\lambda\;G(\vec{\theta})d\vec{\theta} \end{equation} を得る。d\vec{\theta}について解くと \begin{equation} d\vec{\theta}\propto G^{-1}(\vec{\theta})\vec{\nabla}f \end{equation} を得る。これが微小変化\delta fが最大となる向きである。この向きを利用する勾配法を自然勾配法と呼ぶ。ユークリッド空間の場合はGを単位行列と置けば良い。

方策勾配への適用


 J(\vec{\theta})の勾配を最大にする向きは、先の議論より \begin{equation} d\vec{\theta}\propto F^{-1}(\vec{\theta})\vec{\nabla}_{\theta}J(\vec{\theta}) \label{eq5} \end{equation} で与えられる。ただし、ここでの情報行列F(\vec{\theta})は式(\ref{eq4})のP(w|\vec{\theta})\pi_{\theta}(a|s)に置き換えた次式で定義される。 \begin{equation} F(\vec{\theta})\equiv{\bf E} \left[ \vec{\nabla}_{\theta}\ln{\pi_{\theta}(a|s)} \vec{\nabla}_{\theta}^T\ln{\pi_{\theta}(a|s)} \right] \end{equation} 式(\ref{eq5})に式(\ref{eq2})を代入する。 \begin{equation} d\vec{\theta}\propto F^{-1}(\vec{\theta})\;{\bf E} \left[ \vec{\nabla}_{\theta} \ln{\pi_{\theta}(a|s)}\;Q(s,a) \right] \label{eq3} \end{equation} Q(s,a)をパラメータ\vec{w}を用いた次のモデルで近似することがよく行われる。 \begin{equation} Q(s,a)=\vec{w}^T \vec{\nabla}_{\theta}\ln{\pi_{\theta}(a|s)} \end{equation} これを、式(\ref{eq3})に代入すると \begin{eqnarray} d\vec{\theta} &\propto& F^{-1}(\vec{\theta})\;{\bf E} \left[ \vec{\nabla}_{\theta} \ln{\pi_{\theta}(a|s)}\;\left[\vec{w}^T \vec{\nabla}_{\theta}\ln{\pi_{\theta}(a|s)}\right] \right] \\ &=& F^{-1}(\vec{\theta})\;{\bf E} \left[ \vec{\nabla}_{\theta}\ln{\pi_{\theta}(a|s)} \vec{\nabla}_{\theta}^T\ln{\pi_{\theta}(a|s)} \right] \vec{w}\\ &=& F^{-1}(\vec{\theta})\;F(\vec{\theta})\;\vec{w}\\ &=& \vec{w} \end{eqnarray} を得る。つまり、J(\vec{\theta})を更新する際の\vec{\theta}の向きは、\vec{w}と一致することになる(というより、こうなるようにQ(s,a)を近似するのだろう)。

参考文献