Reinforcement Learning
learning optimal decision-making through interactions between agents and environments
Read diagram labels
- Agent: brain / policy
- Environment: world / physics
- Action (aₜ)
- State and reward (sₜ, rₜ)
Core Concepts Covered
- Markov Decision Processes (MDPs) and Bellman equations
- Value-based (Q-learning, DQN) and Policy-based methods
- Actor-critic models and reinforcement learning feedback
Local Setup Recommendation
To execute and experiment with the code cells below on your local machine, ensure you have set up your isolated virtual environments and scientific libraries by following the detailed protocols in Unit 03: Environment Setup or run them in Google Colab.
1. Markov Decision Processes, Trajectories, and Returns
An agent interacts with an environment through a trajectory . A Markov Decision Process is : states, actions, transition probabilities, rewards, and discount factor. The Markov property says the current state contains the information needed to predict the next transition given an action; Unit 19 develops the stochastic-process foundation.
The return after time is A smaller favors immediate reward; a value near one gives longer-horizon consequences more weight. In finite episodes may equal one, while continuing tasks usually use to keep returns finite.
A policy may be deterministic or stochastic. RL differs from supervised learning because actions affect which future observations and rewards become available.
MDP Transitions: State, Action, Reward, and Next State
Read diagram labels
- s0
- s1
- s2
- a, r=+1
- a, r=+5
- P(s' | s,a) can branch stochastically
Discounted Trajectory Return
Rewards after a state are and . Find and compare it with the undiscounted finite return.
1..
2.The undiscounted return is .
Discounting makes the reward two steps away contribute only instead of .
Expected One-Step Reward
Action gives reward with probability and with probability . Find its expected immediate reward.
1..
This expectation alone is not the action value; future state values must also be included.
2. Value Functions and Bellman Backups
The state value is and the action value is . The Bellman expectation equation decomposes value into one-step reward plus discounted value under the same policy:
Optimality replaces the policy average with the best next choice: A Bellman backup applies one of these right-hand sides to update an estimate.
A Bellman Backup Combines Reward and Future Value
Read diagram labels
- s
- s'₁
- s'₂
- p=.7, r=2
- p=.3, r=0
- Q(s,a)
- = Σ p(r + γV)
- one-step backup
Bellman Expectation Backup
A fixed policy takes an action that reaches with probability , reward , value ; or with probability , reward , value . Let . Find the backup.
1.Branch returns are and .
.
Bellman Optimality Choice
At state , action Left has expected backup and Right has . Which is optimal?
1.Left gives ; Right gives .
, so the greedy action is Right.
3. Policy Evaluation and Value Iteration
Policy evaluation repeatedly applies the Bellman expectation backup until values stabilize for a fixed policy. Policy improvement then acts greedily with respect to those values. Alternating the two gives policy iteration. Value iteration combines partial evaluation and improvement by repeatedly applying the Bellman optimality operator.
For a finite discounted MDP, the optimality operator is a contraction, so repeated exact backups converge to . In larger problems, sampling and function approximation replace exhaustive state sweeps.
Two Value-Iteration Sweeps
A state can Exit for reward , or Wait for reward and deterministically return to . With and , compute .
1..
2..
The estimate has stabilized at ; Exit and one-step Wait are tied under this value.
Value iteration compares complete backed-up action returns, not only immediate rewards.
4. Q-Learning, Exploration, and Deep Q-Networks
Model-free Q-learning updates from an observed transition: The bracketed quantity is the temporal-difference (TD) error. It is off-policy because its target uses the greedy next action even when behavior explores.
-greedy selects a random action with probability and otherwise a greedy action. With actions and a unique greedy action, that action's total probability is . A stochastic policy instead learns a full probability distribution, which is useful for naturally uncertain or continuous control.
A DQN replaces the table with . An experience replay buffer breaks short-range correlations and reuses transitions in random mini-batches. A separate target network supplies slowly changing bootstrap targets. Without these devices, moving targets, correlated data, and maximization bias can destabilize learning; monitor seeds and learning curves rather than trusting one run.
Q-Table Learning and Random Experience Replay
Read diagram labels
- Q(s,a) table
- (s, a, r, s')
- random mini-batch breaks correlation
Complete Q-Learning Update
Given , reward , , , and , update .
1.TD target is .
2.TD error is .
Updated value is .
-Greedy Probabilities
There are four actions, one uniquely greedy, and . What probability does each action receive?
1.Exploration assigns to every action.
2.The greedy action also receives exploitation mass , totaling .
Each non-greedy action receives .
5. Policy Gradients, Advantages, and Actor–Critic
Policy gradients directly maximize . The score-function estimator weights log-policy gradients by returns: High-return actions become more probable; a baseline can reduce variance without changing the expected gradient.
The advantage says whether an action is better than the state's baseline. Actor–critic methods use an actor for and a critic for or . A one-step TD error is a practical advantage estimate.
PPO constrains policy changes through a clipped probability-ratio objective, improving reliability compared with unconstrained large policy steps. It remains sensitive to reward design, normalization, rollout length, and implementation details.
Actor–Critic Learning Loop
Read diagram labels
- ACTOR
- πθ(a|s)
- ENV
- r, s'
- CRITIC
- Vφ(s)
- advantage / TD error guides policy update
TD Error and Actor Direction
The critic has , observes reward , next value , and . Find the TD error and interpret the actor update.
1..
2.The positive TD error means the action performed better than the critic expected.
An actor update weighted by increases the log-probability of that sampled action.
Return-Weighted Policy Gradient
Two sampled log-policy gradients are and with returns and . Estimate their unnormalized average direction.
1.Weight and sum: .
2.Average across two samples: .
The positive-return action is reinforced while the negative-return action is suppressed.
Cumulative Algorithm Choice
Choose a starting family for a tiny known MDP, an Atari-like pixel environment with discrete actions, and a continuous robot controller.
1.Use value or policy iteration for the tiny known transition model.
2.Use a DQN-family method for high-dimensional observations with a small discrete action set.
Use a stochastic actor–critic policy for continuous actions.
Interactive Practice Quiz
Test your understanding with instant feedback
What does the discount factor control?
What does a Bellman expectation backup use for the next action?
What is the Q-learning TD target?
Why use an experience replay buffer in DQN?
What does the critic estimate in an actor–critic method?
If , , , and , what is the one-step TD error?
With three actions, a unique greedy action, and , what is the greedy action's total probability?
What is the main role of a DQN target network?
Further Readings
Explore these highly recommended external references to deepen your understanding
Reinforcement Learning: An Introduction
https://www.andrew.cmu.edu/course/10-703/textbook/BartoSutton.pdf
Gymnasium Documentation
https://gymnasium.farama.org/
Playing Atari with Deep Reinforcement Learning
https://arxiv.org/abs/1312.5602
Asynchronous Methods for Deep Reinforcement Learning
https://arxiv.org/abs/1602.01783
Proximal Policy Optimization Algorithms
https://arxiv.org/abs/1707.06347
