Reinforcement Learning series
01. Foundations of Reinforcement Learning
2026-07-09
This series explains the main reinforcement learning algorithms through both intuition and theory.
The series is based mainly on two lecture series. The UC Berkeley RL course by Sergey Levine gives a broad algorithmic overview of reinforcement learning. The UCLA reinforcement learning course by Ernest Ryu gives a more mathematical treatment. For a deeper understanding, I recommend watching the lectures directly.
Markov Decision Process
A Markov decision process, or MDP, is a mathematical way to describe a sequential decision-making process.
The basic picture is simple. At time , the agent is in some current state . It chooses an action , and then the world moves to a next state .
For example, consider chess. The current state is the board position, and the action is the move chosen by the player. After the move is made, the next state is the new board position.
Driving can also be viewed in the same way. The current state is the road situation around the car: where the car is, how it is moving, and what is happening nearby. The action might be to accelerate, brake, or steer. After that action, the next state is the road situation a moment later.
We call the rule that describes this change the transition model, or dynamics model:
This notation means that, given and , the model assigns probabilities to possible next states .
In chess, this rule is just the rules of the game. Given a board position and a legal move, the next board position is fixed. So chess has deterministic and known dynamics.
In driving, this rule is much harder to write down. The next road situation depends on the car, the road, and other drivers. The same action in a similar-looking situation may not always give the same result. So driving has stochastic and unknown dynamics.
The key assumption in an MDP is the Markov property. It says that the next state only depends on the current state and action, not on the full history before them:
There is one thing to be careful about. The Markov property does not mean the past is useless. It means that the state should already contain the relevant information from the past. If important information is missing from the state, then the process may no longer look Markov.
The Reinforcement Learning Objective
The dynamics model describes how the environment responds to an action. It tells us how the state changes after the agent acts.
What the agent can control is which action to choose in the current state. We call this rule the policy, usually written as .
For example, in chess, the policy tells the player which move to make from the current board position. In driving, the policy tells the car whether to accelerate, brake, or steer from the current road situation.
If the policy is stochastic, we write it as
which means the probability of choosing action in state .
Now we need a way to say whether a policy is good or bad. For this, we add rewards to the MDP. A reward is a number that tells the agent how desirable an outcome is.
In chess, the reward might be positive for winning and negative for losing. In driving, the reward might encourage safe progress and penalize collisions or leaving the lane.
At each time step, the agent is in state , chooses action using its policy, receives reward , and moves to the next state . More generally, the reward and next state can be sampled from the dynamics:
If the reward is deterministic, we can write it as a reward function .
Once a policy is fixed, the policy and the dynamics together define a distribution over trajectories. One trajectory can be written as
Here, the initial state is sampled from the initial state distribution . Following the MDP, the probability of a trajectory under policy is
Now we can define the reinforcement learning objective. A policy is good if the trajectories it generates tend to have high total reward. Usually, we write this as maximizing the expected discounted sum of rewards:
The factor appears because we often want the return to be well-defined even when the trajectory is very long or infinite. If we simply sum rewards forever, the total reward may diverge. When rewards are bounded and , the discounted sum is finite:
Most RL algorithms assume for mathematical convenience. In practice, if the undiscounted total reward is already well bounded, using is usually fine.
When Does an MDP End?
In the trajectory notation above, we wrote the final time as . So how is determined?
In general, is not a pre-determined, fixed value. An MDP ends when the trajectory reaches a terminal state. For example, in chess, the game ends when the board reaches a terminal state, such as checkmate or draw. We can write this terminal state as :
So is the time when the trajectory ends.
One thing to notice is that is a random variable, which makes it inconvenient to work with mathematically. For example, we should not casually write
because the upper limit still depends on the sampled trajectory.
A common trick is to define an equivalent MDP that never formally stops. We make the terminal state absorbing: once the process reaches , it stays there forever and receives zero reward:
After this transformation, the policy at does not matter. No matter what action is chosen, the process stays in the terminal state and receives no further reward. This lets us use infinite-horizon notation while still representing tasks that end.
Partially Observable MDP
So far, we have assumed that the agent can observe the full state . In many problems, this is not true. The agent only receives an observation , which may contain only partial information about the true state.
For example, in driving, the full state would include everything relevant in the environment. But the car only observes what its sensors can measure. If another car is hidden behind a truck, that information is part of the true state, but it may not appear in the current observation.
This setting is called a partially observable MDP, or POMDP. In a POMDP, the policy is usually written as a function of the observation:
instead of the full state .
For the rest of this post, I will assume a fully observable MDP. In many cases, the same ideas can be adapted to POMDPs by replacing the state with the observation.
Stationarity
One more assumption in this post is that the dynamics are stationary. This means the transition model does not change over time:
So the same state and action follow the same dynamics at every time step.
If the dynamics change with time, they are non-stationary. One example is the fixed-horizon case, where the episode is forced to end at a pre-determined time . This is different from the terminal-state view above, where depends on the trajectory. In the fixed-horizon case, the transition rule depends on time:
When dynamics are non-stationary, the optimal policy may also need to depend on time. Instead of writing
we may need to write
For the rest of this post, I will assume stationary dynamics.
Value Functions
Let us define a few useful functions for working with a policy .
The state value function measures the expected return starting from state and then following policy :
The state-action value function measures the expected return starting from state , first taking action , and then following policy :
So tells us how good it is to be in a state under policy , while tells us how good it is to first take action from that state and then follow .
The advantage function compares these two quantities:
The advantage tells us whether action is better or worse than the average action under policy at state . If , then action is better than average. If , then it is worse than average.
Basic Properties of and
The relationship between and follows directly from the way an MDP generates a trajectory.
If we start from state , the policy first chooses an action . After that, the expected return is . Therefore, the value of state is the average state-action value under the policy:
Conversely, suppose we start from state and first take action . The environment gives reward and next state . From that point on, we follow policy , so the remaining expected return is . Therefore,
These two equations connect and . Combining them gives the one-step transition property.
For the state value function,
For the state-action value function,
Bellman Equation and Bellman Operator
For a fixed policy , define the Bellman operator as the operator that maps to :
The one-step transition property for can then be written as
So is a fixed point of the Bellman operator. The important fact is that the converse also holds: if a bounded function satisfies this fixed point equation, then it must be the true value function .
Theorem. Let be a fixed policy. Assume , , and almost surely. Then exists and satisfies the Bellman equation
Conversely, if a bounded function satisfies
then .
Moreover, if we start from any bounded initial function and repeatedly apply the Bellman operator, the result converges to :
Proof
Since rewards are bounded and , the discounted return is bounded, so is well defined. Also, by the one-step transition property, . Thus is a fixed point of .
Now we show that this fixed point is unique. We will use the Banach fixed point theorem.
Banach fixed point theorem. Let be a complete metric space. Suppose is a -contraction with , meaning
Then has a unique fixed point . Moreover, for any ,
We will apply this theorem to the Bellman operator. Here, we work with bounded functions under the sup norm
For any two bounded functions ,
Therefore, is a -contraction. By the Banach fixed point theorem, has a unique fixed point, and repeatedly applying from any bounded initial function converges to that fixed point.
Since is already a fixed point, it must be the unique fixed point. Therefore, if any bounded function satisfies , then . Also,
The same idea holds for the state-action value function . Define the Bellman operator on by
Theorem. Let be a fixed policy. Assume , , , and almost surely. Then exists and satisfies the Bellman equation
Conversely, if a bounded function satisfies
then .
Moreover, if we start from any bounded initial function and repeatedly apply the Bellman operator, the result converges to :
The proof is almost identical to the proof for . The same contraction argument applies, now using the sup norm over state-action pairs.
This is the end of the first post. We introduced the basic setup of reinforcement learning: MDPs, rewards, policies, trajectories, value functions, and Bellman equations. In the next post, we will look at how to optimize the policy.