1CS 188: Artificial IntelligenceFall 2007Lecture 10: MDPs9/27/2007Dan Klein – UC BerkeleyMarkov 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’) Prob that a from s leads to s’ i.e., P(s’ | s,a) Also called the model A reward function R(s, a, s’) Sometimes just R(s) or R(s’) A start state (or distribution) Maybe a terminal state MDPs are a family of non-deterministic search problems Reinforcement learning: MDPswhere we don’t know the transition or reward functions2Example: High-Low Three card types: 2, 3, 4 Infinite deck, twice as many 2’s Start with 3 showing After each card, you say “high” or “low” New card is flipped If you’re right, you win the points shown on the new card Ties are no-ops If you’re wrong, game ends Differences from expectimax: #1: get rewards as you go #2: you might play forever!2324High-Low States: 2, 3, 4, done Actions: High, Low Model: T(s, a, s’): P(s’=done | 4, High) = 3/4 P(s’=2 | 4, High) = 0 P(s’=3 | 4, High) = 0 P(s’=4 | 4, High) = 1/4 P(s’=done | 4, Low) = 0 P(s’=2 | 4, Low) = 1/2 P(s’=3 | 4, Low) = 1/4 P(s’=4 | 4, Low) = 1/4 … Rewards: R(s, a, s’): Number shown on s’ if s ≠ s’ 0 otherwise Start: 3Note: could choose actions with search. How?43Example: High-Low3HighLow243High LowHigh LowHighLow3, High, Low3T = 0.5, R = 2T = 0.25, R = 3T = 0, R = 4T = 0.25, R = 0MDP Search Trees Each MDP state gives an expectimax-like search treeass’s, a(s,a,s’) called a transitionT(s,a,s’) = P(s’|s,a)R(s,a,s’)s,a,s’s is a state(s, a) is a q-state4Utilities of Sequences In order to formalize optimality of a policy, need to understand utilities of sequences of rewards Typically consider stationary preferences: Theorem: only two ways to define stationary utilities Additive utility: Discounted utility:Assuming that reward depends only on state for these slides!Infinite Utilities?! Problem: infinite sequences with infinite rewards Solutions: Finite horizon: Terminate after a fixed T steps Gives nonstationary policy (π depends on time left) Absorbing state(s): guarantee that for every policy, agent will eventually “die” (like “done” for High-Low) Discounting: for 0 < γ < 1 Smaller γ means smaller “horizon” – shorter term focus5Discounting Typically discount rewards by γ < 1 each time step Sooner rewards have higher utility than later rewards Also helps the algorithms convergeEpisodes and Returns An epsiode is a run of an MDP Sequence of transitions (s,a,s’) Starts at start state Ends at terminal state (if it ends) Stochastic! The utility, or return, of an epsiode The discounted sum of the rewards6Utilities under Policies Fundamental operation: compute the utility of a state s Define the value (utility) of a state s, under a fixed policy π:Vπ(s) = expected return starting in s and following π Recursive relation (one-step look-ahead):π(s)ss, π(s)s,a,s’s’Policy Evaluation How do we calculate values for a fixed policy? Idea one: it’s just a linear system, solve with Matlab (or whatever) Idea two: turn recursive equations into updates Viπ(s) = expected returns over the next i transitions while following πEquivalent to doing depth i search and plugging in zero at leavesπ(s)ss, π(s)s,a,s’s’7Example: High-Low Policy: always say “high” Iterative updates:[DEMO]Q-Functions Also, define a q-value, for a state and action (q-state) Qπ(s) = expected return starting in s, taking action a and following π thereafterass, as,a,s’s’8Recap: MDP Quantities Return = Sum of futurediscounted rewardsin one episode(stochastic) V: Expected return from a state under a policy Q: Expected return from a q-state under a policyass, as,a,s’s’Optimal Utilities Fundamental operation: compute the optimal utilities of states s Define the utility of a state s:V*(s) = expected return starting in s and acting optimally Define the utility of a q-state (s,a):Q*(s) = expected return starting in s, taking action a and thereafter acting optimally Define the optimal policy:π*(s) = optimal action from state sass, as,a,s’s’9The Bellman Equations Definition of utility leads to a simple relationship amongst optimal utility values:Optimal rewards = maximize over first action and then follow optimal policy Formally:ass, as,a,s’s’Solving MDPs We want to find the optimal policy π Proposal 1: modified expectimax search:ass, as,a,s’s’10MDP Search Trees? Problems: This tree is usually infinite (why?) The same states appear over and over (why?) There’s actually one tree per state (why?) Ideas: Compute to a finite depth (like expectimax) Consider returns from sequences of increasing length Cache values so we don’t repeat workValue Estimates Calculate estimates Vk*(s) Not the optimal value of s! The optimal value considering only next k time steps (k rewards) As k → ∞, it approaches the optimal value Why: If discounting, distant rewards become negligible If terminal states reachable from everywhere, fraction of episodes not ending becomes negligible Otherwise, can get infinite expected utility and then this approach actually won’t work11Memoized Recursion? Recurrences: Cache all function call results so you never repeat work What happened to the evaluation function?Value Iteration Problems with the recursive computation: Have to keep all the Vk*(s) around all the time Don’t know which depth πk(s) to ask for when planning Solution: value iteration Calculate values for all states, bottom-up Keep increasing k until convergence12Value Iteration Idea: Start with V0*(s) = 0, which we know is right (why?) Given Vi*, calculate the values for all states for depth i+1: This is called a value update or Bellman update Repeat until convergence Theorem: will converge to unique optimal values Basic idea: approximations get refined towards optimal values Policy may converge long before values doExample: Bellman Updates13Example: Value Iteration Information propagates outward from terminal states and eventually all states have correct value estimates[DEMO]V2V3Convergence*
View Full Document