強化學習讀書筆記 - 09 - on-policy預測的近似方法

強化學習讀書筆記 - 09 - on-policy預測的近似方法

參照

須要瞭解強化學習的數學符號,先看看這裏:html

這一章開始了第二部門 - 近似解決方案web

近似方法的重要性

咱們先看看傳統方法中存在的問題:算法

  • 不適用複雜的環境。主要緣由是狀態和行動太多,策略須要大量空間來記憶策略價值。
  • 環境多是不穩定的,過去的經驗不能適用於將來的狀況。須要一個通用性的方法來更新策略價值。
  • 策略價值是一個數值,缺少通用性。指望有一個通用的方法來計算策略價值。

因此對近似預測方法的理解是,找到一個通用的方法\(\hat{v}(s, \theta)\)
數學表示
\[ \hat{v}(s, \theta) \approx v_{\pi}(s) \\ where \\ \theta \text{ - a weight vector} \\ \theta \doteq (\theta_1, \theta_2, ..., \theta_n)^T \]app

解釋
近似預測方法是指求策略的狀態價值的近似值。
求策略的行動狀態價值的近似值叫作近似控制方法(Control Methods)(下一章的內容)。函數

近似預測方法的目標

首先,咱們須要找到一個判斷近似預測方法質量的計算公式。學習

價值均方偏差(Mean Squared Value Error)
\[ MSVE(\theta) = \sum_{s \in \mathcal{S}} d(s) [v_{\pi} - \hat{v}(s, \theta)]^2 \\ where \\ d(s) \text{ - on-policy distribution, the fraction of time spent in s under the target policy } \pi \\ \]lua

  • 在情節性任務中
    \[ \eta(s) = h(s) + \sum_{\bar{s}} \eta(\bar{s}) \sum_{a} \pi(a|\bar{s})p(s|\bar{s}, a), \ \forall s \in \mathcal{S} \\ d(s) = \frac{\eta(s)}{\sum_{s'} \eta(s')} \\ where \\ \eta(s) \text{ - the number of time steps spent in state s in a single episode} \\ h(s) \text{ - time spent in a state s if episodes start in it} \]spa

  • 在連續性任務中
    \[ d(s) = \text{ the stationary distribution under } \pi \\ \]server

解釋:
\(\eta(s) = h(s) + \sum_{\bar{s}} \eta(\bar{s}) \sum_{a} \pi(a|\bar{s})p(s|\bar{s}, a), \ \forall s \in \mathcal{S}\)
狀態s的發生時間(次數) = 在情節中狀態s發生在開始的時間(次數) + 狀態s發生在其它的時間(次數)htm

隨機梯度遞減方法(Stochastic gradient descend method)

那麼如何求\(\theta\)呢?一個常見的方法是經過梯度遞減的方法,迭代的求解\(\theta\)

隨機梯度遞減算法

Stochastic gradient descend
\[ \begin{align} \theta_{t+1} & \doteq \theta_{t} - \frac{1}{2} \alpha \nabla [v_{\pi}(S_t) - \hat{v}(S_t, \theta_t)]^2 \\ & = \theta_{t} + \alpha [v_{\pi}(S_t) - \hat{v}(S_t, \theta_t)] \nabla \hat{v}(S_t, \theta_t) \\ \end{align} \\ where \\ \nabla f(\theta) \doteq \left ( \frac{\partial f(\theta)}{\partial \theta_1}, \frac{\partial f(\theta)}{\partial \theta_2}, \cdots, \frac{\partial f(\theta)}{\partial \theta_n} \right )^T \\ \alpha \text{ - the step size, learning rate} \]

解釋
這個方法能夠在屢次迭代後,讓\(\theta\)最優。
\(v_{\pi}(S_t)\)是實際值。
\(\hat{v}(S_t, \theta_t)\)是當前計算值。
隨機梯度遞減方法經過偏差(實際值 - 當前計算值)接近最優值的方法。
比較麻煩的是:如何求\(\nabla \hat{v}(S_t, \theta_t)\)
傳統的方法是求\(v_{\pi}(s), q_{\pi}(s, a)\),在近似方法中變成了求\(\theta, \hat{v}(s, \theta), \hat{q}(s, a,\theta)\)

蒙特卡洛

  • 算法描述

    Input: the policy \(\pi\) to be evaluated
    Input: a differentiable function \(\hat{v} : \mathcal{S} \times \mathbb{R^n} \to \mathbb{R}\)

    Initialize value-function weights \(\theta\) arbitrarily (e.g. \(\theta = 0\))
    Repeat (for each episode):
      Generate an episode \(S_0, A_0, R_1 ,S_1 ,A_1, \cdots ,R_t ,S_t\) using \(\pi\)
      For \(t = 0, 1, \cdots, T - 1\)
       \(\theta \gets \theta + \alpha [G_t -\hat{v}(S_t, \theta)] \nabla \hat{v}(S_t, \theta)\)

半梯度遞減方法(Semi-gradient method)

之因此叫半梯度遞減的緣由是TD(0)和n-steps TD計算價值的公式不是精確的(而蒙特卡羅方法是精確的)。

半梯度降低(Semi-gradient TD(0))

  • 算法描述

    Input: the policy \(\pi\) to be evaluated
    Input: a differentiable function \(\hat{v} : S^+ \times \mathbb{R^n} \to \mathbb{R}\) such that \(\hat{v}(terminal, \dot \ ) = 0\)

    Initialize value-function weights \(\theta\) arbitrarily (e.g. \(\theta = 0\))
    Repeat (for each episode):
      Initialize \(\mathcal{S}\)
      Repeat (for each step of episode):
       Choose $A \sim \pi(\dot  |S) $
       Take action \(A\), observe \(R, S'\)
       \(\theta \gets \theta + \alpha [R + \gamma \hat{v}(S', \theta) -\hat{v}(S', \theta)] \nabla \hat{v}(S, \theta)\)
       \(S \gets S'\)
      Until \(S'\) is terminal

n-steps TD

請看原書,不作拗述。

特徵選擇

線性方程的定義

\[ \phi(s) \doteq (\phi_1(s), \phi_2(s), \dots, \phi_n(s))^T \\ \hat{v} \doteq \theta^T \phi(s) \doteq \sum_{i=1}^n \theta_i \phi_i(s) \]
\(\phi(s)\)特徵函數
這裏討論特徵函數的通用化定義方法。

多項式基(polynomials basis)

\(s\)的每個維度均可以當作一個特徵。多項式基的方法是使用\(s\)的高維多項式做爲新的特徵。
好比:二維的\(s = (s_1, s_2)\),能夠選擇多項式爲\((1, s_1, s_2, s_1s_2)\)或者\((1, s_1, s_2, s_1s_2, s_1^2, s_2^2, s_1s_2^2, s_1^2s_2, s_1^2s_2^2)\)

多項式基方法的通用數學表達:
\[ \phi_i(s) = \prod_{j=1}^d s_j^{C_{i,j}} \\ where \\ s = (s_1,s_2,\cdots,s_d)^T \\ \phi_i(s) \text{ - polynomials basis function} \]

傅里葉基(Fourier basis)

傅里葉基方法的通用數學表達:
\[ \phi_i(s) = \cos(\pi c^i \dot s), \ s \in [0,1)] \\ where \\ c^i = (x_1^i, c_2^i, \cdots, c_d^i)^T, \ with \ c_j^i \in \{0, \cdots, N\} \ for \ j = 1, \cdots, d \ and \ i = 0, \cdots, (N + 1)^d \]

徑向基(Radial Basis)

徑向基方法的通用數學表達:
\[ \phi_i(s) \doteq exp \left ( - \frac{\lVert s-c_i \rVert ^2 }{2 \sigma_i^2} \right ) \]

最小二乘法TD(Least-Squares TD)

Input: feature representation \(\phi(s) \in \mathbb{R}^n, \forall s \in \mathcal{S}, \phi(terminal) \doteq 0\)

$\hat{A^{-1}} \gets \epsilon^{-1} I \qquad \text{An } n \times n  matrix $
\(\hat{b} \gets 0\)
Repeat (for each episode):
  Initialize S; obtain corresponding \(\phi\)
  Repeat (for each step of episode):
   Choose \(A \sim \pi(\dot \ | S)\)
   Take action \(A\), observer \(R, S'\); obtain corresponding \(\phi'\)
   \(v \gets \hat{A^{-1}}^T (\phi - \gamma \phi')\)
   \(\hat{A^{-1}} \gets \hat{A^{-1}} - (\hat{A^{-1}}\phi) v^T / (1+v^T\phi)\)
   \(\hat{b} \gets \hat{b} + R \phi\)
   \(\theta \gets \hat{A^{-1}} \hat{b}\)
   \(S \gets S'; \phi \gets \phi'\)   until S' is terminal

相關文章
相關標籤/搜索