lecture 12: batch rl - stanford university€¦ · empirical results: digital marketing 0.002715...

78
Lecture 12: Batch RL Emma Brunskill CS234 Reinforcement Learning. Winter 2018 Slides drawn from Philip Thomas with modifications Emma Brunskill (CS234 Reinforcement Learning. ) Lecture 12: Batch RL Winter 2018 Slides drawn from Philip Tho / 68

Upload: others

Post on 17-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Lecture 12: Batch RL

Emma Brunskill

CS234 Reinforcement Learning.

Winter 2018Slides drawn from Philip Thomas with modifications

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 1

/ 68

Page 2: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Class Structure

• Last time: Fast Reinforcement Learning / Exploration and Exploitation• This time: Batch RL• Next time: Monte Carlo Tree Search

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 2

/ 68

Page 3: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Table of Contents

1 What makes an RL algorithm safe?

2 Notation

3 Create a safe batch reinforement learning algorithmOff-policy policy evaluation (OPE)High-confidence off-policy policy evaluation (HCOPE)Safe policy improvement (SPI)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 3

/ 68

Page 4: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

What does it mean to for a reinforcement learning algorithmto be safe?

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 4

/ 68

Page 5: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 5

/ 68

Page 6: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 6

/ 68

Page 7: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Changing the objective

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 7

/ 68

Page 8: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Changing the objective

• Policy 1:• Reward = 0 with probability 0.999999• Reward = 109 with probability 1-0.999999• Expected reward approximately 1000

• Policy 2:• Reward = 999 with probability 0.5• Reward = 1000 with probability 0.5• Expected reward 999.5

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 8

/ 68

Page 9: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Another notion of safety

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 9

/ 68

Page 10: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Another notion of safety (Munos et. al)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 10

/ 68

Page 11: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Another notion of safety

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 11

/ 68

Page 12: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 12

/ 68

Page 13: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

The Problem

• If you apply an existing method, do you have confidence that it willwork?

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 13

/ 68

Page 14: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Reinforcement learning success

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 14

/ 68

Page 15: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

A property of many real applications

• Deploying "bad" policies can be costly or dangerous

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 15

/ 68

Page 16: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Deploying bad policies can be costly

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 16

/ 68

Page 17: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Deploying bad policies can be dangerous

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 17

/ 68

Page 18: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

What property should a safe batch reinforcement learningalgorithm have?

• Given past experience from current policy/policies, produce a new policy• “Guarantee that with probability at least 1− δ, will not change

your policy to one that is worse than the current policy.”• You get to choose δ• Guarantee not contingent on the tuning of any hyperparameters

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 18

/ 68

Page 19: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Table of Contents

1 What makes an RL algorithm safe?

2 Notation

3 Create a safe batch reinforement learning algorithmOff-policy policy evaluation (OPE)High-confidence off-policy policy evaluation (HCOPE)Safe policy improvement (SPI)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 19

/ 68

Page 20: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Notation

• Policy π: π(a) = P(at = a∣∣ st = s)

• History: H = (s1, a1, r1, s2, a2, r2, · · · , sL, aL, rL)

• Historical data: D = {H1,H2, · · · ,Hn}• Historical data from behavior policy, πb• Objective:

V π = E[L∑

t=1

γtRt

∣∣π]

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 20

/ 68

Page 21: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Safe batch reinforement learning algorithm

• Reinforcement learning algorithm, A• Historical data, D, which is a random variable• Policy produced by the algorithm, A(D), which is a random variable• a safe batch reinforement learning algorithm, A, satisfies:

Pr(VA(D) ≥ V πb ≥ 1− δ

or, in general

Pr(VA(D) ≥ Vmin) ≥ 1− δ

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 21

/ 68

Page 22: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Table of Contents

1 What makes an RL algorithm safe?

2 Notation

3 Create a safe batch reinforement learning algorithmOff-policy policy evaluation (OPE)High-confidence off-policy policy evaluation (HCOPE)Safe policy improvement (SPI)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 22

/ 68

Page 23: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Create a safe batch reinforement learning algorithm

• Off-policy policy evaluation (OPE)• For any evaluation policy, πe , Convert historical data, D, into n

independent and unbiased estimates of V πe

• High-confidence off-policy policy evaluation (HCOPE)• Use a concentration inequality to convert the n independent and

unbiased estimates of V πe into a 1− δ confidence lower bound onV πe

• Safe policy improvement (SPI)• Use HCOPE method to create a safe batch reinforement learning

algorithm, a

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 23

/ 68

Page 24: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (OPE)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 24

/ 68

Page 25: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Importance Sampling (Reminder)

IS(D) =1n

n∑i=1

(L∏

t=1

πe(at∣∣ st)

πb(at∣∣ st)

)(L∑

t=1

γtR it

)E[IS(D)] = V πe

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 25

/ 68

Page 26: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Create a safe batch reinforement learning algorithm

• Off-policy policy evaluation (OPE)• For any evaluation policy, πe , Convert historical data, D, into n

independent and unbiased estimates of V πe

• High-confidence off-policy policy evaluation (HCOPE)• Use a concentration inequality to convert the n independent and

unbiased estimates of V πe into a 1− δ confidence lower bound onV πe

• Safe policy improvement (SPI)• Use HCOPE method to create a safe batch reinforement learning

algorithm, a

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 26

/ 68

Page 27: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

High-confidence off-policy policy evaluation (HCOPE)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 27

/ 68

Page 28: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Hoeffding’s inequality

• Let X1, · · · ,Xn be n independent identically distributed randomvariables such that Xi ∈ [0, b]

• Then with probability at least 1− δ:

E[Xi ] ≥1n

n∑i=1

Xi − b

√ln(1/δ)

2n,

where Xi = 1n

∑ni=1(wi

∑Lt=1 γ

tR it) in our case.

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 28

/ 68

Page 29: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Safe policy improvement (SPI)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 29

/ 68

Page 30: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Safe policy improvement (SPI)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 30

/ 68

Page 31: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Create a safe batch reinforement learning algorithm

• Off-policy policy evaluation (OPE)• For any evaluation policy, πe , Convert historical data, D, into n

independent and unbiased estimates of V πe

• High-confidence off-policy policy evaluation (HCOPE)• Use a concentration inequality to convert the n independent and

unbiased estimates of V πe into a 1− δ confidence lower bound onV πe

• Safe policy improvement (SPI)• Use HCOPE method to create a safe batch reinforement learning

algorithm, a

WON’T WORK!

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 31

/ 68

Page 32: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (revisited)

• Importance sampling (IS):

IS(D) =1n

n∑i=1

(L∏

t=1

πe(at∣∣ st)

πb(at∣∣ st)

)(L∑

t=1

γtR it

)

• Per-decision importance sampling (PDIS)

PSID(D) =L∑

t=1

γt1n

n∑i=1

(t∏

τ=1

πe(aτ∣∣ sτ )

πb(aτ∣∣ sτ )

)R it

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 32

/ 68

Page 33: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (revisited)

• Importance sampling (IS):

IS(D) =1n

n∑i=1

wi

(L∑

t=1

γtR it

)

• Weighted importance sampling (WIS)

WIS(D) =1∑n

i=1 wi

n∑i=1

wi

(L∑

t=1

γtR it

)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 33

/ 68

Page 34: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (revisited)

• Weighted importance sampling (WIS)

WIS(D) =1∑n

i=1 wi

n∑i=1

wi

(L∑

t=1

γtR it

)

• NOT unbiased. When n = 1,E[WIS ] = J(πb)

• Strongly consistent estimator of V πe

• i.e. Pr(limn→∞WIS(D) = V πe ) = 1• If• Finite horizon• One beahvior policy, or bounded rewards

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 34

/ 68

Page 35: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (revisited)

• Weighted per-decision importance sampling• Also called consistent weighted per-decision importance sampling• A fun exercise!

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 35

/ 68

Page 36: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Control variates

• Given: X• Estimate: µ = E[X ]

• µ̂ = X

• Unbiased: E[µ̂] = E[X ] = µ

• Variance: Var(µ̂) = Var(X )

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 36

/ 68

Page 37: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Control variates

• Given: X ,Y ,E[Y ]

• Estimate: µ = E[X ]

• µ̂ = X − Y + E[Y ]

• Unbiased:E[µ̂] = E[X − Y + E[Y ]] = E[X ]− E[Y ] + E[Y ] = E[X ] = µ

• Variance:

Var(µ̂) = Var(X − Y + E[Y ]) = Var(X − Y )

= Var(X ) + Var(Y )− 2Cov(X ,Y )

• Lower variance if 2Cov(X ,Y ) > Var(Y )

• We call Y a control variate• We saw this idea before: baseline term in policy gradient estimation

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 37

/ 68

Page 38: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (revisited)

• Idea: add a control variate to importance sampling estimators• X is the importance sampling estimator• Y is a control variate build from an approximate model of the

MDP• E[Y ] = 0 in this case

• PDISCV (D) = PDIS(D)− CV (D)

• Called the doubly robust estimator (Jiang and Li, 2015)• Robust to (1) poor approximate model, and (2) error in estimates

of πb• If the model is poor,the estimates are still unbiased• If the sampling policy is unknown, but the model is good,

MSE will still be low• DR(D) = PDISCV (D)

• Non-recursive and weighted forms, as well as control variate viewprovided by Thomas and Brunskill (2016)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 38

/ 68

Page 39: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (revisited)

DR(πe∣∣D) =

1n

n∑i=1

∞∑t=0

γtw it (R i

t − q̂πe (S it ,A

it)) + γtρit−1v̂

πe (S it),

where w it =

∏tτ1

πe(aτ

∣∣ sτ )πb(aτ

∣∣ sτ )• Recall: we want the control variate Y to cancel with X :

R − q(S ,A) + γv(S ′)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 39

/ 68

Page 40: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Empirical Results (Gridworld)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 40

/ 68

Page 41: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Empirical Results (Gridworld)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 41

/ 68

Page 42: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Empirical Results (Gridworld)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 42

/ 68

Page 43: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Empirical Results (Gridworld)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 43

/ 68

Page 44: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Empirical Results (Gridworld)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 44

/ 68

Page 45: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (revisited): Blending

• Importance sampling is unbiased but high variance• Model based estimate is biased but low variance• Doubly robust is one way to combine the two• Can also trade between importance sampling and model based estimatewithin a trajectory• MAGIC estimator (Thomas and Brunskill 2016)• Can be particularly useful when part of the world is non-Markovian in

the given model, and other parts of the world are Markov

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 45

/ 68

Page 46: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (revisited)

• What if supp(πe ⊂ supp(πb))• There is a state-action pair, (s, a), such that πe(a

∣∣ s) = 0, butπb(a

∣∣ s) 6= 0.• If we see a history where (s, a) occurs, what weight should we give it?

• IS(D) = 1n

∑ni=1

(∏Lt=1

πe(at

∣∣ st)πb(at

∣∣ st))(∑L

t=1 γtR i

t

)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 46

/ 68

Page 47: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (revisited)

• What if there are zero samples (n = 0)?• The importance sampling estimate is undefined

• What if no samples are in supp(πe) (or supp(p) in general)?• Importance sampling says: the estimate is zero• Alternate approach: undefined

• Importance sampling estimator is unbiased if n > 0• Alternate approach will be unbiased given that at least one sample is in

the support of p• Alternate approach detailed in Importance Sampling with Unequal

Support (Thomas and Brunskill, AAAI 2017)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 47

/ 68

Page 48: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (revisited)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 48

/ 68

Page 49: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (revisited)

• Thomas et. al. Predictive Off-Policy Policy Evaluation forNonstationary Decision Problems, with Applications to DigitalMarketing (AAAI 2017)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 49

/ 68

Page 50: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off-policy policy evaluation (revisited)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 50

/ 68

Page 51: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Create a safe batch reinforement learning algorithm

• Off-policy policy evaluation (OPE)• For any evaluation policy, πe , Convert historical data, D, into n

independent and unbiased estimates of V πe

• High-confidence off-policy policy evaluation (HCOPE)• Use a concentration inequality to convert the n independent and

unbiased estimates of V πe into a 1− δ confidence lower bound onV πe

• Safe policy improvement (SPI)• Use HCOPE method to create a safe batch reinforement learning

algorithm, a

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 51

/ 68

Page 52: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

High-confidence off-policy policy evaluation (revisited)

• Consider using IS + Hoeffding’s inequality for HCOPE on mountain car

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 52

/ 68

Page 53: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

High-confidence off-policy policy evaluation (revisited)

• Using 100,000 trajectories• Evaluation policy’s true performance is 0.19 ∈ [0, 1]

• We get a 95% cconfidence lower bound of: -5,8310,000

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 53

/ 68

Page 54: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

What went wrong

wi =L∏

t=1

πe(at∣∣ st)

πb(at∣∣ st)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 54

/ 68

Page 55: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

High-confidence off-policy policy evaluation (revisited)

• Removing the upper tail only decreases the expected value.

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 55

/ 68

Page 56: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

High-confidence off-policy policy evaluation (revisited)

• Thomas et. al, High confidence off-policy evaluation, AAAI 2015

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 56

/ 68

Page 57: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

High-confidence off-policy policy evaluation (revisited)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 57

/ 68

Page 58: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

High-confidence off-policy policy evaluation (revisited)

• Use 20% of the data to optimize c

• Use 80% to compute lower bound with optimized c

• Mountain car results:

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 58

/ 68

Page 59: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

High-confidence off-policy policy evaluation (revisited)

Digital marketing:

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 59

/ 68

Page 60: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

High-confidence off-policy policy evaluation (revisited)

Cognitive dissonance:

E[Xi ] ≥1n

n∑i=1

Xi − b

√ln(1/δ)

2n

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 60

/ 68

Page 61: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

High-confidence off-policy policy evaluation (revisited)

• Student’s t-test• Assumes that IS(D) is normally distributed• By the central limit theorem, it (is as n→∞)

Pr

(E[

1n

n∑i=1

Xi ] ≥1n

n∑i=1

Xi

)=

√1

n−1∑n

i=1(Xi − X̄n)2

√n

t1−δ,n−1

≥ 1− δ

• Efron’s Bootstrap methods (e.g., BCa)• Also, without importance sampling: Hanna, Stone, and

Niekum, AAMAS 2017

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 61

/ 68

Page 62: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

High-confidence off-policy policy evaluation (revisited)

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 62

/ 68

Page 63: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Create a safe batch reinforcement learning algorithm

• Off-policy policy evaluation (OPE)• For any evaluation policy, πe , Convert historical data, D, into n

independent and unbiased estimates of V πe

• High-confidence off-policy policy evaluation (HCOPE)• Use a concentration inequality to convert the n independent and

unbiased estimates of V πe into a 1− δ confidence lower bound onV πe

• Safe policy improvement (SPI)• Use HCOPE method to create a safe batch reinforcement learning

algorithm, a

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 63

/ 68

Page 64: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Safe policy improvement (revisited)

Thomas et. al, ICML 2015

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 64

/ 68

Page 65: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Empirical Results: Digital Marketing

Agent

Environment

Action, 𝑎

State, 𝑠 Reward, 𝑟

Page 66: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Empirical Results: Digital Marketing

0.002715

0.003832

n=10000 n=30000 n=60000 n=100000

Expecte

d N

orm

aliz

ed R

etu

rn

None, CUT None, BCa k-Fold, CUT k-Fold, Bca

Page 67: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Empirical Results: Digital Marketing

Page 68: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Empirical Results: Digital Marketing

Page 69: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Example Results : Diabetes Treatment

80

Blood Glucose (sugar)

Eat Carbohydrates Release Insulin

Page 70: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Example Results : Diabetes Treatment

81

Blood Glucose (sugar)

Eat Carbohydrates Release Insulin

Hyperglycemia

Page 71: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Example Results : Diabetes Treatment

82

Blood Glucose (sugar)

Eat Carbohydrates Release Insulin

Hypoglycemia

Hyperglycemia

Page 72: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Example Results : Diabetes Treatment

83

injection =bloodglucose − targetbloodglucose

𝐶𝐹+

mealsize

𝐶𝑅

Page 73: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Example Results : Diabetes Treatment

84

Intelligent Diabetes Management

Page 74: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Example Results : Diabetes Treatment

85

Pro

bab

ility

Po

licy

Ch

ange

d

Pro

bab

ility

Po

licy

Wo

rse

Page 75: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Other Relevant Work

• How to deal with long horizons? (Guo, Thomas, Brunskill NIPS 2017)• How to deal with importance sampling being “unfair”? (Doroudi,Thomas and Brunskill, best paper UAI 2017)• What to do when the behavior policy is not known?• What to do when the behavior policy is deterministic?• What to do when care about doing safe exploration?• What to do when care about performance on a single trajectory• For last two, see great work by Marco Pavone’s group, Pieter Abbeel’s

group, Shie Mannor’s group and Claire Tomlin’s group, amongst others

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 65

/ 68

Page 76: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Off Policy Policy Evaluation and Selection

• Very important topic: healthcare, education, marketing, ...• Insights are relevant to on policy learning• Big focus of my lab• A number of others on campus also working in this area (e.g. StefanWager, Susan Athey...)• Very interesting area at the intersection of causality and control

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 66

/ 68

Page 77: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

What You Should Know: Off Policy Policy Evaluation andSelection

• Be able to define and apply importance sampling for off policy policyevaluation• Define some limitations of IS (variance)• List a couple alternatives (weighted IS, doubly robust)• Define why we might want safe reinforcement learning• Define the scope of the guarantees implied by safe policy improvement

as defined in this lecture

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 67

/ 68

Page 78: Lecture 12: Batch RL - Stanford University€¦ · Empirical Results: Digital Marketing 0.002715 0.003832 n=10000 n=30000 n=60000 n=100000 ed Return None, CUT None, BCa k-Fold, CUT

Class Structure

• Last time: Exploration and Exploitation• This time: Batch RL• Next time: Monte Carlo Tree Search

Emma Brunskill (CS234 Reinforcement Learning. )Lecture 12: Batch RLWinter 2018 Slides drawn from Philip Thomas with modifications 68

/ 68