reinforcement learning: from basics to recent algorithms

31
1 Reinforcement Learning: From basics to Recent Algorithms 고려대학교 박영준

Upload: others

Post on 09-Feb-2022

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Reinforcement Learning: From basics to Recent Algorithms

1

Reinforcement Learning: From basics to Recent Algorithms

고려대학교

박영준

Page 2: Reinforcement Learning: From basics to Recent Algorithms

2

Contents

§ Reinforcement Learning

§ Multi-Armed Bandits Problem

§ Recent Algorithms

§ Conclusions

Page 3: Reinforcement Learning: From basics to Recent Algorithms

3

Reinforcement Learning (RL)

§ Find policy 𝛑 𝒂 𝒔 through max ∑𝐤)𝟎+ 𝜸𝒌𝑹𝐭0𝐤0𝟏

§ It is called approximate dynamic programming

Environment

Agent State: sReward: r

Actions: aInteraction

Page 4: Reinforcement Learning: From basics to Recent Algorithms

4

Comparison with Supervised Learning

§ Common

ü Predict something such as action or label

§ Difference

ü Interaction

Reinforcement Learning Supervised Learning

Training Data

𝑆, 𝐴, 𝑅, 𝑆, 𝐴, … (𝑋, 𝑌)

Model 𝜋 𝑎 𝑠 >Y = 𝐹(X)

Objective 𝐺D = 𝑅D0E + 𝛾𝑅D0H + 𝛾H𝑅D0I … = JK)L

+

𝛾K𝑅D0K0E Y − >Y H

Page 5: Reinforcement Learning: From basics to Recent Algorithms

5

Training Data of Reinforcement Learning (Optional)

§ Episode & S, A, R sequence

Episode Sequence

1 S, A, R, S, A, R, S, A, R, S, A, R

2 S, A, R

3 S, A, R, S, A, R

4 S, A, R, S, A, R, S, A, R

... …

Page 6: Reinforcement Learning: From basics to Recent Algorithms

6

Comparison with Unsupervised Learning

§ Common

ü No labels

§ Difference

ü RL maximize a cumulative rewards

Reinforcement Learning Unsupervised Learning

Training Data

𝑆, 𝐴, 𝑅, 𝑆, 𝐴, … 𝑋

Model 𝜋 𝑎 𝑠 𝐹(X)

Objective 𝐺D = 𝑅D0E + 𝛾𝑅D0H + 𝛾H𝑅D0I … = JK)L

+

𝛾K𝑅D0K0E X − 𝐹 𝑋

Page 7: Reinforcement Learning: From basics to Recent Algorithms

7

Multi-Armed Bandits Problem

§ k slot machines

§ State: single state [0, 0, 0, … 0]

§ Action: choice a machine

§ Reward: money

Page 8: Reinforcement Learning: From basics to Recent Algorithms

8

Solutions for Multi-Armed Bandits

§ Action-value methods

§ Gradient-based methods

Page 9: Reinforcement Learning: From basics to Recent Algorithms

9

Action-Value Function

§ 𝑄D(𝑎) measure benefit of each action

Bandit Episode1 Episode2 Episode3 Episode4 Q

1 2 2

2 3 3

3 5 5

4 1 1

Page 10: Reinforcement Learning: From basics to Recent Algorithms

10

Action-Value Function

§ 𝑄D(𝑎) measure preference of each action

Bandit Episode1 Episode2 Episode3 Episode4 Episode5 Q

1 2 3 2.5

2 3 3

3 5 5

4 1 1

Page 11: Reinforcement Learning: From basics to Recent Algorithms

11

Policy from Q Function

§ Policy𝑎D = argmax

Q𝑄D 𝑎

Bandit Episode1 Episode2 Episode3 Episode4 Episode5 Q

1 2 3 2.5

2 3 3

3 5 5

4 1 1

Estimate Q function → Play (run policy)

Page 12: Reinforcement Learning: From basics to Recent Algorithms

12

Estimation of Action-Value

§ Incremental update of 𝑄D(𝑎)

NewEstimate ← OldEstimate + StepSize (Target - OldEstimate)

Page 13: Reinforcement Learning: From basics to Recent Algorithms

13

Exploitation vs Exploration

§ Adding 𝜖-greedy policy

Bandit 𝑸𝟏 𝑸𝟐 𝑸𝟑 𝑸𝟒 𝑸𝟓 𝑸𝟔

1 0 0 0 0 0 5

2 0 0 2 2 2 2

3 0 3 3 3 3 3

4 0 0 0 1 1 1

Bandit Episode1 Episode2 Episode3 Episode4 Episode5 Episode6

1 5

2 2

3 3

4 1 1

Action Trajectory

Q Trajectory

Page 14: Reinforcement Learning: From basics to Recent Algorithms

14

Effect of 𝜖-greedy Policy

§ 𝜖-greedy policy

Page 15: Reinforcement Learning: From basics to Recent Algorithms

15

Gradient-Based Methods

§ Softmax policy (also called as Gibbs or Boltzmann)

§ Preference for each action 𝐻D(𝑎)

§ Update 𝐻D(𝑎)

• If the reward is higher than the baseline, then the probability of taking the action in the future is increased

• if the reward is below baseline, then probability is decreased.

Page 16: Reinforcement Learning: From basics to Recent Algorithms

16

Update Rule of Gradient-Based Methods

§ Gradient ascent algorithm

• Details in page 38~40

𝐻D0E 𝑎 ← 𝐻D 𝑎 + 𝛼𝜕𝐸[𝑅D]𝜕𝐻D(𝑎)

𝐸 𝑅D =J`

𝜋D 𝑥 𝑞∗(𝑥)𝜕𝐸[𝑅D]𝜕𝐻D(𝑎)

=𝜕

𝜕𝐻D(𝑎)J`

𝜋D 𝑥 𝑞∗ 𝑥

=J`

𝑞∗ 𝑥𝜕𝜋D 𝑥𝜕𝐻D(𝑎)

=J`

𝑅D𝜕𝜋D 𝑥𝜕𝐻D(𝑎)

𝐸 𝑅D|𝐴D = 𝑞∗(𝐴D)

Objectives

Page 17: Reinforcement Learning: From basics to Recent Algorithms

17

Gradient-Based Methods

§ Performance

Page 18: Reinforcement Learning: From basics to Recent Algorithms

18

Connection Between Reinforcement Learning

§ Action-value methods

→ Value-based RL

ü DQN

§ Gradient-based methods

→ Policy-based RL

ü Policy Gradient

§ Action-value methods & Gradient-based methods

→ Actor-Critic methods (actor: policy-based / critic: value-based)

ü A2C, A3C,…

Page 19: Reinforcement Learning: From basics to Recent Algorithms

19

Beyond Multi-Armed Bandits

§ Long episodes

§ Large states & actions

Page 20: Reinforcement Learning: From basics to Recent Algorithms

20

Value Functions

§ State-value functions

§ Action-value functions

Page 21: Reinforcement Learning: From basics to Recent Algorithms

21

Bellman Equations

§ Bellman Eq. for 𝑣f

§ Bellman Optimality Eq.

Page 22: Reinforcement Learning: From basics to Recent Algorithms

22

Dynamic Programming

§ Policy iteration, value iteration

Page 23: Reinforcement Learning: From basics to Recent Algorithms

23

Model-Free Methods

§ Monte Carlo (MC) Methods

• S, A, R, S, A, R, S, A, R, S, A, R, Terminate → Update

• S, A, R, S, A, R, Terminate → Update

§ Temporal Difference (TD) Learning

• S, A, R, Update, S, A, R, Update, S, A, R, Update, S, A, R, Terminate, Update

• S, A, R, Update, S, A, R, Terminate, Update

NewEstimate ← OldEstimate + StepSize (Target - OldEstimate)

Page 24: Reinforcement Learning: From basics to Recent Algorithms

24

MC vs TD

MC Methods TD Methods

Page 25: Reinforcement Learning: From basics to Recent Algorithms

25

On-Policy vs Off-policy

§ To enhance exploration, use off-policy methods

• One policy (target policy) learn (exploitation)

• Another policy generate behavior (exploration)

§ SARSA (on-policy TD)

§ Q-learning (off-policy TD)

Page 26: Reinforcement Learning: From basics to Recent Algorithms

26

On-Policy vs Off-policy

Page 27: Reinforcement Learning: From basics to Recent Algorithms

27

Deep Reinforcement Learning

§ Model-free control

𝑞 𝑠, 𝑎 = 𝐸 𝐺D|𝑆D = 𝑠, 𝐴D = 𝑎

≈ 𝐹(𝑠, 𝑎|𝜃)

𝜋 𝑆D0E = argmaxQi

𝑞 𝑆D0E, 𝑎′

§ Return의 기대값 Q value를 deep neural

network (𝐹)를 이용해 근사

§ 매 state마다 가장 큰 Q value에 대응하는

action을 선택

Deep�Q-Learning�(DQN)

𝜋 𝑆D0E ≈ 𝐹(𝑠|𝜃)

𝛻𝐽 𝜃 = 𝛻𝐸 𝐺D|𝜋

§ Policy를 deep neural network (𝐹 ) 를 이용해

근사

§ Policy가 주어졌을 때 , return의 기대값이

목적함수

Policy�Gradient

Page 28: Reinforcement Learning: From basics to Recent Algorithms

28

DQN

§ Off-policy TD learning

§ Objective

ℒ 𝜃 = 𝑦DQopqD − 𝑄 𝑠D, 𝑎D; 𝜃 H

§ DQN

𝑦DQopqD = 𝑟 + 𝛾maxQ𝑄(𝑠D0E, 𝑎; 𝜃t)

§ Double DQN

𝑦DQopqD = 𝑟 + 𝛾𝑄(𝑠D0E, argmaxQ

𝑄(𝑠D0E, 𝑎; 𝜃) ; 𝜃t)

Double�DQN

§ Q value = state value + advantage

𝑄 𝑠, 𝑎 ; 𝜃, 𝛼, 𝛽

= 𝑉 𝑠; 𝜃, 𝛽 + 𝐴 𝑠, 𝑎; 𝜃, 𝛼 − maxQi

𝐴 𝑠, 𝑎′; 𝜃, 𝛼

Dueling�DQN

Page 29: Reinforcement Learning: From basics to Recent Algorithms

29

Policy Gradient Methods

§ REINFORCE (MC policy gradient)𝛻w𝐽 𝜃 = 𝛻w log 𝜋w 𝑠 𝐺D

§ Actor Critic Policy Gradient (mix)𝛻w𝐽 𝜃 = 𝛻w log 𝜋w 𝑠 𝑄(𝑠, 𝑎)

§ Advantage Actor-Critic Policy Gradient (mix)𝛻w𝐽 𝜃 = 𝛻w log 𝜋w 𝑠 𝑄 𝑠, 𝑎 − 𝑉 𝑠

Page 30: Reinforcement Learning: From basics to Recent Algorithms

30

Tricks on Deep RL

§ Value-based method uses memory

• S, A, R, Update, S, A, R, Update, S, A, R, Update, S, A, R, Terminate, Update

§ Asynchronous methods

Page 31: Reinforcement Learning: From basics to Recent Algorithms

31

Conclusions