0% found this document useful (0 votes)
5 views123 pages

Markov Decision Processes: Ppts by Dan Klein and Pieter Abbeel For Cs188 Intro To Ai at Uc Berkeley

AI Markov decision problem explanation in details

Uploaded by

Abhishek Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views123 pages

Markov Decision Processes: Ppts by Dan Klein and Pieter Abbeel For Cs188 Intro To Ai at Uc Berkeley

AI Markov decision problem explanation in details

Uploaded by

Abhishek Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 123

Markov Decision Processes

PPTs by Dan Klein and Pieter Abbeel for CS188 Intro to AI at UC Berkeley.
Non-Deterministic Search
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 each time step
▪ Small “living” reward each step (can be negative)
▪ Big rewards come at the end (good or bad)
▪ Goal: maximize sum of rewards
Grid World Actions
Deterministic Grid World Stochastic Grid World
Markov Decision Processes
▪ An MDP is defined by:
▪ A set of states s ∈ S
▪ A set of actions a ∈ A
▪ A transition function T(s, a, s’)
▪ Probability that a from s leads to s’, i.e., P(s’| s, a)
▪ Also called the model or the dynamics
▪ A reward function R(s, a, s’)
▪ Sometimes just R(s) or R(s’)
▪ A start state
▪ Maybe a terminal state

▪ MDPs are non-deterministic search problems


▪ One way to solve them is with expectimax search
▪ We’ll have a new tool soon

[Demo – gridworld manual intro (L8D1)]


Video of Demo Gridworld Manual Intro
What is Markov about MDPs?
▪ “Markov” generally means that given the present state, the
future and the past are independent

▪ For Markov decision processes, “Markov” means action


outcomes depend only on the current state

Andrey Markov
(1856-1922)

▪ This is just like search, where the successor function could only
depend on the current state (not the history)
Policies
▪ In deterministic single-agent search problems,
we wanted an optimal plan, or sequence of
actions, from start to a goal

▪ For MDPs, we want an optimal policy π*: S → A


▪ A policy π gives an action for each state
▪ An optimal policy is one that maximizes
expected utility if followed
▪ An explicit policy defines a reflex agent
Optimal policy when R(s, a, s’) = -0.03
▪ Expectimax didn’t compute entire policies for all non-terminals s
▪ It computed the action for a single state only
Optimal Policies

R(s) = -0.01 R(s) = -0.03

R(s) = -0.4 R(s) = -2.0


Example: Racing
Example: Racing
▪ A robot car wants to travel far, quickly
▪ Three states: Cool, Warm, Overheated
▪ Two actions: Slow, Fast
▪ Going faster gets double reward 0.5 +1
1.0
Fast
Slow -10
+1
0.5

Warm
Slow

Fast 0.5 +2

Cool 0.5
+1 Overheated
1.0
+2
Racing Search Tree
MDP Search Trees
▪ Each MDP state projects an expectimax-like search tree

s s is a state

(s, a) is a
s, a
q-state
(s,a,s’) called a transition
s,a,s’ T(s,a,s’) = P(s’|s,a)
R(s,a,s’)
’s
Utilities of Sequences
Utilities of Sequences
▪ What preferences should an agent have over reward sequences?

▪ More or less? [1, 2, 2] or [2, 3, 4]

▪ Now or later? [0, 0, 1] or [1, 0, 0]


Discounting
▪ It’s reasonable to maximize the sum of rewards
▪ It’s also reasonable to prefer rewards now to rewards later
▪ One solution: values of rewards decay exponentially

Worth Now Worth Next Step Worth In Two Steps


Discounting
▪ How to discount?
▪ Each time we descend a level, we
multiply in the discount once

▪ Why discount?
▪ Sooner rewards probably do have
higher utility than later rewards
▪ Also helps our algorithms converge

▪ Example: discount of 0.5


▪ U([1,2,3]) = 1*1 + 0.5*2 + 0.25*3
▪ U([1,2,3]) < U([3,2,1])
Stationary Preferences
▪ Theorem: if we assume stationary preferences:

▪ Then: there are only two ways to define utilities


▪ Additive utility:
▪ Discounted utility:
Quiz: Discounting
▪ Given:

▪ Actions: East, West, and Exit (only available in exit states a, e)


▪ Transitions: deterministic

▪ Quiz 1: For γ = 1, what is the optimal policy?

▪ Quiz 2: For γ = 0.1, what is the optimal policy?

▪ Quiz 3: For which γ are West and East equally good when in state d?
Infinite Utilities?!
▪ Problem: What if the game lasts forever? Do we get infinite rewards?
▪ Solutions:
▪ Finite horizon: (similar to depth-limited search)
▪ Terminate episodes after a fixed T steps (e.g. life)
▪ Gives nonstationary policies (π depends on time left)

▪ Discounting: use 0 < γ < 1

▪ Smaller γ means smaller “horizon” – shorter term focus

▪ Absorbing state: guarantee that for every policy, a terminal state will eventually
be reached (like “overheated” for racing)
Recap: Defining MDPs
▪ Markov decision processes: s
▪ Set of states S
▪ Start state s0 a
▪ Set of actions A s, a
▪ Transitions P(s’|s,a) (or T(s,a,s’))
▪ Rewards R(s,a,s’) (and discount γ) s,a,s’
’s

▪ MDP quantities so far:


▪ Policy = Choice of action for each state
▪ Utility = sum of (discounted) rewards
Solving MDPs
Optimal Quantities

▪ The value (utility) of a state s:


V*(s) = expected utility starting in s and s s is a
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 and s,a,s’ (s,a,s’) is a
(thereafter) acting optimally ’s transition

▪ The optimal policy:


π*(s) = optimal action from state s

[Demo – gridworld values (L8D4)]


Snapshot of Demo – Gridworld V Values

Noise = 0
Discount = 1
Living reward = 0
Snapshot of Demo – Gridworld Q Values

Noise = 0
Discount = 1
Living reward = 0
Snapshot of Demo – Gridworld V Values

Noise = 0.2
Discount = 1
Living reward = 0
Snapshot of Demo – Gridworld Q Values

Noise = 0.2
Discount = 1
Living reward = 0
Snapshot of Demo – Gridworld V Values

Noise = 0.2
Discount = 0.9
Living reward = 0
Snapshot of Demo – Gridworld Q Values

Noise = 0.2
Discount = 0.9
Living reward = 0
Snapshot of Demo – Gridworld V Values

Noise = 0.2
Discount = 0.9
Living reward = -0.1
Snapshot of Demo – Gridworld Q Values

Noise = 0.2
Discount = 0.9
Living reward = -0.1
Values of States
▪ Fundamental operation: compute the (expectimax) value of a state
▪ Expected utility under optimal action
s
▪ Average sum of (discounted) rewards
▪ This is just what expectimax computed! a
s, a
▪ Recursive definition of value:
s,a,s’
’s
Racing Search Tree
Racing Search Tree
Racing Search Tree
▪ We’re doing way too much
work with expectimax!

▪ Problem: States are repeated


▪ Idea: Only compute needed
quantities once

▪ Problem: Tree goes on forever


▪ Idea: Do a depth-limited
computation, but with increasing
depths until change is small
▪ Note: deep parts of the tree
eventually don’t matter if γ < 1
Time-Limited Values
▪ Key idea: time-limited values

▪ Define Vk(s) to be the optimal value of s if the game ends


in k more time steps

▪ Equivalently, it is what a depth-k expectimax would give from s

[Demo – time-limited values (L8D6)]


Noise = 0.2
Discount = 0.9
Living reward = 0

Consider Grid world: Sates are presented


as (Row, Colum)

Possible actions at each state: Move one


step in either North, South, East, West
k=0
Noise = 0.2
Discount = 0.9
Living reward = 0

For K=0, V0(S) is optimal value of a state


S, if game ends in zero time steps

i.e. No time to get any expected reward


thus zero utility (value)

Therefore, at k=0, every state has 0 value


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
Computing Time-Limited Values
Value Iteration
Value Iteration
▪ Start with V0(s) = 0: No time steps left means an Vk+1(s)
expected reward sum of zero
a

▪ Given vector of Vk(s) values, s, a

s,a,s’
▪ Do one ply of expectimax from every state: Vk(s’)

▪ Repeat until convergence


Value Iteration

▪ Complexity of each iteration: O(S2A) Vk+1(s)

▪ Theorem: will converge to unique optimal values


a
s, a
▪ Basic idea: approximations get refined
towards optimal values s,a,s’
▪ Policy may converge long before values do Vk(s’)
Example: Value Iteration

Initially : V0(s) = 0: No time steps left means an expected reward sum of zero

0 0 0

States
Cool Warm Overheated
Example: Value Iteration
Now, Calculate V1(s)

Using value update equation:

Assume no discount! i.e. γ = 1

Available actions in various states:

Cool: Slow, Fast; Warm: Slow, Fast; Overheated: None

0 0 0

States
Cool Warm Overheated
Example: Value Iteration
Example: Value Iteration
Example: Value Iteration
Example: Value Iteration
Example: Value Iteration
Example: Value Iteration
Example: Value Iteration
Example: Value Iteration

2 1 0

0 0 0

States
Cool Warm Overheated
Example: Value Iteration
Example: Value Iteration
Example: Value Iteration
Example: Value Iteration
Example: Value Iteration
Example: Value Iteration
Example: Value Iteration

As we assume no discount i.e. γ = 1


Value updates will continue for ever (will not
3.5 2.5 0 converse)

2 1 0

0 0 0

States
Cool Warm Overheated
Example: Value Iteration

However, if . γ < 1
It will converse.
3.5 2.5 0
Stopping Criteria: When states values become
stable i.e. almost no change in value for next
time step.
2 1 0

0 0 0

States
Cool Warm Overheated
Noise = 0.2
Discount = 0.9
Living reward = 0

Consider Grid world: Sates are presented


as (Row, Colum)

Possible actions at each state: Move one


step in either North, South, East, West
k=0
Noise = 0.2
Discount = 0.9
Living reward = 0

For k = 0, V0(S) is optimal value of a state


S, if game ends in zero time steps

i.e. No time to get any expected reward


thus zero utility (value)

Therefore, at k = 0, every state has 0 value


k=1
Value update of states after 1 time-step:
For k = 1, V1(S)

In one time-step (k = 1): There is NO reward to get


for any states, except states (1, 3) and (2, 3),

In state (1, 3) robot gets -1 reward and exit the game,

In state (2, 3) robot gets +1 reward and exit the game.


k=1

(2, 0)
(2, 0)
k=1 (2, 0) (2, 1)

(1 0)

(2, 0)
k=1 (2, 0) (2, 1)

(1 0)

(2, 0)
k=1 (2, 0) (2, 1)

(1 0)

(2, 0)
k=1 (2, 0) (2, 1)

(1 0)

(2, 0)
k=1 (2, 0) (2, 1)

(1 0)

(2, 0)
k=1

(2, 2)
(2, 2)
k=1 (2, 1) (2, 2) (2, 3)

(1, 2)

(2, 0)
k=1 (2, 1) (2, 2) (2, 3)

(1, 2)

(2, 0)
k=1 (2, 1) (2, 2) (2, 3)

(1, 2)

(2, 0)
k=1 (2, 1) (2, 2) (2, 3)

(1, 2)

(2, 0)
k=1 (2, 1) (2, 2) (2, 3)

(1, 2)

(2, 0)
k=1
Value update of states after 1 time-step:
For k = 1, V1(S)

For both Sates (1, 3) and (2, 3): Only action available
is (2, 2)

Available action: Exit

Thus, No need to calculate Q values as no uncertainty.

V1 ((1, 3)) = -1 and V1 ((2, 3)) = +1


k=2

(2, 0)
k=2

(2, 0)
k=2

(2, 0)
k=2

(2, 0)
k=2

(2, 0)
k=2

(2, 0)
k=2

(2, 2)
k=2 (2, 1)

(2, 0)
k=2 (2, 1)

(2, 0)
k=2

(2, 0)
k=2

(2, 0)
k=2

(2, 0)
k=2

(1, 2)
k=2

(2, 0)
k=2

(2, 0)
k=2

(2, 0)
k=2

(2, 0)
k=2

(2, 0)
k=2
Value update of states after 1 time-step:
For k = 2, V2(S)

For both Sates (1, 3) and (2, 3): Only action available
is (2, 2)

Available action: Exit

Thus, No need to calculate Q values as no uncertainty.

V2 ((1, 3)) = -1 and V2 ((2, 3)) = +1


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
Convergence*
▪ How do we know the Vk vectors are going to converge?

▪ Case 1: If the tree has maximum depth M, then VM holds


the actual untruncated values

▪ Case 2: If the discount is less than 1


▪ Sketch: For any state Vk and Vk+1 can be viewed as depth
k+1 expectimax results in nearly identical search trees
▪ The difference is that on the bottom layer, Vk+1 has actual
rewards while Vk has zeros
▪ That last layer is at best all RMAX
▪ It is at worst RMIN
▪ But everything is discounted by γk that far out
▪ So Vk and Vk+1 are at most γk max|R| different
▪ So as k increases, the values converge

You might also like