Reinforcement Learning
learning optimal decision-making through interactions between agents and environments
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 (MDPs)
In Reinforcement Learning (RL), we study how an autonomous decision-making Agent can learn to navigate an active Environment to maximize a cumulative mathematical reward signal over time. We formalize this sequential decision-making framework using Markov Decision Processes (MDPs).
An MDP is mathematically defined by a 5-tuple: :
• State Space (): The set of all possible situations or configurations of the environment.
• Action Space (): The set of all possible choices or moves available to the agent.
• Transition Probability (): The probability of transitioning to state given that the agent takes action in state . This represents the dynamics (physics) of the world.
• Reward Function (): The scalar feedback (reward or penalty) the environment returns after the agent takes a step.
• Discount Factor (): Determines how much the agent values immediate rewards compared to future rewards. A value of makes the agent 'shortsighted' (focused only on immediate gains), while makes it highly strategic. It also mathematically guarantees that infinite reward sum sequences converge to a finite limit.
Grid-World Navigation Example: Imagine a robot navigating a grid trying to reach a gold chest ( reward) while avoiding a lava pit ( penalty). The states are the grid coordinates. The actions are . If the floor is slippery, there might only be an transition probability of moving in the commanded direction, with a chance of sliding sideways. The robot must learn a sequence of steps that minimizes the risk of slipping into the lava while reaching the gold!
2. Value Functions and the Bellman Optimality Equations
To decide on optimal actions, the agent must learn to estimate the long-term future value of its current choices. We define a Policy as the probability distribution of actions given the current state. We evaluate policies using two value functions:
• State-Value Function (): The expected cumulative discounted return starting in state and following policy thereafter.
• Action-Value Function (): (Known as the Q-value). The expected cumulative discounted return starting in state , executing action , and following policy thereafter.
These functions satisfy recursive, self-consistent relationships called the Bellman Equations. The Bellman Optimality Equation for the optimal Q-value is:
,
Bellman Backup Example: Suppose we are in a state and take action . The immediate reward is . There is a chance () of transitioning to a next state . In , the maximum possible Q-value for any future action is . If our discount factor is , the Bellman backup calculates our current Q-value as: This demonstrates beautifully how value information cascades backwards through time steps to guide the agent's current decisions!
3. Q-Learning, DQNs, and Policy Gradients
How do we solve optimal policies? We use different algorithm classes depending on our data structures:
• Tabular Q-Learning: A model-free, off-policy temporal difference algorithm. It updates a table of Q-values iteratively without needing to know the environment's transition physics . The update rule is:
,
where is the learning rate. To balance exploration, we use -greedy selection: the agent takes a random exploratory action with probability , and exploits its best-known action with probability .
• Deep Q-Networks (DQN): For high-dimensional state spaces (like raw pixels in Atari games), maintaining a Q-table is impossible. DQNs solve this by replacing the lookup table with a Neural Network to approximate optimal Q-values.
• Policy Gradients & Actor-Critic: Instead of approximating Q-values, policy gradient methods directly parameterize and optimize the policy using gradient ascent. Actor-Critic architectures combine both: the Critic approximates value functions to evaluate actions, while the Actor updates the policy direction based on the Critic's feedback.
Interactive Practice Quiz
Test your understanding with instant feedback
