Markov Decision Processes & Bellman Equations
962 words
5 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Markov Decision Processes & Bellman Equations ## ๐ฏ Learning Objectives - Formalize RL problems as MDPs - Understand the Markov property and its implications - Derive Bellman expectation and optimality equations - Implement value and action-value function estimation ## ๐ Prerequisites - Probability (conditional p...

Markov Decision Processes & Bellman Equations
๐ฏ Learning Objectives
- Formalize RL problems as MDPs
- Understand the Markov property and its implications
- Derive Bellman expectation and optimality equations
- Implement value and action-value function estimation
๐ Prerequisites
- Probability (conditional probability, expectation)
- Dynamic programming concepts
1. ๐ Core Content
1.1 The Agent-Environment Interface
An MDP is defined by the tuple (S,A,P,R,ฮณ):
- S: Set of states
- A: Set of actions
- P(sโฒโฃs,a): Transition probability to state s' after action a in state s
- R(s,a,sโฒ): Reward received after transitioning
- ฮณโ[0,1]: Discount factor (Diagram) Markov Property: The future is independent of the past given the present:
1.2 Returns and Discounting
The return Gtโ is the discounted cumulative reward:
Why discount?
- Mathematical convenience: Infinite sums converge
- Uncertainty: Future rewards are uncertain
- Human preference: We prefer immediate rewards
- Avoids infinite loops (in continuing tasks)
1.3 Value Functions
State-value function Vฯ(s): Expected return starting from state s following policy ฯ
Action-value function Qฯ(s,a): Expected return starting from state s, taking action a, then following policy ฯ
1.4 Bellman Expectation Equation
For a given policy ฯ:
1.5 Bellman Optimality Equation
The optimal value function Vโ gives the maximum return attainable:
The optimal policy ฯโ can be derived greedily from Qโ:
1.6 Worked Example: Grid World
Consider a 2ร2 grid with 4 states S = {A, B, C, D}:
pseudoA โ B โ โ C โ D
Actions: {Right, Down}, ฮณ=0.9
- From A: Right โ B (R=0), Down โ C (R=0)
- From B: Right โ D (R=0), Down โ D (R=+1)
- From C: Right โ D (R=0), Down โ D (R=+1)
- From D: Terminal (no further reward) Let's compute Vโ using Bellman optimality: Vโ(D)=0 (terminal) Vโ(B)=max{0.9รVโ(D),โ1+0.9รVโ(D)}=max{0,โ1}=0 (Right is optimal) Vโ(C)=max{0.9รVโ(D),โ1+0.9รVโ(D)}=max{0,โ1}=0 (Right is optimal) Vโ(A)=max{0.9รVโ(B),0.9รVโ(C)}=max{0,0}=0 (tie, either action)
๐ Practice Questions
</details> * * * ## ๐ Cross-References - **Next**: [Dynamic Programming](/notes/04-degree-electives-bsda5007-reinforcement-learning-week03-03-dynamic-programming) - **Previous**: [Multi-Armed Bandits](/notes/04-degree-electives-bsda5007-reinforcement-learning-week01-01-multi-armed-bandits) - **Video**: BSDA5007 Week 2 transcripts [Join Discord](https://discord.gg/gE2m4Qrdqv) [Previous**Multi-Armed Bandits**](/notes/04-degree-electives-bsda5007-reinforcement-learning-week01-01-multi-armed-bandits)[Next**Dynamic Programming**](/notes/04-degree-electives-bsda5007-reinforcement-learning-week03-03-dynamic-programming)Q1<strong>Q1</strong>: In a 3-state MDP, transitioning from state 1 gives reward +5 and goes to state 2. State 2 gives reward +10 and goes to state 3 (terminal). ฮณ=0.9. Compute V(1) and V(2).V(3) = 0 (terminal)V(2) = 10 + 0.9 ร V(3) = 10 + 0 = 10V(1) = 5 + 0.9 ร V(2) = 5 + 0.9 ร 10 = 5 + 9 = 14So V*(1) = 14 (assuming only one action per state). The agent should expect total discounted return of 14 starting from state 1. Q2<strong>Q2<strong>Q2</strong>: If ฮณ=0.5 instead of 0.9, how do the values change? What does this tell us?V(2) = 10 + 0.5 ร 0 = 10 (same โ value of future is already 0) V(1) = 5 + 0.5 ร 10 = 5 + 5 = 10With lower ฮณ: V(1) drops from 14 to 10. This shows that lower discount factors make the agent value immediate rewards more. With ฮณ=0.5, the reward from state 1 (5) contributes more to V(1) than the delayed reward from state 2 (10 ร 0.5 = 5).ฮณ close to 1: far-sighted agent ฮณ close to 0: short-sighted agent Q3<strong>Q3<strong>Q3<strong>Q3<strong>Q3</strong>: Why is the Bellman equation a "self-consistency" condition?The Bellman equation expresses a recursive relationship:
- V(s) = immediate reward + discounted V(next state)
- But V(next state) depends on V(state after that), and so on
This is self-consistency because the value of a state must equal its own definition. It's not a computational formula (you can't compute V(s) from V(s') without knowing V(s') first) โ it's a condition that the true value function must satisfy.The Bellman equation becomes useful when turned into an update rule: Vk+1โ(s)=maxaโโP[r+ฮณVkโ(sโฒ)]This iterative approach converges to the true V*. Q4<strong>Q4<strong>Q4<strong>Q4<strong>Q4<strong>Q4</strong>: Derive the relationship between V^ฯ and Q^ฯ.By definition: Vฯ(s)=Eฯโ[GtโโฃStโ=s] Qฯ(s,a)=Eฯโ[GtโโฃStโ=s,Atโ=a]The relationship: Vฯ(s)=โaโฯ(aโฃs)Qฯ(s,a)The value of a state under policy ฯ is the weighted average of action-values, weighted by the probability of taking each action under ฯ.Conversely: Qฯ(s,a)=โsโฒ,rโP(sโฒ,rโฃs,a)[r+ฮณVฯ(sโฒ)]The value of taking action a in state s is the immediate reward plus the discounted value of the next state.