Quiz 2

Markov Decision Processes & Bellman Equations

962 words
5 min read
Python Week 1: the first filter for runtime behavior
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, A, P, R, \gamma):
  • SS: Set of states
  • AA: Set of actions
  • P(ss,a)P(s'|s,a): Transition probability to state s' after action a in state s
  • R(s,a,s)R(s,a,s'): Reward received after transitioning
  • γ[0,1]\gamma \in [0,1]: Discount factor (Diagram) Markov Property: The future is independent of the past given the present:
P(St+1St,At)=P(St+1S1,A1,...,St,At)P(S_{t+1} | S_t, A_t) = P(S_{t+1} | S_1, A_1, ..., S_t, A_t)

1.2 Returns and Discounting

The return GtG_t is the discounted cumulative reward:
Gt=Rt+1+γRt+2+γ2Rt+3+...=k=0γkRt+k+1G_t = R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + ... = \sum_{k=0}^\infty \gamma^k R_{t+k+1}
Why discount?
  1. Mathematical convenience: Infinite sums converge
  2. Uncertainty: Future rewards are uncertain
  3. Human preference: We prefer immediate rewards
  4. Avoids infinite loops (in continuing tasks)

1.3 Value Functions

State-value function Vπ(s)V^\pi(s): Expected return starting from state s following policy π\pi
Vπ(s)=Eπ[GtSt=s]V^\pi(s) = \mathbb{E}_\pi[G_t | S_t = s]
Action-value function Qπ(s,a)Q^\pi(s,a): Expected return starting from state s, taking action a, then following policy π\pi
Qπ(s,a)=Eπ[GtSt=s,At=a]Q^\pi(s,a) = \mathbb{E}_\pi[G_t | S_t = s, A_t = a]

1.4 Bellman Expectation Equation

For a given policy π\pi:
Vπ(s)=aπ(as)s,rP(s,rs,a)[r+γVπ(s)]V^\pi(s) = \sum_a \pi(a|s) \sum_{s',r} P(s',r|s,a)[r + \gamma V^\pi(s')] Qπ(s,a)=s,rP(s,rs,a)[r+γaπ(as)Qπ(s,a)]Q^\pi(s,a) = \sum_{s',r} P(s',r|s,a)[r + \gamma \sum_{a'} \pi(a'|s') Q^\pi(s',a')]

1.5 Bellman Optimality Equation

The optimal value function VV^* gives the maximum return attainable:
V(s)=maxas,rP(s,rs,a)[r+γV(s)]V^*(s) = \max_a \sum_{s',r} P(s',r|s,a)[r + \gamma V^*(s')] Q(s,a)=s,rP(s,rs,a)[r+γmaxaQ(s,a)]Q^*(s,a) = \sum_{s',r} P(s',r|s,a)[r + \gamma \max_{a'} Q^*(s',a')]
The optimal policy π\pi^* can be derived greedily from QQ^*:
π(s)=argmaxaQ(s,a)\pi^*(s) = \arg\max_a Q^*(s,a)

1.6 Worked Example: Grid World

Consider a 2×2 grid with 4 states S = {A, B, C, D}:
pseudo
A → 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 VV^* using Bellman optimality: V(D)=0V^*(D) = 0 (terminal) V(B)=max{0.9×V(D),1+0.9×V(D)}=max{0,1}=0V^*(B) = \max\{0.9 \times V^*(D), -1 + 0.9 \times V^*(D)\} = \max\{0, -1\} = 0 (Right is optimal) V(C)=max{0.9×V(D),1+0.9×V(D)}=max{0,1}=0V^*(C) = \max\{0.9 \times V^*(D), -1 + 0.9 \times V^*(D)\} = \max\{0, -1\} = 0 (Right is optimal) V(A)=max{0.9×V(B),0.9×V(C)}=max{0,0}=0V^*(A) = \max\{0.9 \times V^*(B), 0.9 \times V^*(C)\} = \max\{0, 0\} = 0 (tie, either action)

📝 Practice Questions

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 = 10
V(1) = 5 + 0.9 × V(2) = 5 + 0.9 × 10 = 5 + 9 = 14
So 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 = 10
With 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)=maxaP[r+γVk(s)]V_{k+1}(s) = \max_a \sum P[r + \gamma V_k(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π[GtSt=s]V^\pi(s) = \mathbb{E}_\pi[G_t | S_t = s] Qπ(s,a)=Eπ[GtSt=s,At=a]Q^\pi(s,a) = \mathbb{E}_\pi[G_t | S_t = s, A_t = a]
The relationship: Vπ(s)=aπ(as)Qπ(s,a)V^\pi(s) = \sum_a \pi(a|s) Q^\pi(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,rP(s,rs,a)[r+γVπ(s)]Q^\pi(s,a) = \sum_{s',r} P(s',r|s,a)[r + \gamma V^\pi(s')]
The value of taking action a in state s is the immediate reward plus the discounted value of the next state.
</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)
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.