JayRobotics

[오승상 강화학습] 03. Markov Decision Process

1. Markov Decision Process (MDP)

Markov Decision Process
Markov Decision Process

1-1. Markov process

  • {St}\lbrace S_t \rbrace : Markov property를 만족하는 Stochastic process (collection of random variables, S0, S1, … , St−1, St, St+1S_0, \ S_1, \ \dots \ , \ S_{t-1}, \ S_{t}, \ S_{t+1})
  • Markov process is a tuple (S, P)(S, \ P)
    • SS : a (finite) set of states
    • PP : state transition probability Pij=p(sj∣si)=P(St+1=sj∣St=si)P_{ij}=p(s_j|s_i)=P(S_{t+1}=s_j|S_t=s_i)

1-2. Markov Decision Process

  • MDP 이론은 SS와 AA가 반드시 finite할 것을 요구하지 않는다.
  • 즉, state space와 action space는 continuous할 수도 있다.
  • MDP는 모든 state가 Markov property를 갖는 tuple (S,A,P,R,γ)(S, A, P, R, \gamma)이다.
구성 요소의미
SSstate space
AAaction space
PPtransition probability
RRreward function
γ∈[0,1]\gamma \in [0, 1]discount factor (할인율, 0과 1 사이에 존재하는 실수값)
PP : Transition probability
  • PP는 current state St=sS_t=s에서 어떤 action At=aA_t=a를 선택했을 때, next state가 St+1=s′S_{t+1}=s^{\prime}이 될 확률을 의미한다.
Pss′a=p(s′∣s,a)=P(St+1=s′∣St=s,At=a)P_{ss^{\prime}}^a = p(s^{\prime} \mid s, a) = P(S_{t+1}=s^{\prime} \mid S_t=s, A_t=a)
RR : Reward function
  • RR은 current state St=sS_t=s에서 어떤 action At=aA_t=a를 취해 next state St+1=s′S_{t+1}=s^{\prime}로 전이될 때 받는 reward이다.
3가지 reward type

| RsR_{s} | 현재 state에 대한 reward | | RsaR^{a}_{s} | 현재 state St=sS_t=s 에서 어떤 action At=aA_t=a 를 취했을 때 얻는 reward | | Rss′aR^{a}_{ss^{\prime}} | 현재 state St=sS_t = s 에서 어떤 action At=aA_t=a 를 취해서 St+1=s′S_{t+1}=s^{\prime} 로 전이될 때 얻는 reward |

1-3. MDP model example

해당 모델에서는 γ\gamma (할인률)을 고려하지 않는다.

state diagram 1
state diagram 1
State space
  • 3개의 state를 가진다. ( S0, S1, S2S_0, \ S_1, \ S_2)
Action space
  • 2 종류의 action을 가진다. ( a0, a1a_0, \ a_1)
Reward function
  • 2 종류의 reward를 가진다. ( +1, −1+1, \ -1 )
Transition probability example
Ps0s1a1=p(s1∣s0, a1)=P(St+1=s1∣St=s, At=a1)=0.3P^{a_1}_{s_0 s_1} = p(s_1|s_0, \ a_1)=P(S_{t+1}=s_1|S_t=s, \ A_t=a_1) = 0.3
state diagram 2
state diagram 2
Reward function example
Rs1s2a1=+1R^{a_1}_{s_1 s_2} = +1
state diagram 3
state diagram 3

1-4. Model-based

  • transition probability PP 와 reward function RR 을 알고 있을때 MDP
  • model을 알고 있으므로 model 기반 문제 해결이 가능
  • e.g. Dynamic programming (방대한 확률 문제를 세분화 시켜서 효율적으로 해결)

1-5. Model-free

  • transition probability를 모를 때 MDP
  • transition probability를 추정하지 않고, 경험(sample data)으로부터 value/Q 값을 직접 추정
  • e.g. Reinforcement Learning (Q-learning, SARSA, DQN 등)

2. MDP in grid world

해당 모델에서는 γ\gamma (할인률)을 고려하지 않는다.

MDP in grid world
MDP in grid world

2-1. State set

  • S={(1,1), (1,2), (1,3), … , (4,2), (4,3)}S = \lbrace (1,1), \ (1,2), \ (1,3), \ \dots \ , \ (4,2), \ (4,3) \rbrace

2-2. Action set

  • A={north, south, east, west}A =\lbrace north, \ south, \ east, \ west \rbrace

2-3. State transition probability

P(3,1)(3,2)north=0.8, P(3,1)(2,1)north=0.1, P(3,1)(4,1)north=0.1P^{north}_{(3,1)(3,2)} = 0.8, \ P^{north}_{(3,1)(2,1)} = 0.1, \ P^{north}_{(3,1)(4,1)} = 0.1
  • Stochastic grid world 사용
  • St=9S_t = 9 가지, At=A_t = 4 가지, St+1=S_{t+1} = 11 가지 ⇒ 총 396 가지 transition probability가 나오게 된다.

2-4. Big reward

  • R(3,3)→(4,3)east=+1R^{\mathrm{east}}_{(3,3)\to(4,3)} = +1 : (4,3)(4,3) 위치에서 마치게 되면 승점 +1+1

  • R(3,2)→(4,2)north=−1R^{\mathrm{north}}_{(3,2)\to(4,2)} = -1 : (4,2)(4,2) 위치에서 마치게 되면 벌점 −1-1

  • R(4,1)→(4,2)north=−1R^{\mathrm{north}}_{(4,1)\to(4,2)} = -1 : (4,2)(4,2) 위치에서 마치게 되면 벌점 −1-1

2-5. Small negative reward

  • Rss′aR^{a}_{s s^{\prime}} : 한 번 action을 취할 때 마다 소량의 감점(cc) 부여
  • 의미없는 action을 줄이고, 게임이 길어지는 것을 방지하기 위해서 필요하다.

3. Optimal policy in grid world

  • 아래 사진의 경우, cc (small negative reward) 값을 각각 다르게 하였을 때의 결과로 4가지 케이스는 모두 다른 MDP model 이다.
optimal policy in grid world
optimal policy in grid world

3-1. Deterministic policy

π:S→A,           a=π(s)\pi : S \rightarrow A, \ \ \ \ \ \ \ \ \ \ \ a = \pi(s)
  • 각 state 마다 action을 선택하는 방법

3-2. Stochastic policy

π(a ∣ s)=P(At=a ∣ St=s)\pi(a \ | \ s) = P(A_t=a \ | \ S_t=s)
  • 각 state 마다 action의 확률분포를 부여하는 방법
  • e.g. north(80%), east(10%), west(10%)
  • 위 Grid world example에서는 stochasric policy를 적용한다.

3-3. Expected total reward

optimal policy in grid world 2
optimal policy in grid world 2

Episode

  • 시작 상태 에서 출발하여 종료 상태(terminal state)에 도달할 때까지의 한 번의 완결된 경험
  • policy가 정해져 있다고 하더라도, episode는 여러 개가 나올 수 있다.
  • **초록색 episode**의 total reward : 4c+1=4⋅(−0.4)+1=−0.64c+1 = 4\cdot(-0.4)+1=-0.6
  • **파란색 episode**의 total reward : 3c−1=3⋅(−0.4)−1=−2.23c-1=3 \cdot(-0.4)-1=-2.2

policy 성능 평가 방법

  • policy를 평가하기 위해 한 episode가 종료된 후 total reward를 계산하게 된다.
  • 이때, 일반적으로는 stochastic policy를 사용하는데, 이 경우 하나의 policy에 대해서도 여러 개의 episode가 나올 수 있다.
  • 따라서, **모든 episode에 대한 total reward의 expectation(기대값)을 계산함**으로써 policy를 평가하게 된다.

3-4. Optimal policy

π∗(a ∣ s)\pi_*(a \ | \ s)
  • Optimal policy란, expected total reward를 maximize하는 policy
  • 즉, 평균적으로 가장 좋은 reward를 받는 policy를 설정하는 것이다.
  • Optimal policy는 Dynamic programming 이나 Reinforcement Learning에서 찾고자 하는 목표이다.

3-5. MDP의 궁극적인 목표

  • Optimal policy( π∗\pi_*)를 찾는 것

References

고려대 오승상 강화학습 03 Markov Decision Process