In supervised learning, an external teacher provides the algorithm with ground-truth target labels. In Reinforcement Learning (RL), there is no supervisor. An autonomous Agent learns optimal behavior through trial-and-error interaction with a dynamic Environment, receiving scalar Reward Signals that reinforce beneficial actions and penalize detrimental ones.
Figure 35.1: The Reinforcement Learning Interaction Cycle — Agent Actions (A_t), Environmental State Transitions (S_{t+1}), and Scalar Rewards (R_{t+1}).
The Formal Framework: Markov Decision Processes (MDP)
Every reinforcement learning problem is mathematically formulated as a Markov Decision Process, defined by the 5-tuple ( (S, A, P, R, gamma) ):
- State Space (( S )): The set of all possible environmental states.
- Action Space (( A )): The set of legal actions executable by the agent.
- Transition Probability (( P(s' | s, a) )): The probability of transitioning to next state ( s' ) given current state ( s ) and action ( a ).
- Reward Function (( R(s, a, s') )): The immediate scalar feedback emitted by the environment after transition.
- Discount Factor (( gamma in [0, 1) )): Quantifies the present value of future rewards. ( gamma=0 ) makes the agent myopic (cares only about immediate rewards); ( gamma
ightarrow 1 ) makes the agent farsighted.
The Markov Property
A state transition satisfies the Markov Property if the future is conditionally independent of the past, given the present state:
( P(S_{t+1} = s' | S_t = s_t, A_t = a_t, S_{t-1} = s_{t-1}, dots, S_0 = s_0) = P(S_{t+1} = s' | S_t = s_t, A_t = a_t) )
The current state ( S_t ) must capture all relevant historical information necessary to decide the next action.
Return, Policy & Value Functions
- Cumulative Discounted Return (( G_t )): Total reward accumulated from step ( t ) into the future:
( G_t = sum_{k=0}^{infty} gamma^k R_{t+k+1} ).
- Policy (( pi(a|s) )): The agent's decision strategy mapping state ( s ) to a probability distribution over actions ( a ).
- State-Value Function (( V^pi(s) )): The expected return starting from state ( s ) following policy ( pi ):
( V^pi(s) = mathbb{E}_pi [G_t | S_t = s] ).
- Action-Value Function (( Q^pi(s, a) )): The expected return starting from state ( s ), taking action ( a ), and thereafter following policy ( pi ):
( Q^pi(s, a) = mathbb{E}_pi [G_t | S_t = s, A_t = a] ).
The Bellman Equations: Recursive Decomposition
Richard Bellman (1957) formulated the cornerstone of dynamic programming: a value function can be recursively decomposed into the immediate reward plus the discounted value of the successor state:
1. Bellman Expectation Equation for ( V^pi(s) ):
( V^pi(s) = sum_{a in A} pi(a|s) sum_{s' in S} P(s'|s, a) left[ R(s, a, s') + gamma V^pi(s')
ight] )
2. Bellman Optimality Equation for ( V^*(s) ):
The optimal value ( V^*(s) ) must equal the expected return from the single best action:
( V^*(s) = max_{a in A} sum_{s' in S} P(s'|s, a) left[ R(s, a, s') + gamma V^*(s')
ight] )
Dynamic Programming Solutions: Value Iteration
When the transition probabilities ( P ) and reward model ( R ) are known (a model-based MDP), Value Iteration turns the Bellman Optimality Equation into an iterative update rule. Starting with arbitrary values ( V_0(s) = 0 ), it updates values across all states until convergence:
( V_{k+1}(s) leftarrow max_{a} sum_{s'} P(s'|s, a) [R(s, a, s') + gamma V_k(s')] )
Python Implementation: Value Iteration on a Gridworld
The following script solves a 3-state linear MDP using Bellman Value Iteration:
import numpy as np
# 3 States: 0 (Start), 1 (Bridge), 2 (Goal with +100 reward)
n_states = 3
gamma = 0.90 # Discount factor
theta = 1e-4 # Convergence threshold
# Transition model: Actions ['Left', 'Right']
V = np.zeros(n_states)
rewards = np.array([0.0, 0.0, 100.0])
def value_iteration():
global V
iteration = 0
while True:
delta = 0
V_new = np.copy(V)
for s in range(n_states):
if s == 2: # Terminal Goal state
continue
# Evaluate Actions: Left -> max(0, s-1), Right -> min(2, s+1)
val_left = rewards[max(0, s - 1)] + gamma * V[max(0, s - 1)]
val_right = rewards[min(2, s + 1)] + gamma * V[min(2, s + 1)]
best_value = max(val_left, val_right)
delta = max(delta, abs(best_value - V[s]))
V_new[s] = best_value
V = V_new
iteration += 1
if delta < theta:
break
print(f"Value Iteration Converged in {iteration} rounds!")
print("Optimal State Values V*(s):", np.round(V, 2))
value_iteration()
Frequently Asked Questions (FAQ) - Student & Interview Review
Q1. What is the Discount Factor (gamma) and why is it necessary?
The discount factor gamma (0 <= gamma < 1) models the preference for immediate rewards over distant future rewards. Mathematically, it prevents the cumulative return G_t from blowing up to infinity in continuous, non-terminating (infinite horizon) MDP tasks.
Q2. What is the difference between Policy Iteration and Value Iteration?
Value Iteration iteratively updates state values directly using the Bellman Optimality Equation until values converge, extracting the optimal policy once at the end. Policy Iteration alternates between two explicit steps: Policy Evaluation (solving linear equations to evaluate current policy) and Policy Improvement (greedily updating the policy), typically converging in fewer iterations.
Q3. Why can't we use Dynamic Programming for all real-world RL problems?
Dynamic programming algorithms require complete knowledge of the transition probability matrix P(s'|s,a) and reward model R (model-based). In real-world problems (like driving a car or playing video games), the transition dynamics are unknown or infinitely complex, requiring model-free methods like Q-Learning.
Q4. What is the Credit Assignment Problem in Reinforcement Learning?
The Credit Assignment Problem asks: when an agent receives a delayed reward at the end of a long sequence of actions (such as winning a chess game after 50 moves), which specific intermediate actions were responsible for the success versus which were mistakes? Temporal Difference (TD) learning resolves this using bootstrapping.
Explore Related Artificial Intelligence Tutorials & Next Steps
Broaden your foundational and advanced AI knowledge across our curriculum: