強化學習讀書筆記 - 09 - on-policy預測的近似方法
參照
- Reinforcement Learning: An Introduction, Richard S. Sutton and Andrew G. Barto c 2014, 2015, 2016
- 強化學習讀書筆記 - 00 - 術語和數學符號
- 強化學習讀書筆記 - 01 - 強化學習的問題
- 強化學習讀書筆記 - 02 - 多臂老O虎O機問題
- 強化學習讀書筆記 - 03 - 有限馬爾科夫決策過程
- 強化學習讀書筆記 - 04 - 動態規划
- 強化學習讀書筆記 - 05 - 蒙特卡洛方法(Monte Carlo Methods)
- 強化學習讀書筆記 - 06~07 - 時序差分學習(Temporal-Difference Learning)
- 強化學習讀書筆記 - 08 - 規划式方法和學習式方法
需要了解強化學習的數學符號,先看看這里:
這一章開始了第二部門 - 近似解決方案
近似方法的重要性
我們先看看傳統方法中存在的問題:
- 不適用復雜的環境。主要原因是狀態和行動太多,策略需要大量空間來記憶策略價值。
- 環境可能是不穩定的,過去的經驗不能適用於未來的情況。需要一個通用性的方法來更新策略價值。
- 策略價值是一個數值,缺乏通用性。期望有一個通用的方法來計算策略價值。
所以對近似預測方法的理解是,找到一個通用的方法\(\hat{v}(s, \theta)\)。
數學表示
解釋
近似預測方法是指求策略的狀態價值的近似值。
求策略的行動狀態價值的近似值叫做近似控制方法(Control Methods)(下一章的內容)。
近似預測方法的目標
首先,我們需要找到一個判斷近似預測方法質量的計算公式。
價值均方誤差(Mean Squared Value Error)
- 在情節性任務中
- 在連續性任務中
解釋:
\(\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發生在其它的時間(次數)
隨機梯度遞減方法(Stochastic gradient descend method)
那么如何求\(\theta\)呢?一個常見的方法是通過梯度遞減的方法,迭代的求解\(\theta\)。
隨機梯度遞減算法
Stochastic gradient descend
解釋
這個方法可以在多次迭代后,讓\(\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)\) 為特征函數。
這里討論特征函數的通用化定義方法。
多項式基(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)\)
多項式基方法的通用數學表達:
傅里葉基(Fourier basis)
傅里葉基方法的通用數學表達:
徑向基(Radial Basis)
徑向基方法的通用數學表達:
最小二乘法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