0% found this document useful (0 votes)
9 views

Lec 09

This document discusses Markov decision processes and methods for solving them. It introduces value iteration, which iteratively updates value estimates until convergence. It also covers policy iteration, which alternates between policy evaluation to calculate values for the current policy and policy improvement to derive a new policy based on the values.

Uploaded by

daliYop
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Lec 09

This document discusses Markov decision processes and methods for solving them. It introduces value iteration, which iteratively updates value estimates until convergence. It also covers policy iteration, which alternates between policy evaluation to calculate values for the current policy and policy improvement to derive a new policy based on the values.

Uploaded by

daliYop
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

CS 188: Artificial Intelligence

Markov Decision Processes II

Instructor: Pieter Abbeel


University of California, Berkeley
[These slides adapted from Dan Klein and Pieter Abbeel]
Recap: Defining MDPs
o Markov decision processes:
s
o Set of states S
o Start state s0 a
o Set of actions A
o Transitions P(s’|s,a) (or T(s,a,s’)) s, a
o Rewards R(s,a,s’) (and discount g)
s,a,s’
s’
o MDP quantities so far:
o Policy = Choice of action for each state
o Utility = sum of (discounted) rewards
o Values = expected future utility from a state (max node)
o Q-Values = expected future utility from a q-state (chance node)
Example: Grid World
§ A maze-like problem
§ The agent lives in a grid
§ Walls block the agent’s path

§ Noisy movement: actions do not always go as


planned
§ 80% of the time, the action North takes the agent
North (if there is no wall there)
§ 10% of the time, North takes the agent West; 10% East
§ If there is a wall in the direction the agent would have
been taken, the agent stays put

§ The agent receives rewards


§ Small “living” reward each step (can be negative)
§ Big rewards come at the end (good or bad)

§ Goal: maximize sum of rewards


Solving MDPs
Optimal Quantities

§ The value (utility) of a state s:


V*(s) = expected utility starting in s s s is a
and acting optimally state
a
(s, a) is a
§ The value (utility) of a q-state (s,a): s, a q-state
Q*(s,a) = expected utility starting out
having taken action a from state s s,a,s’ (s,a,s’) is a
and (thereafter) acting optimally s’ transition

§ The optimal policy:


p*(s) = optimal action from state s
Value Iteration
o Start with V0(s) = 0: no time steps left means an expected reward sum of zero
o Given vector of Vk(s) values, do one ply of expectimax from each state:
Vk+1(s)
a
s, a

o Repeat until convergence, which yields V* s,a,s’


Vk(s’)

o Complexity of each iteration: O(S2A)

o Theorem: will converge to unique optimal values


o Basic idea: approximations get refined towards optimal values
o Policy may converge long before values do
Value Iteration
o Bellman equations characterize the optimal values: V(s)

a
s, a

s,a,s’
o Value iteration computes them: V(s’)

o Value iteration is just a fixed point solution method


o … though the Vk vectors are also interpretable as time-limited values
Value Iteration (again J ) s
a
o Init:
s, a
∀𝑠: 𝑉 𝑠 = 0
s,a,s’
o Iterate: s’

∀𝑠: 𝑉!"# 𝑠 = max * 𝑇 𝑠, 𝑎, 𝑠 & [𝑅 𝑠, 𝑎, 𝑠 & + 𝛾𝑉 𝑠 & ]


$
%&

𝑉 = 𝑉!"#
Note: can even directly assign to V(s), which will not compute the sequence of Vk but will still converge to V*
The Bellman Equations

How to be optimal:
Step 1: Take correct first action

Step 2: Keep being optimal


k=0

Noise = 0.2
Discount = 0.9
Living reward = 0
k=1

Noise = 0.2
Discount = 0.9
Living reward = 0
k=2

Noise = 0.2
Discount = 0.9
Living reward = 0
k=3

Noise = 0.2
Discount = 0.9
Living reward = 0
k=4

Noise = 0.2
Discount = 0.9
Living reward = 0
k=5

Noise = 0.2
Discount = 0.9
Living reward = 0
k=6

Noise = 0.2
Discount = 0.9
Living reward = 0
k=7

Noise = 0.2
Discount = 0.9
Living reward = 0
k=8

Noise = 0.2
Discount = 0.9
Living reward = 0
k=9

Noise = 0.2
Discount = 0.9
Living reward = 0
k=10

Noise = 0.2
Discount = 0.9
Living reward = 0
k=11

Noise = 0.2
Discount = 0.9
Living reward = 0
k=12

Noise = 0.2
Discount = 0.9
Living reward = 0
k=100

Noise = 0.2
Discount = 0.9
Living reward = 0
Policy Extraction
Computing Actions from Values
o Let’s imagine we have the optimal values V*(s)

o How should we act?


o It’s not obvious!

o We need to do a mini-expectimax (one step)

o This is called policy extraction, since it gets the policy implied by the
values
Computing Actions from Q-Values
o Let’s imagine we have the optimal
q-values:

o How should we act?


o Completely trivial to decide!

o Important lesson: actions are easier to select from q-values than


values!
Let’s think.
o Take a minute, think about value iteration.
o Write down the biggest question you have about it.
Policy Methods
Problems with Value Iteration
o Value iteration repeats the Bellman updates: s
a
s, a

o Problem 1: It’s slow – O(S2A) per iteration s,a,s’


s’

o Problem 2: The “max” at each state rarely changes

o Problem 3: The policy often converges long before the values


k=12

Noise = 0.2
Discount = 0.9
Living reward = 0
k=100

Noise = 0.2
Discount = 0.9
Living reward = 0
Policy Iteration
o Alternative approach for optimal values:
o Step 1: Policy Evaluation: calculate utilities for some fixed policy (not optimal
utilities!) until convergence
o Step 2: Policy Improvement: update policy using one-step look-ahead with
resulting converged (but not optimal!) utilities as future values
o Repeat steps until policy converges

o This is Policy Iteration


o It’s still optimal!
o Can converge (much) faster under some conditions
Policy Evaluation
Fixed Policies
Do the optimal action Do what p says to do
s s
a p(s)
s, a s, p(s)

s,a,s’ s, p(s),s’
s’ s’

o Expectimax trees max over all actions to compute the optimal values
o If we fixed some policy p(s), then the tree would be simpler – only one action
per state
o … though the tree’s value would depend on which policy we fixed
Utilities for a Fixed Policy
o Another basic operation: compute the utility of a state s s
under a fixed (generally non-optimal) policy
p(s)
o Define the utility of a state s, under a fixed policy p: s, p(s)
Vp(s) = expected total discounted rewards starting in s and
following p
s, p(s),s’
s’
o Recursive relation (one-step look-ahead / Bellman
equation):
Policy Evaluation
o How do we calculate the V’s for a fixed policy p? s

o Idea 1: Turn recursive Bellman equations into updates p(s)


(like value iteration) s, p(s)

s, p(s),s’
s’

o Efficiency: O(S2) per iteration

o Idea 2: Without the maxes, the Bellman equations are just a linear system
o Solve with Matlab (or your favorite linear system solver)
Example: Policy Evaluation
Always Go Right Always Go Forward
Example: Policy Evaluation
Always Go Right Always Go Forward
Policy Iteration
Policy Iteration

o Evaluation: For fixed current policy p, find values with policy evaluation:
o Iterate until values converge:

o Improvement: For fixed values, get a better policy using policy extraction
o One-step look-ahead:
Comparison
o Both value iteration and policy iteration compute the same thing (all optimal values)

o In value iteration:
o Every iteration updates both the values and (implicitly) the policy
o We don’t track the policy, but taking the max over actions implicitly recomputes it

o In policy iteration:
o We do several passes that update utilities with fixed policy (each pass is fast because we
consider only one action, not all of them)
o After the policy is evaluated, a new policy is chosen (slow like a value iteration pass)
o The new policy will be better (or we’re done)

o Both are dynamic programs for solving MDPs


Summary: MDP Algorithms
o So you want to….
o Compute optimal values: use value iteration or policy iteration
o Compute values for a particular policy: use policy evaluation
o Turn your values into a policy: use policy extraction (one-step lookahead)

o These all look the same!


o They basically are – they are all variations of Bellman updates
o They all use one-step lookahead expectimax fragments
o They differ only in whether we plug in a fixed policy or max over actions
The Bellman Equations

How to be optimal:
Step 1: Take correct first action

Step 2: Keep being optimal


Double Bandits
Double-Bandit MDP
o Actions: Blue, Red No discount
o States: Win, Lose 100 time steps
0.25 $0
Both states have
the same value
0.75
$2
W 0.25 L
$0
$1 $1
0.75 $2
1.0 1.0
Offline Planning
o Solving MDPs is offline planning No discount
o You determine all quantities through computation 100 time steps
o You need to know the details of the MDP Both states have
the same value
o You do not actually play the game!

0.25 $0
Value
0.75
W $2 0.25 L
Play Red 150 $0
$1 $1
0.75 $2
Play Blue 100 1.0 1.0
Let’s Play!

$2 $2 $0 $2 $2
$2 $2 $0 $0 $0
Online Planning
o Rules changed! Red’s win chance is different.

?? $0

??
$2
W ?? L
$0
$1 $1
?? $2
1.0 1.0
Let’s Play!

$0 $0 $0 $2 $0
$2 $0 $0 $0 $0
What Just Happened?
o That wasn’t planning, it was learning!
o Specifically, reinforcement learning
o There was an MDP, but you couldn’t solve it with just computation
o You needed to actually act to figure it out

o Important ideas in reinforcement learning that came up


o Exploration: you have to try unknown actions to get information
o Exploitation: eventually, you have to use what you know
o Regret: even if you learn intelligently, you make mistakes
o Sampling: because of chance, you have to try things repeatedly
o Difficulty: learning can be much harder than solving a known MDP
Next Time: Reinforcement Learning!

You might also like