Markov Decision Processes (MDPs)

GATE Relevance: High

🎯 Learning Objectives

  • Understand the agent-environment interaction loop in reinforcement learning
  • Define an MDP formally as a tuple (S, A, P, R, γ)
  • Explain the Markov property and why it simplifies decision-making
  • Derive the Bellman expectation equations for Vπ and Qπ
  • Write down the Bellman optimality equations for V* and Q*
  • Compute returns and value functions on small grid-world examples

1. The Reinforcement Learning Framework

Reinforcement Learning (RL) is a computational approach to learning from interaction. Unlike supervised learning where labelled examples are provided, an RL agent must discover good behaviour through trial and error, receiving numerical reward signals from the environment.

📚 Reinforcement Learning

An agent interacts with an environment over a sequence of discrete time steps t = 0, 1, 2, … At each step t the agent:

  1. Observes the current state St ∈ S
  2. Selects an action At ∈ A(St)
  3. Receives a reward Rt+1 ∈ ℜ
  4. Transitions to a new state St+1

This creates a trajectory: S0, A0, R1, S1, A1, R2, S2, …

💡 Key Insight

The agent’s goal is not to maximise immediate reward but to maximise the cumulative reward over time. This creates the fundamental trade-off between exploration (trying new actions) and exploitation (using known good actions).

2. The Markov Property

📚 Markov Property

A state St is Markov if and only if:

P(St+1 | St) = P(St+1 | S1, S2, …, St)

The future depends only on the current state, not on the history of states that preceded it. The state captures all relevant information from the past.

The Markov property is a critical simplifying assumption. It means we don’t need to remember the entire history of interactions — the current state is a sufficient statistic for predicting what happens next.

📝 Example: Chess as a Markov Process

The current board position in chess is Markov — knowing the current position of all pieces is sufficient to determine all legal moves and evaluate the position. The sequence of moves that led to this position doesn’t matter for future play (ignoring draw-by-repetition rules).

3. Formal MDP Definition

📚 Markov Decision Process (MDP)

An MDP is a 5-tuple ⟨S, A, P, R, γ⟩ where:

  • S — a finite set of states
  • A — a finite set of actions (or A(s) for state-dependent actions)
  • P — transition function: P(s′ | s, a) = probability of reaching state s′ from state s by taking action a
  • R — reward function: R(s, a, s′) = immediate reward received after transitioning from s to s′ via action a
  • γ ∈ [0, 1] — discount factor

3.1 Transition Function

The transition function P defines the dynamics of the environment. For any state s ∈ S and action a ∈ A:

∑s′ ∈ S P(s′ | s, a) = 1

This means from any state-action pair, the probabilities of transitioning to all possible next states must sum to 1.

3.2 Reward Function

The reward function can take several forms depending on the formulation:

  • R(s, a, s′) — depends on current state, action, and next state
  • R(s, a) — depends only on current state and action (expected over next states)
  • R(s) — depends only on the current state

3.3 Discount Factor γ

⚠ Why Do We Need Discounting?

  • Mathematical convenience: Ensures the infinite sum of rewards converges (for γ < 1)
  • Economic interpretation: A reward now is worth more than the same reward in the future
  • Uncertainty: The agent may not survive forever; γ can model the probability of continuing
  • γ = 0: Myopic agent — only cares about immediate reward
  • γ = 1: Far-sighted agent — all future rewards weighted equally (only valid for episodic tasks)

📝 Example: Simple 3-State MDP

Consider an MDP with S = {s1, s2, s3}, A = {a, b}, and γ = 0.9:

From StateActionTo StateP(s′|s,a)R(s,a,s′)
s1as10.2+5
s1as20.8+10
s1bs31.0−1
s2as10.5+2
s2as20.5+2
s3as31.00

Here s3 is a terminal/absorbing state with zero reward.

4. Return (Cumulative Reward)

📚 Return Gt

The return Gt is the total discounted reward from time step t onward:

Gt = Rt+1 + γRt+2 + γ²Rt+3 + … = ∑k=0∞ γk Rt+k+1

A key recursive relationship that is fundamental to all RL algorithms:

Gt = Rt+1 + γ Gt+1

📝 Worked Example: Computing Return

Suppose γ = 0.5 and a trajectory gives rewards: R1=2, R2=3, R3=5, R4=1 (then terminal).

G0 = 2 + 0.5×3 + 0.25×5 + 0.125×1 = 2 + 1.5 + 1.25 + 0.125 = 4.875

G1 = 3 + 0.5×5 + 0.25×1 = 3 + 2.5 + 0.25 = 5.75

Verify recursion: G0 = R1 + γ G1 = 2 + 0.5 × 5.75 = 2 + 2.875 = 4.875 ✅

5. Policy π

📚 Policy

A policy π defines the agent’s behaviour. It is a mapping from states to actions (or distributions over actions).

  • Deterministic policy: π(s) = a — maps each state to a single action
  • Stochastic policy: π(a | s) = P(At = a | St = s) — gives a probability distribution over actions for each state

The goal of RL is to find an optimal policy π* that maximises the expected return from every state.

6. Value Functions

6.1 State-Value Function Vπ(s)

📚 State-Value Function

The state-value function Vπ(s) gives the expected return starting from state s and following policy π:

Vπ(s) = Eπ[Gt | St = s] = Eπ[∑k=0∞ γk Rt+k+1 | St = s]

6.2 Action-Value Function Qπ(s, a)

📚 Action-Value Function

The action-value function Qπ(s, a) gives the expected return starting from state s, taking action a, then following policy π:

Qπ(s, a) = Eπ[Gt | St = s, At = a]

6.3 Relationship between V and Q

Vπ(s) = ∑a ∈ A π(a | s) · Qπ(s, a)

The value of a state is the weighted average of Q-values, weighted by the policy’s action probabilities.

7. Bellman Expectation Equations

🔧 Bellman Expectation Equation for Vπ

Vπ(s) = ∑a π(a|s) ∑s′ P(s′|s,a) [R(s,a,s′) + γ Vπ(s′)]

The value of state s under policy π equals the expected immediate reward plus the discounted value of the next state, averaged over all actions and transitions.

🔧 Bellman Expectation Equation for Qπ

Qπ(s,a) = ∑s′ P(s′|s,a) [R(s,a,s′) + γ ∑a′ π(a′|s′) Qπ(s′,a′)]

💡 Backup Diagrams

The Bellman equations can be visualised as backup diagrams showing how value information flows backward from successor states. For Vπ, the diagram has a state node at the top, branching into action nodes (weighted by π), each branching into next-state nodes (weighted by P), which connect back to state values.

📝 Worked Example: Bellman Equation on a 2×2 Grid

Consider a 2×2 grid world with states {(0,0), (0,1), (1,0), (1,1)}. The goal is (1,1) with reward +10. All other transitions give reward −1. γ = 0.9. The agent moves deterministically in the chosen direction (up, down, left, right) and stays in place if hitting a wall.

Under a uniform random policy π(a|s) = 0.25 for each action, the Bellman equation for state (0,0):

Vπ(0,0) = 0.25 × [−1 + 0.9·Vπ(0,0)]  (hit wall, stay)
    + 0.25 × [−1 + 0.9·Vπ(0,1)]  (move right)
    + 0.25 × [−1 + 0.9·Vπ(1,0)]  (move down)
    + 0.25 × [−1 + 0.9·Vπ(0,0)]  (hit wall, stay)

This gives a system of 4 linear equations in 4 unknowns that can be solved simultaneously.

8. Optimal Value Functions & Bellman Optimality Equations

📚 Optimal Value Functions

The optimal state-value function V*(s) gives the maximum expected return achievable from state s over all policies:

V*(s) = maxπ Vπ(s),   ∀ s ∈ S

The optimal action-value function Q*(s,a):

Q*(s,a) = maxπ Qπ(s,a),   ∀ s ∈ S, a ∈ A

🔧 Bellman Optimality Equation for V*

V*(s) = maxa ∈ A ∑s′ P(s′|s,a) [R(s,a,s′) + γ V*(s′)]

The optimal value of a state is the value of the best action from that state.

🔧 Bellman Optimality Equation for Q*

Q*(s,a) = ∑s′ P(s′|s,a) [R(s,a,s′) + γ maxa′ Q*(s′,a′)]

💡 Why Are Bellman Optimality Equations Non-Linear?

Unlike the Bellman expectation equations (which are linear for a fixed π), the optimality equations contain a max operator, making them non-linear. This means they generally cannot be solved in closed form and require iterative methods like value iteration or policy iteration.

Once V* is known, the optimal policy is extracted greedily:

π*(s) = argmaxa ∑s′ P(s′|s,a) [R(s,a,s′) + γ V*(s′)]

Once Q* is known, the optimal policy is even simpler:

π*(s) = argmaxa Q*(s,a)

9. Complete Worked Example: 3×3 Grid World

📝 Grid World Setup

A 3×3 grid world with:

  • States: 9 cells labelled (0,0) to (2,2)
  • Actions: {Up, Down, Left, Right}
  • Goal state: (2,2) with reward +1 (terminal)
  • Pit state: (1,1) with reward −1 (terminal)
  • All other transitions: reward −0.04 (living penalty)
  • Transition: deterministic (probability 1.0)
  • Hitting a wall: agent stays in place, still gets −0.04
  • γ = 0.9
Grid layout:
  (0,0) (0,1) (0,2)
  (1,0) [PIT] (1,2)
  (2,0) (2,1) [GOAL]

Optimal policy (intuitive):
  (0,0)→Right  (0,1)→Right  (0,2)→Down
  (1,0)→Up     [PIT]         (1,2)→Down
  (2,0)→Right  (2,1)→Right  [GOAL]

We will solve this MDP using value iteration in the next section. The key insight: the living penalty −0.04 encourages the agent to reach the goal quickly, while the pit provides a negative outcome to avoid.

Summary

  • RL involves an agent learning from interaction with an environment
  • An MDP is defined by ⟨S, A, P, R, γ⟩
  • The Markov property: the future depends only on the current state
  • The return Gt = ∑ γk Rt+k+1 is the total discounted reward
  • A policy π(a|s) maps states to action probabilities
  • Vπ(s) = expected return from s following π; Qπ(s,a) = expected return from (s,a) following π
  • Bellman expectation equations recursively relate values; they are linear for fixed π
  • Bellman optimality equations use max over actions; they are non-linear
  • The optimal policy is greedy w.r.t. V* or Q*

References

  • Sutton & Barto, Reinforcement Learning: An Introduction, Chapter 3
  • Russell & Norvig, AIMA, Chapter 17