Intro to RL
In RL, we have an agent that lives in a universe with some reward function that guides how the agent should act. Our goal is for the agent to learn policies ("how to act") that maximize reward gained in this universe.
MDPs
Usually, we model the universe the agent lives in as a Markov Decision Process (MDP).
- An episodic1 MDP is defined by a tuple
- State space : the representation of the environment
- Action space : the actions the agent can take
- Horizon : the number of time-steps in an "episode"2
- Transition kernel : the "physics engine" of the universe, mapping a state-action pair to a probability distribution over the next state:
- Reward function : the scalar feedback signal received at step
The goal of RL is to find a policy that maximizes the expected cumulative reward.
Q-function and value functions
How do we evaluate how "good" a policy is? We define value functions.
Value function
The value function represents the expected cumulative reward if the agent starts in state and strictly follows policy until the end of the horizon: This expectation is over two independent sources of randomness - i.e.
- the policy may be stochastic:
- the environment is stochastic:
Q-function
The Q-function (aka. action-value function) represents the expected cumulative reward if the agent starts in state , takes a specific action , and then follows policy afterward: ^ in word: "the best value you can get from taking action in state equals the reward you can collect right now, plus (averaged over wherever the environment might send you next) the best value obtainable from the next state if you keep acting optimally."
- := "act optimally from here onward"
- := accounting for the environment's stochastic response to your action
The core idea here is the recursion - optimal long-run value splits cleanly into reward now + optimal value of the future.
Optimal Q-function
The goal of RL is to find the optimal policy , which corresponds to the optimal Q-function . If we know perfectly, we effectively have the optimal policy :
- 🔑 In any state , pick the action that maximizes
- 💡 The optimal Q-function satisfies the Bellman Optimality Equation:
Model-free RL
Model-free RL encompasses methods that find the optimal policy but skip "learning the model - i.e. skips learning the transition kernel or the reward function . The agent doesn't try to understand the physics of the world; it just tries to learn the function directly through trial and error.
Q-learning
Q-learning is one of the foundational model-free RL algorithms! It uses the Bellman equation as an update rule.
- When the agent experiences a transition , it updates its estimate of by nudging it toward a "target": where is the learning rate and is a discount factor.
- : how far you move toward the new estimate on each update
- : how much you care about future reward vs. immediate; a reward steps away is worth of its face value.
- 💡 Intuition for the update: We can split the update into two pieces:
- The bracket is the TD error: the gap between what you currently believe is, and a freshly informed estimate (the target) built from the reward you actually just received plus your current best guess of the future (, i.e. the discounted reward you expect to receive in the future, given that you act optimally based on your current estimate of ).
- 🔑 Connection to the Bellman optimality equation: Notice that the target is precisely the RHS of the Bellman optimality equation (), except without the expectation over because this expectation is not computable without knowing - so we substitute the single we happened to land in as one sample of it.
- 💡 ^ The idea is that if we repeatedly do these updates over enough data points , nudging our tabular a bit each time, we will have approximated the expectation over using these iterative updates s.t. .
- 🔖 The convergence guarantee: Tabular Q-learning converges to with probability 1, provided the following conditions hold:
- Every pair is visited infinitely often.
- The learning rate decays correctly: but → the steps must be large enough in total to travel any distance, but shrink fast enough to stop the noise from perpetually jostling the estimate.
- Bounded rewards, and (or a proper finite horizon).
- 🔑 ^ under these conditions, the nudging provably drives . The mechanism for this proof is a fixed-point argument: the Bellman optimality operator is a contraction in the max-norm with factor , so repeatedly applying it pulls any starting estimate toward its unique fixed point . Q-learning is a stochastic, sampled version of iterating that contraction: each update applies approximately, using one sampled in place of the true expectation, and the decaying step size averages out the sampling noise so the approximate iteration still lands on the same fixed point.
- ❓ Is Q-learning neural-network based? No, original Q-learning is tabular - you keep a lookup table with one cell per pair and edit cells directly using the update rule above.
Model-based RL
Model-based RL explicitly learns the rules of the universe. Using collected data, we aim to approximate the transition kernel and the reward (as well as potentially other relevant information about the universe). Once we have this simulated "world model," a planner can be used to search through possible action sequences to find the one that yields the highest return.
- Model-based methods originally started out fully tabular - e.g. for small discrete MDPs, we can just count what we see.
- Estimate by the empirical frequency of landing in after taking in
- Estimate by averaging the rewards you saw
- 🔖 Obtain a policy using these estimated values ^ + value iteration / policy iteration.
- Modern versions of model-based RL have explored more complex ways of modeling and , e.g. -
- Gaussian processes, linear models, Gaussian mixtures
- Neural networks
- 💡 These formulations of and make it possible to scale the "rules of the universe" to apply to large, continuous worlds - i.e. the tabular method fails when is continuous.
Once we have a fully specified MDP (that we learned via model-based RL), we can compute the optimal policy from it using methods such as value iteration (VI) and policy iteration (PI). These are essentially the planning engines that model-based RL plugs into.