Policy Evaluation

Download Report

Transcript Policy Evaluation

INC 637 Artificial
Intelligence
Lecture 13
Reinforcement Learning (RL)
(continue)
Reinforcement Learning
Value Table
Action
State
3
2
 
  3
 
2
4
 
 22 
3
 
 4 
State Value Table
1 dimension
(V-table)
2
4
3
 7 66 9

 4 43  7

State  9 45 3
6
4
6

7
8
5
 :
:
:

6
4
 7
7
7
5
8
7
9
:
8
6 4
3
4 3 9
3 11 54
6 4
8
0 8 56
5 46 8
:
:
:
9 6 6
6
7 
6

5
4

5
:

4
Action Value Table
2 dimension
(Q-table)
Bellman Equation for a Policy p
คำนวณหำ Value Function จำก policy π
Rt  rt 1   rt 2   2 rt  3   3 rt  4
 rt 1   rt 2   rt 3   rt  4

2
 rt 1   Rt 1
So:
V p (s)  Ep Rt st  s
 Ep rt 1   V st 1  st  s
Or, without the expectation operator:
V (s)   p (s,a) PssRss   V ( s)
p
a
a
s
a
p
Bellman Optimality Equation for V*
The value of a state under an optimal policy must equal
the expected return for the best action from that state:
p

V (s)  max Q (s,a)
aA(s)
 max Ert 1   V  (st 1 ) st  s, at  a
aA(s)
 max  PsasRsas   V  (s)
aA(s)
s 
3 Methods to find V*
• Dynamic Programming
• Monte Carlo
• Temporal Difference
Dynamic Programming
ประกอบด้ วยขบวนกำรหลัก 2 ส่ วน
Policy Evaluation
Policy Improvement
Policy Evaluation
p
Be ll man e qu ati on for
V :
V (s)   p (s,a) PssRss   V ( s)
p
a
a
a
p
s 
— a system ofS sim ultaneous linear equat ions
แต่ ละ state มีสมกำรของตัวเองซึ่งขืน้ กับ value function ของ next state
เป็ นสมกำร linear หลำยตัวแปร
อย่ ำงไรก็ตำม ก็ยงั ยำกทีจ่ ะแก้ สมกำรถ้ ำมีหลำยๆ state
Iterative Policy Evaluation
V0  V1 
 Vk  Vk 1 
V
p
a “sweep”
A sweep consists of applying a backup operation to each state.
ตือใช้ value function จำก อันก่ อนมำประมำณอันปัจจุบนั
A full policy evaluation backup:
Vk 1 (s)   p (s,a) PssRss   Vk (s)
a
a
s
a
Example
Terminal state
Terminal state
• Undiscounted episodic task
• Actions that would take agent off the grid
leave state unchanged
• Reward is –1 for every action until the
terminal state is reached
(0.25(-1+0.0) + 0.25(-1-1.0) + 0.25(-1-1.0) + 0.25(-1-1.0)
Policy Improvement
สำมำรถทำได้ จำก value function ทีค่ ำนวณได้ มำโดยปรับ
ให้ ไปเลือก action ทีม่ ี value function สู งสุ ด
p(s)  argmaxQp (s,a)
a
 argmax  Psas Rsas    V p (s)
a
s 
เรียกว่ ำเป็ น greedy actions
Then V p   V p
What ifVp  Vp ?
i.e., for alls S, V p(s)  max PsasRsas   Vp (s ) ?
a
s
But this is the Bellm an Opt imality Equat ion.
So V p  V  and bot hp and pare opt imal policies.
Iterative Policy Improvement
p0  V
p0
p1
 p1  V 
policy evaluation
p V p
*
*
policy improvement
“greedification”
กำร estimate ค่ ำ value function โดยใช้ ค่ำ estimate
ของมันเองเรียก Bootstrapping
*
Dynamic Programming
Monte Carlo Method
Dynamic Programming ต้ องรู้ world model
นั่นคือมี reward เท่ ำใด ทีไ่ หมบ้ ำง และ next state เป็ นอะไร
Monte Carlo จะไม่ ต้องรู้ world model มำก่ อน
คุณสมบัติของ Monte Carlo
• ใช้ ได้ กบั episodic tasks เท่ ำนั้น
• learn จำก ประสบกำรณ์ จริงโดยใช้ complete returned reward
Monte Carlo Policy Evaluation
• Goal: learn Vp(s)
• Given: some number of episodes under p
which contain s
• Idea: Average returns observed after visits to s
1
2
3
4
5
• Every-Visit MC: average returns for every time s is
visited in an episode
• First-visit MC: average returns only for first time s
is visited in an episode
• Both converge asymptotically
Backup Diagram of MC
• Entire episode included
• Only one choice at each
state (unlike DP)
s1
a1
s2
a2
• MC does not bootstrap
s3
a3
• Time required to
estimate one state does
not depend on the total
number of states
Series of
actions
Monte Carlo Policy Iteration
Qp k (s, p k 1 (s))  Qp k (s,argmaxQp k (s,a))
a
 maxQp k (s,a)
a
pk
 Q (s,p k (s))
pk
 V (s)
Policy Improvement
Example: Blackjack
• Object: Have your card sum be greater than
the dealers without exceeding 21.
• States (200 of them):
– current sum (12-21)
– dealer’s showing card (ace-10)
– do I have a useable ace?
• Reward: +1 for winning, 0 for a draw, -1 for
losing
• Actions: stick (stop receiving cards), hit
(receive another card)
• Policy: Stick if my sum is 20 or 21, else hit
เช่ นในสถำนะกำรหนึ่งไม่ มี usable ace และ เจ้ ำมือ show 8
เรำเริ่มต้ นที่ แต้ ม = 12 จั่วได้ เป็ น 14 และ 18 แล้ วดูผลว่ ำแพ้ หรือชนะ
จะนำค่ ำผลลัพธืทไี่ ด้ มำ update state ที่ 12, 14, 18 นี้
ทำไปหลำยหมืน่ ครั้งจะได้ กรำฟของทุก state ดังรูป
Temporal Difference (TD)
Policy Evaluation (the prediction problem):
p
for a given policy p, compute the state-value function V
Recall:
Simple every- visit Mont e Carlomethod:
V(st )  V(st )   Rt  V (st )
target: the actual return after time t
T he simplest T D method,
T D(0):
V(st )  V(st )   rt 1   V (st1 )  V(st )
target: an estimate of the return
Simple Monte Carlo
V(st )  V(st )   Rt  V (st )
where Rt is the actual return following st ate
st .
st
T
T
T
TT
T
TT
T
TT
T
TT
T
Simplest TD Method
V(st )  V(st )   rt 1   V (st1 )  V(st )
st
rt 1
s t 1
TT
T
T
T
TT
T
T
TT
T
TT
T
Dynamic Programming
V(st )  Ep rt 1   V(st )
st
rt 1
T
TT
TT
T
T
T
T
T
T
s t 1
T
TD Bootstraps and Samples
• Bootstrapping: update involves an
estimate
– MC does not bootstrap
– DP bootstraps
– TD bootstraps
• Sampling: update does not involve
an expected value
– MC samples
– DP does not sample
– TD samples
Learning an Action-Value Function
Est im at eQp for the current behavior policy
p.
After every transit ion from a nonterminal st
st ,atdo
e t his:
Qst , at   Qst , at    rt 1   Qst 1 ,at 1   Qst ,at 
If st 1 is term inal,t henQ(st 1, at 1 )  0.
Sarsa: On-Policy TD
ทีเ่ ป็ น on-policy เพรำะต้ องทำ action ก่ อนเพือ่ ให้ ได้ next state
แล้ วค่ อยนำมำ update value table
Q-learning Off-Policy TD
One- step Q- learning:


Qst , at   Qst , at    rt 1   maxQst1 , a  Qst , at 
a
ทีเ่ ป็ น off-policy เพรำะไม่ ต้องทำตำม next state ทีจ่ ะเลือกเอำ
action ทีไ่ ด้ reward สู งสุ ด
Current state
  0.9
Action
ไปทำงขวำ
Next state