深度強化學習 Ch3.1 : TD learning
1. 簡介
TD-learning (Temporal-Difference Learning) 是強化學習中很重要的方法類
旗下延伸包含了許多不同的演算法,像 Q-learning、 Sarsa 等。
此方法結合了 [蒙地卡羅方法] 和 [動態規劃] 兩種想法誕生,
因為動態規劃通常會需要一個規律模型,但在強化學習中有太多不確定情況,無法直接取得模型
所以使用了蒙地卡羅方法來做不停地嘗試尋找規律來得出模型。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
動態規劃簡介
動態規劃可以將一個問題分解成許多子問題,並找出其解決規律模型
ex : 解階層問題 可以寫成
如果將它進行動態規劃可以發現
最後可以得到
所以要解決階層問題就不用重算一遍,把之前的 值拿出來用就好了
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
蒙地卡羅方法簡介
蒙地卡羅方法在這邊也可以理解為[試誤學習]
也就是大量的嘗試,在錯誤中學習規律
TD learning 是由以下元素組成 :
- TD Target : 要學習的目標,會希望動作價值函數 Q 可以近似此目標
- TD error : 與 Target 的差距
- Update : 更新 Q 值,也就是演算法本身
TD learning 又分成兩類型
- On Policy : 會從資料當中學習到同一種策略(),再進行改進 ex : Sarsa( 為 貪婪策略)
- off Policy : 沒有固定策略,會利用學習到的經驗根據當前狀態推斷出動作的價值,
也就是其學習到的策略是獨立於訓練資料 ex : Q-learning
2. Sarsa 演算法
Sarsa 是 on-Policy 的 TD learning 經典演算法,使用當前回報和下一時刻的估計來計算目標
(1). TD target
動作價值函數 Q 反映了 [ 動作,狀態對 ] 的價值,TD target 就是要估計下一時刻的 Q
並讓現在的 Q 近似預測的 Q,找出預測的 Q 叫做 Target
TD target :
- : 當前動作得到的 reward
- , : State, Action
- : 動作價值函數
解釋 : TD target 就是之後要學習近似的目標
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
數學推導
數學推導 :
-
因為要計算未來 Q ,先整理一下 (Return)
-
計算動作價值函數
-
後方的 雖然做過期望了,但是 是對 執行,
剩下的 還是未知所以還可放進 中求期望
-
但要直接求出此期望太過困難(能直接求就不用近似啦!),所以使用蒙地卡羅近似求期望
(2). TD Error
TD error 其實只是 Q 與 TD target 的差距
(3). Update
這個步驟會更新 ,用當前 減去 error 做更動
通常演算法會直接用此式表示
- : 學習率
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
在最左邊的 是指更新後的 Q,其餘右邊的 是當前 Q
整個 Sarsa 可以下圖結構表示 (利用未來預測 Q 來影響更新當前 Q)
當 Q 更新越來越大,回饋也就提升。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
3. Q-Learning
Q-learning 與 Sarsa 的原理非常相似,只差在未來選擇動作 時
Sarsa 只有一種選擇策略並做出一動作,
而 Q learning 會選出多個動作,並挑出其中 Q 值最大的動作
(1). TD target
TD target :
- : 當前動作得到的 reward
- : 未來的 State
- : 動作空間
- : 最大動作價值函數
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
數學推導
數學推導 :
-
前面步驟都與 Sarsa 相同,得到此式
-
因為要求多個 action 下的 max 值
-
動作 會取得最大回饋,可以寫成以下公式
-
接著代換 公式
-
使用蒙地卡羅近似求期望
(2). TD Error
(3). Update
- : 學習率
- : 未來狀態預測出的最大動作價值
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
在最左邊的 是指更新後的 Q,其餘右邊的 是當前 Q
下圖為 Q-learning 結構,可以看到每使用策略()找出多個 action 後
再用貪婪策略選出有最大 Q 的動作,利用此期望回饋影響當前 Q
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Reference