Lecture 10.2: MDPs and Reinforcement Learning
Understanding Markov Decision Processes, Bellman Equations, Value Iteration, Multiagent MDPs, and Reinforcement Learning.
In traditional supervised machine learning, models require massive amounts of labeled data. Collecting such data is often expensive, and real-world datasets may contain missing, noisy, or untrustworthy values.
Reinforcement Learning (RL) overcomes data collection constraints by enabling an agent to learn directly through trial-and-error interactions with an environment, receiving positive rewards for effective actions and negative rewards for undesirable outcomes.
Markov Decision Processes (MDPs)
A Markov Decision Process (MDP) provides the formal mathematical foundation for decision-making under uncertainty in discrete time steps.
The Markov Property
An MDP assumes the Markov Property (memorylessness): the probability of reaching the next state depends only on the current state and action, not on the sequence of preceding states or past history:
Why is the Markov Property important?
- Efficient Computation: Eliminates the need to store or process full state histories.
- Mathematical Tractability: Enables recursive algorithms (like Value Iteration and Dynamic Programming).
- RL Foundation: Forms the backbone of both model-based and model-free reinforcement learning algorithms.
Formal MDP Definition
An MDP is formally specified by a tuple :
- States (): The set of all valid environmental states.
- Actions (): The set of all possible actions.
- Transition Function (): The probability distribution of transitioning to state after taking action in state .
- Reward Function (): The immediate scalar reward received for being in state .
- Start State (): The initial starting state of the process.
Concrete 4-State MDP Example
Consider a sample MDP with four states , start state , and actions .
Reward & Transition Tables
| State () | Reward () |
|---|---|
| (Goal) | |
| From () | Action () | To () | |
|---|---|---|---|
Policy and Discounted Future Rewards
The Policy Dilemma
Should an agent take 100 actions with no reward to reach a state with a massive reward of , or take 100 actions that each yield a reward of 1?
Key trade-offs in defining agent policies:
- Agents don't live forever: Waiting too many steps for a distant reward introduces survival risk.
- Immediate rewards are safer: Immediate rewards are more reliable than uncertain future possibilities.
- Delaying gratification: Delaying gratification can be intelligent—but only up to a reasonable point.
Discounted Return & The Bellman Equation
To model preference for earlier rewards, we apply a Discount Factor () to future rewards. The total discounted return over an infinite sequence of states is:
The long-term utility of being in state under an optimal policy satisfies the Bellman Equation:
System of Bellman Equations
For an environment with states, there are Bellman equations with unknown utility variables.
- Why can't we solve this directly with matrix algebra? The presence of the non-linear operator prevents direct linear algebra solutions. We must use dynamic programming algorithms like Value Iteration.
The Value Iteration Algorithm
Value Iteration starts with initial arbitrary utility estimates and iteratively updates state utilities over time steps using the Bellman Update Equation:
Stopping Criterion & Error Bound ()
Iterations continue until the maximum change in utility across all states in a time step falls below a threshold: When this holds, the error of the current utility estimates relative to true optimal values is guaranteed to be less than .
Role of Parameters ( and )
- User Error Threshold (): Controls precision. A smaller yields higher accuracy but requires more iterations to converge.
- High Discount Factor (): Agent strongly values long-term future rewards. Slower convergence because tiny changes in distant states propagate across many iterations.
- Low Discount Factor (): Agent prioritizes immediate rewards. Faster convergence because distant rewards decay rapidly.
[!WARNING] Stopping Criteria Nuances
- No Absolute Guarantees: The utility difference criterion signals that further updates yield minimal change, but doesn't guarantee discovering absolute optimal policy values in non-convex or high-dimensional approximations.
- Local Optima: The algorithm may stabilize at local optima in complex domains.
- Combined Criteria: In practice, value iteration is often combined with a maximum iteration count limit and environmental performance checks.
Value Iteration Algorithm Pseudocode & Execution Trace
VALUE-ITERATION(T, r, gamma, epsilon)
1 do
2 u <- u'
3 delta <- 0
4 for each s in S do
5 u'(s) <- r(s) + gamma * max_a sum_{s'} T(s, a, s') * u(s')
6 if |u'(s) - u(s)| > delta then
7 delta <- |u'(s) - u(s)|
8 until delta < epsilon * (1 - gamma) / gamma
9 return uSolved Example: Value Iteration
Problem Statement
Consider a Markov Decision Process (MDP) defined by state space , action space , and discount factor .
- State Rewards: , , (Goal State),
- Transition Probabilities :
| From () | Action () | To () | Probability |
|---|---|---|---|
Tasks:
- Compute state utility values for iterations using Value Iteration starting with . Show step-by-step action evaluations.
- Extract the optimal policy for all states.
Step-by-Step Value Iteration Solution
Iteration (Initialization)
Initial state utility estimates are initialized to zero:
Iteration
Update formula:
-
For State ():
- Action :
- Action :
-
For State ():
- Action :
- Action :
-
For State ():
- Action :
- Action :
-
For State ():
- Action :
- Action :
Iteration
Update formula:
-
For State ():
- Action :
- Action :
-
For State ():
- Action :
- Action :
-
For State ():
- Action :
- Action :
-
For State ():
- Action :
- Action :
Iteration
Update formula:
-
For State ():
- Action :
- Action :
-
For State ():
- Action :
- Action :
-
For State ():
- Action :
- Action :
-
For State ():
- Action :
- Action :
Iteration
Update formula:
-
For State ():
- Action :
- Action :
-
For State ():
- Action :
- Action :
-
For State ():
- Action :
- Action :
-
For State ():
- Action :
- Action :
Summary Value Iteration Matrix Table
| State () | |||||
|---|---|---|---|---|---|
Extracted Optimal Policy ()
Evaluating at each state gives the optimal policy:
Multiagent Markov Decision Processes (MMDPs)
When an environment contains multiple interacting agents, single-agent MDP definitions must be extended:
- Naive Simplification (Environment Embedding): Fold all other agents' behaviors into the environment transition function , assuming other agents are non-adaptive background elements. Drawback: Rarely works because other agents adapt their strategies over time, violating the fixed transition function requirement of MDPs.
- Joint Action MDPs (Better Method): Extend transitions to take a Joint Action Vector , where each element represents the action of agent :
- Reward Allocation Strategies:
- Equal Division: Split collective system rewards equally among all agents.
- Marginal Contribution: Assign rewards proportional to each agent's individual contribution to the total system payoff.
Reinforcement Learning Taxonomy & Trade-offs
If environmental dynamics and reward function are unknown, the agent must use Reinforcement Learning (RL).
Key RL Trade-offs
| Trade-off Dimension | Model-Free RL | Model-Based RL |
|---|---|---|
| Sample Efficiency vs. Computation | More sample-efficient for learning policies directly, but computationally heavy during execution. | Highly computationally efficient for planning once a model is learned, but requires substantial data samples to learn an accurate environment model. |
| Environmental Flexibility | Highly adaptable to changes in environment physics without explicitly rebuilding world models. | Requires relearning transition and reward models if environment mechanics change. |
On-Policy vs. Off-Policy Reinforcement Learning
A critical distinction in model-free RL is how the agent handles experience generation versus policy optimization:
- Behavior Policy ( or ): The policy used by the agent to interact with the environment, select actions, and collect experience tuples . This policy often includes exploration mechanisms (e.g., -greedy).
- Target Policy ( or ): The policy that the agent is evaluating and attempting to optimize into the optimal strategy .
1. On-Policy Learning (e.g., SARSA)
In On-Policy methods, the target policy is identical to the behavior policy (). The agent learns the value of the policy it is actively executing. where is the actual next action chosen by the current behavior policy in state .
- Characteristics: Conservative and safe. If the behavior policy makes random exploratory mistakes near dangerous states, SARSA lowers the Q-value of those states to reflect the risk of exploration.
2. Off-Policy Learning (e.g., Q-Learning)
In Off-Policy methods, the target policy is independent of the behavior policy (). The agent learns the optimal target policy (greedy action selection) while using a different, exploratory behavior policy to gather data.
- Characteristics: Evaluates the best possible next action , regardless of which action the behavior policy actually selects next. This allows learning optimal control directly from historical logs, random exploration, or offline data.
| Comparison Dimension | On-Policy (SARSA) | Off-Policy (Q-Learning) |
|---|---|---|
| Target Policy | Same as Behavior Policy () | Optimal Greedy Policy () |
| Experience Source | Must be generated live by current policy | Can be generated by random exploration, historical logs, or replay buffers |
| Update Function | (uses actual sampled ) | (uses maximum Q-value at ) |
| Risk Sensitivity | Accounts for exploration risks (e.g. cliff walking safety) | Ignores exploration risk, learns true optimal path assuming non-exploratory execution |
Q-Learning (Off-Policy Model-Free RL)
Q-learning is an off-policy, model-free, value-based algorithm. The "Q" stands for Quality—representing how valuable taking a specific action is in maximizing long-term cumulative rewards.
The Q-Learning Update Rule
For experience tuple :
where:
- is the Learning Rate.
- is the Discount Factor.
- is the Temporal Difference (TD) Error.
Concrete 3x3 Grid World Q-Learning Example
Consider a grid world navigation problem with 9 discrete states and 4 movement actions .
Environment Specification
- State Space (9 states): Row-column coordinates where (row) and (column).
- Action Space (4 actions): .
- Special States & Rewards:
- Goal State : Immediate reward (Terminal).
- Danger State : Immediate penalty .
- Clear State : Neutral reward .
- Start State : Initial position of agent.
- Q-Table Matrix Size: state-action entries.
Initial Q-Table (All Values Initialized to 0)
| State () | Left | Right | Up | Down |
|---|---|---|---|---|
| (Start) | ||||
[!NOTE] State-Action Entry Interpretation The table cell at row and column stores , which represents the agent's estimated long-term reward for taking action when standing at state .
Step-by-Step Q-Learning Execution Trace (, )
Step 1: Moving Up into Danger from Start
- Current State:
- Selected Action:
- Next State: (Danger Cell)
- Observed Reward:
- Calculate Max Future Value: (all Q-values initially 0)
- Temporal Difference Error:
- Q-Table Update:
Step 2: Reaching Goal from
- Current State:
- Selected Action:
- Next State: (Goal Cell)
- Observed Reward:
- Calculate Max Future Value:
- Temporal Difference Error:
- Q-Table Update:
Step 3: Backward Propagation of Value from
- Current State:
- Selected Action:
- Next State:
- Observed Reward:
- Calculate Max Future Value:
- Temporal Difference Error:
- Q-Table Update:
Updated Q-Table (After Steps 1–3)
| State () | Left | Right | Up | Down |
|---|---|---|---|---|
| (Start) | ||||
Real-World Off-Policy Applications
- Robot Maze Exploration: A robot uses a completely random exploration policy (behavior policy) to explore a maze, while using recorded experience buffer tuples to train a goal-directed optimal policy (target policy).
- Advertisement Recommendation Systems: E-commerce systems monitor random user browsing logs to learn an optimal ad targeting strategy off-policy without degrading live user experience.
Exploration vs. Exploitation (-Greedy Policy)
To balance trying new actions with selecting known high-value actions, the agent chooses actions during training using an -greedy decision rule: Generate a uniform random number at each step:
Lecture 10.1: Decision Theory and Utility
How agents make rational decisions under uncertainty using Utility Theory, Preference Ordering, Expected Utility, and Decision Networks.
Population-Based Approaches and Swarm Intelligence
Exploring Genetic Algorithms, Ant Colony Optimization (ACO), and Particle Swarm Optimization (PSO).