CS 542 Statistical Reinforcement Learning

39
CS 542 Statistical Reinforcement Learning Nan Jiang

Transcript of CS 542 Statistical Reinforcement Learning

Page 1: CS 542 Statistical Reinforcement Learning

CS 542 Statistical Reinforcement Learning

Nan Jiang

Page 2: CS 542 Statistical Reinforcement Learning

What’s this course about?

• A grad-level seminar course on theory of RL • with focus on sample complexity analyses • all about proofs, some perspectives, 0 implementation • No text book; material is created by myself (course notes)

• Related monograph under development w/ Alekh Agarwal, Sham Kakade, and Wen Sun

• See course website for more material and references

2

Page 3: CS 542 Statistical Reinforcement Learning

Who should take this course?

• This course will be a good fit for you if you either • (A) have exposure to RL + comfortable with long

mathematical derivations + interested in understanding RL from a purely theoretical perspective

• (B) are proficient in learning theory and comfortable with highly abstract description of concepts / models / algorithms

• For people not in (A) or (B): I also teach CS498 RL (likely offered sp22), which focuses less on analyses & proofs and more on algorithms & intuitions

3

Page 4: CS 542 Statistical Reinforcement Learning

Prerequisites

• Maths • Linear algebra, probability & statistics, basic calculus • Markov chains • Optional: stochastic processes, numerical analysis • Useful: TCS background, empirical processes and

statistical learning theory, optimization, online learning • Exposure to ML

• e.g., CS 446 Machine Learning • Experience with RL

4

Page 5: CS 542 Statistical Reinforcement Learning

Coursework

• Some readings after/before class • 3~4 homeworks to help digest certain material. • Main assignment: course project (work on your own)

• Baseline: reproduce theoretical analysis in existing papers • Advanced: identify an interesting/challenging extension to

the paper and explore the novel research question yourself • Or, just work on a novel research question (must have a

significant theoretical component; need to discuss with me)

5

Page 6: CS 542 Statistical Reinforcement Learning

Course project (cont.)

• See list of references and potential topics on website • You will need to submit:

• A brief proposal (~1/2 page). Tentative deadline: end of Oct • what’s the topic and what papers you plan to work on • why you choose the topic: what interest you? • which aspect(s) you will focus on?

• Final report: clarity, precision, and brevity are greatly valued. More details to come…

• All docs should be in pdf. Final report should be prepared using LaTeX.

6

Page 7: CS 542 Statistical Reinforcement Learning

Course project (cont. 2)

Rule of thumb 1. learn something that interests you 2. teach me something! (I wouldn’t learn if I could not

understand your report due to lack of clarity) 3. write a report similar to (or better than!) the notes I will share

with you

7

Page 8: CS 542 Statistical Reinforcement Learning

Contents of the course

• many important topics in RL will not be covered in depth (e.g., TD). Read more (e.g., Sutton & Barto book) if you want to get a more comprehensive view of RL

• the other opportunity to learn what’s not covered in lectures is the project, as potential topics for projects are much broader than what’s covered in class.

8

Page 9: CS 542 Statistical Reinforcement Learning

• Course website: http://nanjiang.cs.illinois.edu/cs542/ • logistics, links to slides/notes, and resources (e.g.,

textbooks to consult, related courses) • Canvas for Q&A and announcements: see link on website.

• Please pay attention to Canvas announcements• Those who are not registered: please contact TA to be

added to Canvas • Recording: published on MediaSpace (link on website) • Time: Wed & Fri 12:30-1:45pm. • TA: Jiawei Huang ([email protected]) • Office hours: by appointment

9

Logistics

Page 10: CS 542 Statistical Reinforcement Learning

Introduction to MDPs and RL

Page 11: CS 542 Statistical Reinforcement Learning

11

[Levine et al’16] [Ng et al’03][Mandel et al’16]

[Singh et al’02]

Reinforcement Learning (RL)

[Mnih et al’15][Silver et al’16][Lei et al’12]

[Tesauro et al’07]

Applications

Page 12: CS 542 Statistical Reinforcement Learning

12

s0

b

c

d

e

f

g1

2

3

2

1

3

14

Greedy is suboptimal due to delayed effects

1

V*(g) = 0

V*(f) = 1

V*(d) = 2

V*(e) = 2V*(c) = 4

V*(b) = 5

V*(s0) = 6

V*(d) = min{3 + V*(g) , 1 + V*(f)}

Need long-term planning

Shortest Path

state

action

Bellman Equation

Page 13: CS 542 Statistical Reinforcement Learning

13

s0

b

c

d

e

f

g1

2

2

1

3

14

1

Shortest Path

4

Page 14: CS 542 Statistical Reinforcement Learning

14

s0

b

c

d

e

f

g0.7

0.3

Stochastic

1

2

2

1

3

14

1

Shortest Path

transition distribution

e

0.50.5

Markov Decision Process (MDP)

4

state

action

Page 15: CS 542 Statistical Reinforcement Learning

1

15

s0

b

c

d

e

f

g

0.50.5

1

2

4

2

1

3

14

0.7

0.3

V*(c) = min{4 + 0.7 × V*(d) + 0.3 × V*(e) , 2 + V*(e)}

Stochastic Shortest Path

✓: optimal policy π*

V*(g) = 0

V*(f) = 1

V*(d) = 2

V*(e) = 2.5V*(c) = 4.5

V*(b) = 6

V*(s0) = 6.5

Bellman Equation

Greedy is suboptimal due to delayed effectsNeed long-term planning

✓✓

✓ ✓

Page 16: CS 542 Statistical Reinforcement Learning

Trajectory 1: s0↘ c ↗ d → g

?

16

s0

b

c

d

e

f

g

1

1

2

4

2

1

3

14 0.5

0.5

0.7

0.3

via trial-and-errorStochastic Shortest Path

Page 17: CS 542 Statistical Reinforcement Learning

1

2

4

2

1

3

14

1

17

s0

b

c

d

e

f

g

0.50.5

0.7

0.3s0

c ee

f

g

Trajectory 2: s0↘ c ↗ e → f ↗ g

via trial-and-error

Trajectory 1: s0↘ c ↗ d → g

Shortest PathStochastic

Page 18: CS 542 Statistical Reinforcement Learning

18

0.72

0.28s0

b

c

d

e

f

g

0.55

0.45

1

2

4

2

1

3

14

1

via trial-and-error

How many trajectories do we need to compute a near-optimal policy?

Trajectory 2: s0↘ c ↗ e → f ↗ g

Trajectory 1: s0↘ c ↗ d → g

Shortest Path

sample complexity

Stochastic

Model-based RL

Page 19: CS 542 Statistical Reinforcement Learning

19

s0

b

c

d

e

f

g1

2

4

2

1

3

14

1

via trial-and-error

How many trajectories do we need to compute a near-optimal policy?

• Assume states & actions are visited uniformly • #trajectories needed ≤ n ⋅ (#state-action pairs)

#samples needed to estimate a multinomial distribution

s0

b

c

d

e

f

g1

2

2

1

3

14

1

Nontrivial! Need exploration

?

??

?

Shortest PathStochastic

4

Page 20: CS 542 Statistical Reinforcement Learning

20

Video game playing

5 10 15

γ = 0.8

γ = 0.9

5 10 15

H = 5

H = 10

e.g., random spawn of enemies

action at ∈ A

+20

reward rt = R (st , at)

transition dynamics P ( ⋅ | st , at)

state st ∈ S

policy π: S → A

objective: maximize (or ) E⇥P

H

t=1 rt |⇡⇤

E⇥P1

t=1 �t�1rt |⇡

(unknown)

Page 21: CS 542 Statistical Reinforcement Learning

21

Need generalization

Video game playing

Value function approximation

Page 22: CS 542 Statistical Reinforcement Learning

f (x;θ)

22

f (x;θ)

state features x

state features x

θ

x

x’

+r

Find θ s.t. f (x;θ) ≈ r + γ ⋅ Ex’|x [ f (x’;θ)]…

Need generalization

⇒ f (⋅ ; θ) ≈ V*

Video game playing

Value function approximation

Page 23: CS 542 Statistical Reinforcement Learning

23

value

state features x

Adaptive medical treatment

• State: diagnosis • Action: treatment • Reward: progress in recovery

Page 24: CS 542 Statistical Reinforcement Learning

A Machine Learning view of RL

Page 25: CS 542 Statistical Reinforcement Learning

25

Lecture 1: Introduction to Reinforcement Learning

About RL

Many Faces of Reinforcement Learning

Computer Science

Economics

Mathematics

Engineering Neuroscience

Psychology

Machine Learning

Classical/OperantConditioning

Optimal Control

RewardSystem

Operations Research

BoundedRationality

Reinforcement Learning

slide credit: David Silver

Page 26: CS 542 Statistical Reinforcement Learning

^

Supervised Learning

Given {(x(i), y(i))}, learn f : x ↦ y• Online version: for round t = 1, 2,…, the learner

• observes x(t) • predicts y(t) • receives y(t)

• Want to maximize # of correct predictions• e.g., classifies if an image is about a dog, a cat, a plane, etc.

(multi-class classification) • Dataset is fixed for everyone • “Full information setting” • Core challenge: generalization

26

Page 27: CS 542 Statistical Reinforcement Learning

Contextual bandits

For round t = 1, 2,…, the learner • Given x(t) , chooses from a set of actions a(t) ∈ A • Receives reward r(t) ~ R(x(t) , a(t)) (i.e., can be random) • Want to maximize total reward • You generate your own dataset {(x(t) , a(t) , r(t))}! • e.g., for an image, the learner guesses a label, and is told

whether correct or not (reward = 1 if correct and 0 otherwise). Do not know what’s the true label.

• e.g., for an user, the website recommends a movie, and observes whether the user likes it or not. Do not know what movies the user really want to see.

• “Partial information setting”

27

Page 28: CS 542 Statistical Reinforcement Learning

Contextual bandits

Contextual Bandits (cont.) • Simplification: no x, Multi-Armed Bandits (MAB) • Bandit is a research area by itself. we will not do a lot of bandits

but may go through some material that have important implications on general RL (e.g., lower bounds)

28

Page 29: CS 542 Statistical Reinforcement Learning

RL

For round t = 1, 2,…,

• For time step h=1, 2, …, H, the learner

• Observes xh(t)

• Chooses ah(t)

• Receives rh(t) ~ R(xh(t) , ah(t))

• Next xh+1(t) is generated as a function of xh(t) and ah(t)

(or sometimes, all previous x’s and a’s within round t)

• Bandits + “Delayed rewards/consequences”

• The protocol here is for episodic RL (each t is an episode).

29

Page 30: CS 542 Statistical Reinforcement Learning

Two types of scenarios in RL research

1. Solving a large planning problem using a learning approach - e.g., AlphaGo, video game playing, simulated robotics - Transition dynamics (Go rules) known, but too many states - Run the simulator to collect data

2. Solving a learning problem - e.g., adaptive medical treatment - Transition dynamics unknown (and too many states) - Interact with the environment to collect data

Why statistical RL?

30

Page 31: CS 542 Statistical Reinforcement Learning

Two types of scenarios in RL research

1. Solving a large planning problem using a learning approach

2. Solving a learning problem

• I am more interested in #2. More challenging in some aspects. • Data (real-world interactions) is highest priority. Computation

second. • Even for #1, sample complexity lower-bounds computational

complexity — statistical-first approach is reasonable. • caveat to this argument: you can do a lot more in a simulator;

see http://hunch.net/?p=8825714

Why statistical RL?

31

Page 32: CS 542 Statistical Reinforcement Learning

MDP Planning

Page 33: CS 542 Statistical Reinforcement Learning

An MDP M = (S, A, P, R, γ)

• State space S.

• Action space A.

• Transition function P : S×A→∆(S). ∆(S) is the probability simplex over S, i.e., all non-negative vectors of length |S| that sums up to 1

• Reward function R: S×A→ℝ. (deterministic reward function)

• Discount factor γ ∈ [0,1)

• The agent starts in some state s1, takes action a1, receives reward r1 ~ R(s1, a1), transitions to s2 ~ P(s1, a1), takes action a2, so on so forth — the process continues indefinitely

Infinite-horizon discounted MDPs

33

We will only consider discrete and finite spaces in this course.

Page 34: CS 542 Statistical Reinforcement Learning

• Want to take actions in a way that maximizes value (or return):

• This value depends on where you start and how you act • Often assume boundedness of rewards:

• What’s the range of ?

• A (deterministic) policy π: S→A describes how the agent acts: at state st, chooses action at = π(st).

• More generally, the agent may choose actions randomly (π: S→ ∆(A)), or even in a way that varies across time steps (“non-stationary policies”)

• Define

Value and policy

34

rt ∈ [0, Rmax]𝔼 [∑∞

t=1 γt−1rt] [0,Rmax

1 − γ ]

𝔼 [∑∞t=1 γt−1rt]

Vπ(s) = 𝔼 [∑∞t=1 γt−1rt s1 = s, π ]

Page 35: CS 542 Statistical Reinforcement Learning

Bellman equation for policy evaluation

35

V ⇡(s) = E" 1X

t=1

�t�1rt��s1 = s,⇡

#

= E"r1 +

1X

t=2

�t�1rt��s1 = s,⇡

#

= R(s,⇡(s)) +X

s02SP (s0|s,⇡(s))E

"�

1X

t=2

�t�2rt��s1 = s, s2 = s0,⇡

#

= R(s,⇡(s)) +X

s02SP (s0|s,⇡(s))E

"�

1X

t=2

�t�2rt��s2 = s0,⇡

#

= R(s,⇡(s)) + �X

s02SP (s0|s,⇡(s))E

" 1X

t=1

�t�1rt��s1 = s0,⇡

#

= R(s,⇡(s)) + �X

s02SP (s0|s,⇡(s))V ⇡(s0)

= R(s,⇡(s)) + �hP (·|s,⇡(s)), V ⇡(·)i<latexit sha1_base64="EOqUViW3eaQRlDRi0wywMhhOOhU=">AAAFNniczVRbaxNBFJ52V63xluqjLweDJsE07AZBXwpFEXzwIV6SFjLJMjuZbIbOXpiZFcJ2+6d88Xf41hcfFPHVn+DsJoaYVqUFwYFhD+fyfd85nB0/EVxpxznZ2LTsS5evbF2tXLt+4+at6vbtvopTSVmPxiKWBz5RTPCI9TTXgh0kkpHQF2zfP3xWxPffMal4HL3Vs4QNQxJEfMIp0cblbVsv+6MMJzxvqCbswoNjAMAh0VPfz57nWLCJHmCVhl6md918hHk00TPAAQlDMsr0jpuD9DQcY58HR6A814CoFhhEwOYjeTDVQ4wrv4GWpuAh/CToXJQAlgyvG6plYqab5hJY1Q1qyUyJyN7kOXQbqn40RykzC6T1pksFf5TWOVua8jqFUf8/RZ5T2yrBhSTCubfnH4pb7nq9+TdQQaJAMAOC6TjWKzitVaAy2DR7Lct0r1pz2k554LThLowaWpyuV/2IxzFNQxZpKohSA9dJ9DAjUnMqWF7BqWIJoYckYANjRiRkapiVv30O941nDJNYmhtpKL2rFRkJlZqFvsks5qLWY4XzrNgg1ZMnw4xHSapZROdEk1SAjqF4Q2DMJaNazIxBqORGK9ApkYRq89JUzBDc9ZZPG/1O23Xa7qtHtb2ni3FsobvoHmogFz1Ge+gF6qIeotZ768T6bH2xP9if7K/2t3nq5sai5g765djffwCC5qb0</latexit><latexit sha1_base64="EOqUViW3eaQRlDRi0wywMhhOOhU=">AAAFNniczVRbaxNBFJ52V63xluqjLweDJsE07AZBXwpFEXzwIV6SFjLJMjuZbIbOXpiZFcJ2+6d88Xf41hcfFPHVn+DsJoaYVqUFwYFhD+fyfd85nB0/EVxpxznZ2LTsS5evbF2tXLt+4+at6vbtvopTSVmPxiKWBz5RTPCI9TTXgh0kkpHQF2zfP3xWxPffMal4HL3Vs4QNQxJEfMIp0cblbVsv+6MMJzxvqCbswoNjAMAh0VPfz57nWLCJHmCVhl6md918hHk00TPAAQlDMsr0jpuD9DQcY58HR6A814CoFhhEwOYjeTDVQ4wrv4GWpuAh/CToXJQAlgyvG6plYqab5hJY1Q1qyUyJyN7kOXQbqn40RykzC6T1pksFf5TWOVua8jqFUf8/RZ5T2yrBhSTCubfnH4pb7nq9+TdQQaJAMAOC6TjWKzitVaAy2DR7Lct0r1pz2k554LThLowaWpyuV/2IxzFNQxZpKohSA9dJ9DAjUnMqWF7BqWIJoYckYANjRiRkapiVv30O941nDJNYmhtpKL2rFRkJlZqFvsks5qLWY4XzrNgg1ZMnw4xHSapZROdEk1SAjqF4Q2DMJaNazIxBqORGK9ApkYRq89JUzBDc9ZZPG/1O23Xa7qtHtb2ni3FsobvoHmogFz1Ge+gF6qIeotZ768T6bH2xP9if7K/2t3nq5sai5g765djffwCC5qb0</latexit><latexit sha1_base64="EOqUViW3eaQRlDRi0wywMhhOOhU=">AAAFNniczVRbaxNBFJ52V63xluqjLweDJsE07AZBXwpFEXzwIV6SFjLJMjuZbIbOXpiZFc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ubfnH4pb7nq9+TdQQaJAMAOC6TjWKzitVaAy2DR7Lct0r1pz2k554LThLowaWpyuV/2IxzFNQxZpKohSA9dJ9DAjUnMqWF7BqWIJoYckYANjRiRkapiVv30O941nDJNYmhtpKL2rFRkJlZqFvsks5qLWY4XzrNgg1ZMnw4xHSapZROdEk1SAjqF4Q2DMJaNazIxBqORGK9ApkYRq89JUzBDc9ZZPG/1O23Xa7qtHtb2ni3FsobvoHmogFz1Ge+gF6qIeotZ768T6bH2xP9if7K/2t3nq5sai5g765djffwCC5qb0</latexit>

Page 36: CS 542 Statistical Reinforcement Learning

Bellman equation for policy evaluation

36

Matrix form: define

• Vπ as the |S|×1 vector [Vπ(s)]s∈S

• Rπ as the vector [R(s, π(s))]s∈S

• Pπ as the matrix [P(s’|s, π(s))]s∈S, s’∈S

Vπ(s) = R(s, π(s)) + γ⟨P( ⋅ |s, π(s)), Vπ( ⋅ )⟩

Vπ = Rπ + γPπVπ

(I − γPπ)Vπ = Rπ

Vπ = (I − γPπ)−1Rπ

This is always invertible. Proof?

Page 37: CS 542 Statistical Reinforcement Learning

Each row (indexed by s) is the normalized discounted state occupancy dπ,s, whose (s’)-th entry is

• (1-γ) is the normalization factor so that the matrix is row-stochastic.

• Vπ(s) is the dot product between and reward vector

• Can also be interpreted as the value function of indicator reward function

dπ,s/(1 − γ)

State occupancy

37

(1 − γ) ⋅ (I − γPπ)−1

dπ,s(s′ ) = 𝔼 [∞

∑t=1

γt−1 𝕀[st = s′ ] s1 = s, π ]

Page 38: CS 542 Statistical Reinforcement Learning

• For infinite-horizon discounted MDPs, there always exists a stationary and deterministic policy that is optimal for all starting states simultaneously• Proof: Puterman’94, Thm 6.2.7 (reference due to Shipra Agrawal)

• Let π* denote this optimal policy, and V* := Vπ*

• Bellman Optimality Equation:

• If we know V*, how to get π* ?

• Easier to work with Q-values: Q*(s, a), as

Optimality

38

V⋆(s) = maxa∈A (R(s, a) + γ𝔼s′ ∼P(s,a) [V⋆(s′ )])

π⋆(s) = arg maxa∈A

Q⋆(s, a)

Q⋆(s, a) = R(s, a) + γ𝔼s′ ∼P(s,a) [maxa′ ∈A

Q⋆(s′ , a′ )]

Page 39: CS 542 Statistical Reinforcement Learning

• uploaded on course website

• help understand the relationships between alternative MDP formulations

• more like readings w/ questions to think about

• no need to submit

Ad Hoc Homework 1

39