Dulranga's Notes
Semester 3Artificial Intelligence

Markov Decision Process

Objective: find a strategy (a policy) that maximizes the expected discounted sum of future rewards

The Markov property

"Markov" generally means that, given the present state, the future and the past are independent. For MDPs, action outcomes depend only on the current state

i.e. The future depends on the past, only through the present.

MDP=(S,  A,  T,  R)\text{MDP} = (S,\; A,\; T,\; R)
ComponentMeaning
SSSet of states
AASet of actions
T(s,a,s′)T(s,a,s')Transition function: probability of reaching s′s' from ss by doing aa
R(s,a,s′)R(s,a,s')Reward function

Rewards & Discounting

Rewarding is the way we influence the agent to do what we want it to do. The entire goal of the agent is to maximize this reward. So we define the task by the reward function

FormMeaningWhen used
R(s)R(s)Reward for being in a stateGrid world slides, e.g. "R(s)=−0.03R(s) = -0.03"
R(s,a)R(s,a)Reward depends on the action takenCosts of actions, such as fuel
R(s,a,s′)R(s,a,s')Depends on the outcome tooMost general form

We also care about getting the reward as quickly as possible. A big reward, sooner is the best. So even if the agent get a big reward later, the reward degrades. We note this using the discount factor γ\gamma. (0≤γ≤10\leq \gamma \leq 1)

Utility

Utility is the total amount of rewards the agent was able to collect by doing the actions and transitioning into different states.

U([r0,r1,r2,… ])=∑t=0∞γtrt,0≤γ≤1U([r_0, r_1, r_2, \dots]) = \sum_{t=0}^{\infty} \gamma^t r_t, \qquad 0 \le \gamma \le 1
with γ=0.5\gamma=0.5
U([3,2,1])=0.50(3)+0.51(2)+0.52(1)=4.25U([3,2,1]) = 0.5^0(3) + 0.5^1(2) + 0.5^2(1) = 4.25
γ\gammaEffective horizonBehavior
01 stepPure greed. Only immediate reward matters.
0.5≈ 2 stepsVery short-sighted
0.9≈ 10 stepsCommon for gridworlds
0.99≈ 100 stepsFar-sighted, but converges more slowly
1∞\inftyNeeds a finite horizon or guaranteed termination

Policy

Plan vs Policy

PlanPolicy
Used inDeterministic searchStochastic problems (MDPs)
FormA fixed sequence: a1,a2,a3,…a_1, a_2, a_3, \dotsA mapping from states to actions
Handles surprises?No. If the world deviates, the plan is useless.Yes. It tells you what to do wherever you end up.

A policy is a mapping from states to actions.

π:S→A\pi: S \to A
  • SS - set of states
  • AA - set of actions
  • π\pi - policy

Deterministic policy

Tells directly what action to take when in a given state. These can be stored in a LUT for a car with a engine temp,

StateAction
CoolFast
WarmSlow
Overheated(terminal, no action)

Stochastic policy

π(a∣s)=P(At=a∣St=s),∑aπ(a∣s)=1\pi(a \mid s) = P(A_t = a \mid S_t = s), \qquad \sum_a \pi(a\mid s) = 1

(out of scope)

Stationary vs. non-stationary

  • Stationary: π(s)\pi(s) doesn't depend on time. With infinite horizon and discounting, the optimal policy is stationary, and this is the case the lecture covers.
  • Non-stationary: πt(s)\pi_t(s) changes with the time step. This is needed for finite horizons. With 1 step left you might take a gamble you'd avoid with 100 steps left.

Policy Evaluation

The process of computing the state-value function VπV^\pi​ for a given policy π\pi.

Vπ(s)=∑s′T(s,π(s),s′)[R(s,π(s),s′)+γVπ(s′)]V^\pi(s) = \sum_{s'} T(s,\pi(s),s')\big[R(s,\pi(s),s') + \gamma V^\pi(s')\big]

Optimal Policy

A policy π\pi is optimal if no other policy does better from any state:

Vπ∗(s)  ≥  Vπ(s)for every state s and every policy π V^{\pi^*}(s) \;\ge\; V^{\pi}(s) \qquad \text{for every state } s \text{ and every policy } \pi

Bellman Equations

  • V∗(s)V^∗(s) is the expected utility starting in ss and acting ==🔵optimally==.
  • Q∗(s,a)Q^∗(s,a) is the expected utility of taking action aa in ss, then acting ==🔵optimally==. The pair (s,a)(s,a) is called a q-state.
  • π∗(s)\pi^*(s) is the optimal action from ss.

These are defined recursively.

V∗(s)=max⁡a∑s′T(s,a,s′)[R(s,a,s′)+γV∗(s′)]Q∗(s,a)=∑s′T(s,a,s′)[R(s,a,s′)+γV∗(s′)]\begin{align*} V^*(s) = \max_a &\sum_{s'} T(s,a,s')\big[R(s,a,s') + \gamma V^*(s')\big] \\ Q^*(s,a) = &\sum_{s'} T(s,a,s')\big[R(s,a,s') + \gamma V^*(s')\big] \end{align*}
Relation between Value function and Q-Value function

Q∗(s)Q^*(s) is the sum of expected utility for taking action aa, and transitioning from ss to s′s' of all the possible states after that action

V∗(s)V^*(s) is the maximum sum of utility that can get from all of the available set of actions

V∗(s)=max⁡aQ∗(s,a)V^*(s) = \max_a Q^*(s,a)

Value Iteration

This is the dynamic programming algorithm used to find the optimal policy.

We iteratively apply values from the previous iteration into the next iteration and so on until we converge into a stable threshold.

V0(s)=0∀sVk+1(s)←max⁡a∑s′T(s,a,s′)[R(s,a,s′)+γ Vk(s′)]∀sV_0(s) = 0 \quad \forall s \\ \\ V_{k+1}(s) \leftarrow \max_a \sum_{s'} T(s,a,s')\Big[R(s,a,s') + \gamma\, V_k(s')\Big] \quad \forall s

Exact Value for V∗(s)V^*(s)

If we know the optimal policy for a given state, we can derive the optimal value for that state easily. Ex: when in State BB, policy always take action GoRight\text{GoRight} GoRight\text{GoRight} has a 20% chance of staying in BB and 80% chance of going to CC now,

V∗(B)=(0.8)[  RGoRight+γ  V∗(C)]+(0.2)[  Rstay+γ  V∗(B)]V^*(B) = (0.8)[\;R_\text{GoRight} + \gamma \; V^*(C)] + (0.2)[\;R_{\text{stay}} + \gamma \; V^*(B)]

If we know V∗(C)V^*(C), we can compute exact value for V∗(B)V^*(B)

On this page