# Reinforcement Learning : day 1 勉強編 ## Attention これらは全て私の個人的な理解に基づいているので、鵜呑みにしないでください。 These are based on my understanding, so please keep them as a reference only. ## Framework for Reinforcement Learning ![](https://i.imgur.com/jsAcxk1.png) いくつかの強化学習の枠組み(Q-Learning, モンテカルロ法, ... )があるが、それらに共通する枠組みがこれ There are several reinforcement learning (Q-Learning, Monte Carlo, ... ), but their common framework is this. ## "Learning" in Reinforcement Learning おそらく全ての強化学習における共通の学習とは「**ある状態$s^{(t)}$における行動$a^{(t)}$の"価値$Q$"を学習すること**」である。 勿論、状態$s^{(t)}$における最適な行動$a^{(t)}$をとるようなPolicyを獲得することを目的とした学習はあるが、それは上記の学習に内包される(と、理解する方が一般的な気がする)。 例えば、Policyが完全にランダムな場合は、そもそも最適な行動を決定することはできない。しかし、与えられた条件下(Environment)におけるあらゆる状態の価値$Q$を学習することは可能である。 Common learning in all reinforcement learning is learning the value $Q$ of an action $a^{(t)}$ in a state $s^{(t)}$. Of course, there is a learning process aimed at acquiring policies for "Best" action in a state, but it is included in the above learning. For example, if Policy is completely random, the agent cannot act in the best way. But learning the value $Q$ of all states under a given Environment is possible. ## The relationship between Time $t$ and State $s$ マルコフ決定過程(Markov decision process: MDP)を前提としている。 難しく書いているが、要は、次の状態$s^{(t+1)}$への遷移は、現在の状態$s^{(t)}$と行動$a^{(t)}$のみに依存し、それ以前の状態$\{s^{(t-1)}, ..., s^{(1)}, s^{(0)}\}$や行動$\{a^{(t-1)}, ..., a^{(1)}, a^{(0)}\}$とは依存しない。 It is based on the Markov decision process (MDP). The point is that the next state $s^{(t+1)}$ depends only on the current state $s^{(t)}$ and action $a^{(t)}$. ## About Value $Q$ and Reward $R$ ![](https://i.imgur.com/sdFKrXY.png) [引用元](https://qiita.com/Hironsan/items/56f6c0b2f4cfd28dd906) 例えば、このロボットは次の行動を取ることで即時報酬$R$を得られたとする。      0      ↑ 0.1←   → 0      ↓     0.1 さらに、宝箱までたどり着くと+1の即時報酬$R$がもらえる これはある瞬間の行動の結果、即時報酬$R$がなかったとしても、↑や→の行動を続けて宝箱まで辿りついたほうが、未来に渡って得られる合計報酬$\sum_t R^{(t)}$は大きくなる。 価値$Q$とは、未来の報酬も含まれたある状態である行動を取ることによる期待値(のようなもの)を指す。 For example, suppose that this robot gets an immediate reward $R$ for taking the following actions.      0      ↑ 0.1←   → 0      ↓     0.1 If robot reach the treasure mass, he get an immediate reward $R$ +1. This means that even if there is no immediate reward as a result of an action , the total reward $\sum_t R^{(t)}$ he get over the future will be greater if he continues to perform the ↑ and → actions and reach the treasure mass. ## Q Value 一般的に、状態sと行動aに依存する$Q$値は、それらのマトリクスで表現されることが多い。 仮に、ここではQ-table と呼ぶ。 | | 行動$a_1$ | 行動$a_2$ | ... | 行動$a_N$ | | -------- | -------- | -------- | -------- | -------- | | 状態$s_1$ | 1.1|0.3 | | 3| | 状態$s_2$ | 0.4| 2.2| | 0.2| | ... | | | | | | 状態$s_M$ |2.3 | 3| | 4| ## Q-Learning ![](https://i.imgur.com/WBSm2bh.png) [参考](https://www.tcom242242.net/entry/ai-2/%E5%BC%B7%E5%8C%96%E5%AD%A6%E7%BF%92/%E3%80%90%E5%BC%B7%E5%8C%96%E5%AD%A6%E7%BF%92%E3%80%81%E5%85%A5%E9%96%80%E3%80%91q%E5%AD%A6%E7%BF%92_%E8%BF%B7%E8%B7%AF%E3%82%92%E4%BE%8B%E3%81%AB/) 強化学習とは、Q-table の値を学習していくことである。 Q-Learning もその学習方法のひとつ。 他にもモンテカルロ法や、Sarsa という手法がある。[参考](https://blog.brainpad.co.jp/entry/2017/02/24/121500)