Planning and Learning

這算是一篇綜述性文章,講的不深,但是可以瞭解做planning都有哪些方法。這篇文章裏全部使用了Q的說法,因爲實現上可能是網絡DQN,也可以是經典的Table。

Models and Planning

Models指的是Environment Models,可以分爲兩大類:

  1. 當前狀態和採取的動作作爲輸入,輸出下一個所有可能狀態和獎勵的分佈
  2. 當前狀態和採取的動作作爲輸入,輸出下一個狀態和獎勵

Planning則是指對模型的合理使用,指定使用模型的"策略"(跟policy區分開,使用策略的意思),用最低的成本收斂到價值函數。

Dyna-Q: Integrating Planning, Acting, and Learning

如果能有完美的環境模型,就可以使用類似動態規劃那樣的planning方法來更快更好地收斂Q,但是實際上由於各種各樣的原因,我們手上的模型可能沒有那麼完美。

於是乎,是不是可以先學出個差不多的環境模型,然後使用這個環境模型來學習Q?這當然可以,而且學到的Q也能用於優化策略從而生成更好的樣本,然後更新環境模型和Q,這樣持續的迭代下去。這樣我們就有了兩種更新Q的方式:

  1. 通過真實經驗學到的環境模型生成的模擬樣本更新
  2. 直接通過真實經驗更新

這個過程可以描述爲:
在這裏插入圖片描述

Tabular Dyna-Q

1: InitializeQ(s,a)1:\ Initialize Q(s,a) and Model(s,a)Model(s,a) for all sSs \in S and aA(s)a \in A(s)
2: Do forever2:\ Do \ forever:
3: (a) S3:\ \qquad (a) \ S \leftarrow current (nonterminal) state
4: (b) Aϵ4:\ \qquad (b) \ A \leftarrow \epsilon-greedy (S,Q)(S,Q)
5: (c) Execute5:\ \qquad (c) \ Execute action AA, observe resultant reward RR and next state SS'
6: (d) Q(S,A)Q(S,A)+α[R+γmaxaQ(S,a)Q(S,A)]6:\ \qquad (d) \ Q(S,A) \leftarrow Q(S,A) + \alpha[R+\gamma max_aQ(S',a)-Q(S,A)]
7: (e)Model(S,A)R,S7:\ \qquad (e) Model(S,A) \leftarrow R,S'(assuming deterministic environment)
8: (f)Repeat n8:\ \qquad (f) Repeat \ n times:
9: S9:\ \qquad \qquad S \leftarrow random previously observed state
10:A10: \qquad \qquad A \leftarrowrandom action previously taken in SS
11:R,SModel(S,A)11: \qquad \qquad R,S' \leftarrow Model(S,A)
12:Q(S,A)Q(S,A)+α[R+γmaxaQ(S,a)Q(S,A)]12: \qquad \qquad Q(S,A) \leftarrow Q(S,A) + \alpha[R+\gamma max_aQ(S',a)-Q(S,A)]

算法裏寫的AA指代整個動作集合,實際運作時只會執行aaSSSS'同理。原算法這樣給的,我也不敢隨便改。

算法裏plannaing步驟中,

算法可以使用下面這張圖描述:
在這裏插入圖片描述

Prioritized Sweeping

前面的Planning搜索是隨機的,見算法DynaQDyna-Q第9行,第10行。下面要講的優先掃除算法加入了優先隊列,每次把變化最大的臨近4個(可以單步直接到達)加進去,與廣度優先搜索求最短路徑有相似地方。

我覺得其實是貪心算法+beam search,維持search窗口大小爲4,窗口大小對結果肯定有影響,所以實際做的時候可以嘗試改變這個4.
Prioritized sweeping for a deterministic environment

1: InitializeQ(s,a), Model(s,a)1:\ Initialize Q(s,a), \ Model(s,a), for all s,as,a and PQueuePQueue to empty
2: Do forever:2:\ Do \ forever::
3: (a)S3:\ \qquad (a) S \leftarrow current (nonterminal) state
4: (b)Apolicy4:\ \qquad (b) A \leftarrow policy(S,Q)
5: (c)Execute5:\ \qquad (c) Execute action AA; observe resultant reward, RR, and state, SS'
6: (d)Model(S,A)R,S6:\ \qquad (d) Model(S,A) \leftarrow R,S'
7: (e)PR+γmaxaQ(S,a)Q(S,A).7:\ \qquad (e) P \leftarrow |R + \gamma max_a Q(S',a) - Q(S,A)|.
8: (f)if P>θ, then8:\ \qquad (f) if \ P > \theta, \ then insert S,AS,A into PQueue with priority PP
9: (g) Repeat n9:\ \qquad (g) \ Repeat \ n times, while PQueue is not empty:
10: S,A10:\ \qquad \qquad S,A \leftarrow into PQueuePQueue with priority PP
11:R,SModel(S,A)11: \qquad \qquad R,S' \leftarrow Model(S,A)
12:Q(S,A)Q(S,A)+α[R+γmaxaQ(S,a)Q(S,A)]12: \qquad \qquad Q(S,A) \leftarrow Q(S,A) + \alpha[R+\gamma max_a Q(S',a)-Q(S,A)]
13:Repeat, for all S,A13: \qquad \qquad Repeat, \ for \ all \ \overline{S},\overline{A} predicted to lead S:
14:R14: \qquad \qquad \qquad \overline{R} \leftarrow predicted reward for S\overline{S},A\overline{A},SS
15:PR+γmaxaQ(S,a)QS,A.15: \qquad \qquad \qquad P \leftarrow |\overline{R} + \gamma max_a Q(S,a) - Q(\overline{S}, \overline{A}|.
16:if P>θ then16: \qquad \qquad \qquad if \ P > \theta \ then insert S\overline{S}, A\overline{A} into PQueuePQueue with priority PP

Trajectory Sampling

動態規劃中不計算所有的節點,而是選擇重要的進行更新。

Heuristic Search

在選擇action時,通過一定深度的搜索得到最好的路徑。這種方法在Model準確但是Q不準確的條件下可用。
在這裏插入圖片描述

Rollout Algorithms

As explained by Tesauro and Galperin (1997), who experimented with rollout algorithms for playing backgammon, the term rollout “comes from estimating the value of a backgammon position by playing out, i.e., rolling out,” the position many times to the game’s end with randomly generated sequences of dice rolls, where the moves of both players are made by some xed policy.

Rollout算法是決策時規劃算法,它基於Monte Carlo Control(Model-Free Control裏有一個小節的介紹),應用於從當前環境狀態中採樣跡(trajectories)。通過在大量從任何一個可能的動作上開始然後遵循策略的模擬跡上取平均來評估一個給定策略的動作價值。當動作-價值估計被認爲是足夠準確的時候,最高估計值的動作(或者動作集中的一個)被執行,然後在下一個狀態重複該過程。

Monte Carlo Tree Search

蒙特·卡羅爾樹搜索(MCTS)是一個最近的並且特別成功的決策時planning的例子。

蒙特·卡羅爾樹搜索和Rollout算法類似,但是不是隨機搜索而是有"指導"的搜索,目的是爲了更大概率地獲得更好的路徑。

MCTS也是Alpha Go核心技術之一,同時不侷限於棋類搜索,所有的可以進行多不高效模擬的問題都可以使用這個方法。

MCTS並不是每次都從當前狀態開始搜索,而是會利用以前搜索到的以當前狀態爲開始狀態的高分路徑作爲候選。

MCTS可以分爲如下圖所示的四個步驟:
在這裏插入圖片描述
有三個注意點:

  • backup之後,rollout的路徑不更新價值函數,只更新selection和expansion的路徑
  • 上面四個步驟將按序循環執行,直到時間耗盡或者找不到新的狀態
  • 並不是每次搜索都從當前節點開始,而是會服用出現過的當前節點的樹結構
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章