26
Reinforcement Learning Yijia Zhao ([email protected]) October 20, 2004

Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Reinforcement Learning

Yijia Zhao ([email protected])October 20, 2004

Page 2: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

What Is Reinforcement Learning?

What is Reinforcement Learning?

• Humans learn from interactions with the environment

• RL in AI addresses the question of how an autonomous

agent learns to choose optimal actions through trial and

error interactions

• Different from supervised learning

2

Page 3: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Standard RL Model

Standard RL Model

• T - the environment

• O - some observation of s, the current state of T

• R - reward from being in state s after choosing an action

a

• Goal - learning to choose actions that maximize rewards

3

SA3-B6

Agent Model

The agent’s interaction with the environment defined by

the transition, observation, and reward functions.

Page 4: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Example: Tic-Tac-Toe

Example: Tic-Tac-Toe

• Game theory approach such as minimax requires all play-

ers to make the best moves throughout the game, which

is not the case in practice.

4

Page 5: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Tic-Tac-Toe, RL StyleTic-Tac-Toe, RL Style

• V (i) - latest estimate of probability of winning from that

state i

• Most of the time find i with the largest V (i) and choose

the move that will lead to i

• Sometimes randomly choose a move

• Update V (i) as we go

• V (i) converges to the true probability of winning from

state i

5

Page 6: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Single-agent RL FormulationSingle-agent RL Formulation

• Modeled as a Markov decision problem

• S - the set of game states

• A - the set of actions available

• A reward function R : S × A→ R• A state transition function T : S × A × S → [0, 1],

T (s, a, s′) is the probability of going from s to s′ via action

a

• A policy π is a deterministic function from S to A

6

Page 7: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Single-agent RL Formulation Cont.

Single-agent RL Formulation Cont.

• Let γ ∈ [0, 1] be a discount rate

• Define value function

V π(s) =∞∑i=0

γiEπ[rt+i|st = s]

the expected total discounted reward starting at state s

following policy π

• We want the agent to learn an optimal policy π∗ s.t.

π∗ = arg maxπ

V π(s) ∀s ∈ S

• Write V ∗ instead of V π∗

7

Page 8: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Bellman Equation and Dynamic ProgrammingDynamic Programming for RL

• Bellman equation for value functions

V ∗(s) = maxπ

E[rt + γ∞∑i=0

γirt+i+1|st = s]

= maxa

{R(s, a) + γ∑s′∈S

T (s, a, s′)V ∗(s′)}

• Bellman showed that π is optimal if and only if it satisfies

the Bellman equation for all s ∈ S

• DL algorithms iteratively approximate value functions by

updating the value functions with Bellman equations

• Drawbacks

8

Page 9: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Temporal-Difference LearningTemporal-Difference Learning

• Temporal differences: adjust V (st) for state s using k

steps of observed rewards, followed by estimated value

function for the final visited state

TD(1) : ∆V (st) = α(rt+rt+1+. . .+rt+k+V (st+k)−V (st))

• Alternatively, we can update after just one step

TD(0) : ∆V (st) = α(rt + V (st+1)− V (st))

• TD(1) is the telescoping sum of TD(0)’s!

9

Page 10: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

TD(λ)TD(λ)

• For every state s

∆V (u) = α(r + V (s′)− V (s))e(u)

Eligibility e(s) =∑t

k=1(λγ)t−kδ(s, sk) where δ(s, sk) = 1

if s = sk and 0 otherwise

• Set λ to 0, only the most recently visited state is updated

• Set λ to 1, all visited states are updated

• Best learning occurs at intermediate values

10

Page 11: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Action Value Function QAction Value Function Q

• Define action value function

Qπ(s, a) =∞∑i=0

γiEπ[rt+i|st = s, at = a]

the expected discounted cumulative reward starting at

state s, taking action a, and following policy π thereafter

• Given Q∗(s, a), π∗ can be obtained by identifying the ac-

tion that maximizes Q∗(s, a)

• Bellman equation for Q:

Q∗(s, a) = R(s, a) + γ∑s′∈S

T (s, a, s′) maxa′∈A

Q∗(s′, a′)

11

Page 12: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Q-learning (Watkins 1989)Q-learning

• The most popular form of TD-learning

• Approximates Q(s, a) instead of V (s)

• For 1-step Q-learning, the temporal difference is defined

as

∆Q(st, at) = α(rt + γ maxat+1∈A

Q(st+1, at+1)−Q(st, at))

• Q-learning converges if learning rate decayed appropri-

ately and all states and actions have been visited infinitely

often (Watkins & Dayan 92; Tsitsiklis 94; Jaakkola et al.

94; Singh et al. 00)

12

Page 13: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

The Exploration-Exploitation TradeoffExploration And Exploitation

• Explore - act to reveal information about environment

• Exploit - act to gain high expected reward

• Q-learning convergence depends only on infinite explo-

ration, i.e. can’t be greedy all the time

• Choose random action with prob 1− ε

• Q-learning converges with any choice of ε

13

Page 14: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

TD-Gammon (Gerry Tesauro)

Page 15: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Multi-agent Reinforcement Learning

Multi-agent Reinforcement Learning

• Single-agent RL treats other agents in the system as part

of the environment

• Multi-agent RL explicitly takes other agents into consid-

eration

• Use Markov games (stochastic games) as the theoretical

framework

• Adopt solution concept from game theory

• Want all agents to learn policies such that their joint ac-

tions would eventually lead to an optimal solution

14

Page 16: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Two-Player Zero-Sum Markov Games

Two-player Zero-sum Markov Games

• Two agents with diametrically opposed goals

• A single reward function R : S ×A×O → R, where O is

the action set of the opponent

• A transition function T : S × A×O × S → [0, 1]

• Adopt the minimax strategy, i.e. behave so as to maxi-

mize the reward in the worst case

• An optimal policy π is defined as

π : S × A→ [0, 1]

15

Page 17: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Minimax-Q Learning (Littman 1994)

Minimax-Q Two-Player Zero-Sum Markov

Games (Littman 1994)

• Qπ(s, a, o) is the expected total discounted reward start-

ing at state s, taking action a, the opponent chooses o,

and following π thereafter

• V π(s) is the expected total discounted reward starting at

state s and follow π thereafter

V π(s) = maxπ

mino∈O

∑a∈A

Qπ(s, a, o)π(s, a)

• Bellman equation

Qπ(s, a, o) = R(s, a, o) + γ∑s′∈S

T (s, a, o, s′)V π(s′)

16

Page 18: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Minimax-Q Learning Algorithm

Let t = 1

for all s ∈ S, a ∈ A, o ∈ O do

Q(s, a, o) = 1

V (s) = 1

π(s, a) = 1|A|

end for

loop

With probability e, return an action uniformly at random

Otherwise, if current state is s, return action a with π(s, a)

Let s′ be the next state via a and o the opponent’s action

Q(s, a, o) = Q(s, a, o) + α(R(s, a, o) + γV (s′)−Q(s, a, o))

Use linear programming to find

π(s, ·) = arg maxπ′(s,·)

mino′∈O

∑a′∈A

π′(s, a′)Q(s, a′, o′)

V (s) = min o′ ∈ O

∑a′∈A

π(s, a′)Q(s, a′, o′)

α = α× d

t = t + 1

end loop

18

Page 19: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

General-Sum Markov GamesGeneral-Sum Markov Games

• N - the set of n agents

• S - the finite set of game states

• Ai - the action space of player i

• A transition function T : S × A1 × . . .× An × S → [0, 1]

• Define a reward function for each agent Ri : S×A1× . . .×An → R

• πi is the undeterministic policy of player i, πi : S ×Ai →[0, 1]

20

Page 20: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

General-Sum Markov Games Cont.

General-Sum Markov Games Cont.

• V i(s, π1, . . . ,πn) is the expected total discounted reward

for player i with player j following πj for all player i

V i(s, π1, . . . ,πn) =∞∑

k=0

γkE(rit+k|π1, . . . ,πn, st = s)

• (π1∗, . . . ,π

n∗ ) is a Nash equilibrium if and only if for all

s ∈ S and i ∈ N

V i(s, π1∗, . . . ,π

n∗ ) ≥ V i(s, π1

∗, . . . ,πi−1∗ , πi, πi+1

∗ , . . . ,πn∗ )

for all possible πi.

21

Page 21: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Nash Q-FunctionNash Q-function

• Agent i’s Nash Q-function is the sum of agent i’s current

reward plus its future rewards when all agents follow a

joint Nash equilibrium strategy.

Qi∗(s, a

1, . . . , an) = Ri(s, a1, . . . , an)

+γ∑s′∈S

T (s, a1, . . . , an, s′)V i(s′, π1∗, . . . ,π

n∗ )

• Rather than updating Nash Q-function based on the agent’s

own maximum future reward as in the single-agent case,

Nash Q-learning updates with future Nash equilibrium

rewards.

• Each agent i must observe the other agents’ rewards

22

Page 22: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Nash Q-Learning AlgorithmNash Q-learning

Agent i’s expected total reward following selected Nash equilibrium at state s′ is defined as

NashQit(s

′) =

∑all joint action profiles

[Ri(s′, a1, . . . , an)

∏i∈N

πi(s′, ai)]

Let t = 0

for all s ∈ S, aj ∈ Aj , j = 1, . . . , n do

Qjt (s, a1, . . . , an) = 0

end for

loop

Choose action ait

Observe r1t , . . . , rn

t ; a1t , . . . , an

t , and st+1 = s′for all j = 1, . . . , n do

Qjt+1(s, a1

t , . . . , ant ) = Qj

t (s, a1t , . . . , an

t )

+αt(rjt + γNashQj

t (s′)−Qjt (s, a1

t , . . . , ant ))

end for

t = t + 1

end loop

23

Page 23: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Convergence Requirements For Nash Q-Learning

Convergence Requirements for Nash

Q-learning

• (Q1t , . . . , Q

nt ) converges to (Q1

∗, . . . , Qn∗ ) if every state and

action have been visited infinitely often and the learning

rate αt satisfies

1. 0 ≤ αt(s, a1, . . . , an) < 1,∑∞

t=0 αt(s, a1, . . . , an) = ∞,∑∞t=0(αt(s, a1, . . . , an))2 < ∞, and the latter two hold

uniformly and with probability 1

2. αt(s, a1, . . . , an) = 0 if (s, a1, . . . , an) #= (st, a1, . . . , an)

3. For every t and s ∈ S, there exists a joint action profile

(a1, . . . , an) such that it is a global optimal point or a

saddle point for (Q1t (s, ·), . . . , Qn

t (s, ·)).

24

Page 24: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Limitations of Nash Q-LearningLimitations of Nash Q-learning

• Aside from zero-sum or fully cooperative games, no general-

sum game has been shown to satisfy convergence require-

ments for Nash Q-learning

• If multiple optimal NE exist, the algorithm needs an ora-

cle to coordinate in order to converge to a NE

• Worse case running time is exponential

25

Page 25: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Other Learning Algorithms for MARL

Other Learning Algorithms for MARL

• Friend-or-Foe-Q (Littman 2001) - divides the set of op-

ponents into set of friends (use max) and set of foes (use

minimax), easier to implement and converges to an opti-

mal NE with less strict requirements

• Optimal Adaptive Learning (Wang & Sandholm 2002) -

converges to an optimal NE for all Markov games where

each agent receives the same expected reward (team Markov

games)

• Polynomial Convergence (Brafman & Tennenholtz 2003)

- showed that there exists a polynomial convergence algo-

rithm for team Markov games

26

Page 26: Reinforcement Learning - University of Virginiapeople.virginia.edu/~sdp5f/CSRG/publications/793_fall04/Seminar06… · Tic-Tac-TTic-Toe, RLa c-T oe, StyleRL St yl e ¥ V(i) - lat

Open Questions in MARLOpen Questions in MARL

• A more widely applicable learning algorithm for general-

sum Markov games

• Is NE the best solution concept?

28