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.

MDP transition dynamics diagram

The basic picture is simple. At time tt, the agent is in some current state sts_t. It chooses an action ata_t, and then the world moves to a next state st+1s_{t+1}.

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:

p(st+1st,at)p(s_{t+1} \mid s_t, a_t)

This notation means that, given sts_t and ata_t, the model assigns probabilities to possible next states st+1s_{t+1}.

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:

p(st+1st,at,st1,at1,)=p(st+1st,at)p(s_{t+1} \mid s_t, a_t, s_{t-1}, a_{t-1}, \ldots) = p(s_{t+1} \mid s_t, a_t)

There is one thing to be careful about. The Markov property does not mean the past is useless. It means that the state sts_t 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

Policy and trajectory diagram

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 π\pi.

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

π(atst)\pi(a_t \mid s_t)

which means the probability of choosing action ata_t in state sts_t.

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 sts_t, chooses action ata_t using its policy, receives reward rtr_t, and moves to the next state st+1s_{t+1}. More generally, the reward and next state can be sampled from the dynamics:

(rt,st+1)p(st,at)(r_t, s_{t+1}) \sim p(\cdot \mid s_t, a_t)

If the reward is deterministic, we can write it as a reward function r(st,at)r(s_t, a_t).

Once a policy is fixed, the policy and the dynamics together define a distribution over trajectories. One trajectory can be written as

τ=(s0,a0,r0,s1,a1,r1,,sT)\tau = (s_0, a_0, r_0, s_1, a_1, r_1, \ldots, s_T)

Here, the initial state s0s_0 is sampled from the initial state distribution p0p_0. Following the MDP, the probability of a trajectory under policy π\pi is

pπ(τ)=p0(s0)t=0T1π(atst)p(rt,st+1st,at)p_\pi(\tau) = p_0(s_0) \prod_{t=0}^{T-1} \pi(a_t \mid s_t) p(r_t, s_{t+1} \mid s_t, a_t)

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:

maxπEτpπ(τ)[t=0T1γtrt]\max_\pi \mathbb{E}_{\tau \sim p_\pi(\tau)} \left[ \sum_{t=0}^{T-1} \gamma^t r_t \right]

The factor γ\gamma 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 γ<1\gamma < 1, the discounted sum is finite:

t=0γtrt\sum_{t=0}^{\infty} \gamma^t r_t

Most RL algorithms assume γ<1\gamma < 1 for mathematical convenience. In practice, if the undiscounted total reward is already well bounded, using γ=1\gamma = 1 is usually fine.

When Does an MDP End?

In the trajectory notation above, we wrote the final time as TT. So how is TT determined?

In general, TT 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 sterms_{\mathrm{term}}:

sT=sterms_T = s_{\mathrm{term}}

So TT is the time when the trajectory ends.

One thing to notice is that TT is a random variable, which makes it inconvenient to work with mathematically. For example, we should not casually write

Eτpπ(τ)[t=0Trt]=t=0TEτpπ(τ)[rt]\mathbb{E}_{\tau \sim p_\pi(\tau)} \left[ \sum_{t=0}^{T} r_t \right] = \sum_{t=0}^{T} \mathbb{E}_{\tau \sim p_\pi(\tau)}[r_t]

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 sterms_{\mathrm{term}}, it stays there forever and receives zero reward:

p(rt=0,st+1=stermst=sterm,at)=1p(r_t = 0, s_{t+1} = s_{\mathrm{term}} \mid s_t = s_{\mathrm{term}}, a_t) = 1

After this transformation, the policy at sterms_{\mathrm{term}} 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 sts_t. In many problems, this is not true. The agent only receives an observation oto_t, 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.

Partially observable MDP observation diagram

This setting is called a partially observable MDP, or POMDP. In a POMDP, the policy is usually written as a function of the observation:

π(atot)\pi(a_t \mid o_t)

instead of the full state sts_t.

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:

pt(rt,st+1st,at)=p(rt,st+1st,at)p_t(r_t, s_{t+1} \mid s_t, a_t) = p(r_t, s_{t+1} \mid s_t, a_t)

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 TT. This is different from the terminal-state view above, where TT depends on the trajectory. In the fixed-horizon case, the transition rule depends on time:

pT1(sT=stermsT1,aT1)=1pt(st+1=stermst,at)=0,t=0,,T2\begin{aligned} p_{T-1}(s_T = s_{\mathrm{term}} \mid s_{T-1}, a_{T-1}) &= 1 \\ p_t(s_{t+1} = s_{\mathrm{term}} \mid s_t, a_t) &= 0, \qquad t = 0,\ldots,T-2 \end{aligned}

When dynamics are non-stationary, the optimal policy may also need to depend on time. Instead of writing

π(atst)\pi(a_t \mid s_t)

we may need to write

πt(atst)\pi_t(a_t \mid s_t)

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 π\pi.

The state value function VπV^\pi measures the expected return starting from state ss and then following policy π\pi:

Vπ(s)=Eτpπ(τs0=s)[t=0T1γtrt]V^\pi(s) = \mathbb{E}_{\tau \sim p_\pi(\tau \mid s_0 = s)} \left[ \sum_{t=0}^{T-1} \gamma^t r_t \right]

The state-action value function QπQ^\pi measures the expected return starting from state ss, first taking action aa, and then following policy π\pi:

Qπ(s,a)=Eτpπ(τs0=s,a0=a)[t=0T1γtrt]Q^\pi(s,a) = \mathbb{E}_{\tau \sim p_\pi(\tau \mid s_0 = s, a_0 = a)} \left[ \sum_{t=0}^{T-1} \gamma^t r_t \right]

So Vπ(s)V^\pi(s) tells us how good it is to be in a state under policy π\pi, while Qπ(s,a)Q^\pi(s,a) tells us how good it is to first take action aa from that state and then follow π\pi.

The advantage function compares these two quantities:

Aπ(s,a)=Qπ(s,a)Vπ(s).A^\pi(s,a)=Q^\pi(s,a)-V^\pi(s).

The advantage tells us whether action aa is better or worse than the average action under policy π\pi at state ss. If Aπ(s,a)>0A^\pi(s,a)>0, then action aa is better than average. If Aπ(s,a)<0A^\pi(s,a)<0, then it is worse than average.

Basic Properties of VπV^\pi and QπQ^\pi

The relationship between VπV^\pi and QπQ^\pi follows directly from the way an MDP generates a trajectory.

If we start from state ss, the policy first chooses an action aπ(s)a \sim \pi(\cdot \mid s). After that, the expected return is Qπ(s,a)Q^\pi(s,a). Therefore, the value of state ss is the average state-action value under the policy:

Vπ(s)=Eaπ(s)[Qπ(s,a)]V^\pi(s) = \mathbb{E}_{a \sim \pi(\cdot \mid s)} \left[ Q^\pi(s,a) \right]

Conversely, suppose we start from state ss and first take action aa. The environment gives reward rr and next state ss'. From that point on, we follow policy π\pi, so the remaining expected return is Vπ(s)V^\pi(s'). Therefore,

Qπ(s,a)=E(r,s)p(s,a)[r+γVπ(s)]Q^\pi(s,a) = \mathbb{E}_{(r,s') \sim p(\cdot \mid s,a)} \left[ r + \gamma V^\pi(s') \right]

These two equations connect VπV^\pi and QπQ^\pi. Combining them gives the one-step transition property.

For the state value function,

Vπ(s)=Eaπ(s), (r,s)p(s,a)[r+γVπ(s)]V^\pi(s) = \mathbb{E}_{a \sim \pi(\cdot \mid s),\ (r,s') \sim p(\cdot \mid s,a)} \left[ r + \gamma V^\pi(s') \right]

For the state-action value function,

Qπ(s,a)=E(r,s)p(s,a), aπ(s)[r+γQπ(s,a)]Q^\pi(s,a) = \mathbb{E}_{(r,s') \sim p(\cdot \mid s,a),\ a' \sim \pi(\cdot \mid s')} \left[ r + \gamma Q^\pi(s',a') \right]

Bellman Equation and Bellman Operator

For a fixed policy π\pi, define the Bellman operator TπT^\pi as the operator that maps V:SRV:\mathcal{S}\to\mathbb{R} to TπV:SRT^\pi V:\mathcal{S}\to\mathbb{R}:

(TπV)(s)=Eaπ(s), (r,s)p(s,a)[r+γV(s)](T^\pi V)(s) = \mathbb{E}_{a \sim \pi(\cdot \mid s),\ (r,s') \sim p(\cdot \mid s,a)} \left[ r + \gamma V(s') \right]

The one-step transition property for VπV^\pi can then be written as

TπVπ=Vπ.T^\pi V^\pi = V^\pi.

So VπV^\pi 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 VπV^\pi.

Theorem. Let π\pi be a fixed policy. Assume γ(0,1)\gamma \in (0,1), S<|\mathcal{S}|<\infty, and rR<|r|\le R<\infty almost surely. Then VπV^\pi exists and satisfies the Bellman equation

TπVπ=Vπ.T^\pi V^\pi = V^\pi.

Conversely, if a bounded function V:SRV:\mathcal{S}\to\mathbb{R} satisfies

TπV=V,T^\pi V = V,

then V=VπV=V^\pi.

Moreover, if we start from any bounded initial function V0V_0 and repeatedly apply the Bellman operator, the result converges to VπV^\pi:

limk(Tπ)kV0Vπ=0.\lim_{k\to\infty} \left\| (T^\pi)^k V_0 - V^\pi \right\|_\infty = 0.
Proof

Since rewards are bounded and γ(0,1)\gamma \in (0,1), the discounted return is bounded, so VπV^\pi is well defined. Also, by the one-step transition property, TπVπ=VπT^\pi V^\pi = V^\pi. Thus VπV^\pi is a fixed point of TπT^\pi.

Now we show that this fixed point is unique. We will use the Banach fixed point theorem.

Banach fixed point theorem. Let (X,d)(\mathcal{X}, d) be a complete metric space. Suppose T:XXT:\mathcal{X}\to\mathcal{X} is a γ\gamma-contraction with γ<1\gamma < 1, meaning

d(Tx,Ty)γd(x,y)x,yX.d(Tx, Ty) \le \gamma d(x,y) \quad \forall x,y \in \mathcal{X}.

Then TT has a unique fixed point xx^*. Moreover, for any xXx\in\mathcal{X},

Tkxxas k.T^k x \to x^* \quad \text{as } k\to\infty.

We will apply this theorem to the Bellman operator. Here, we work with bounded functions V:SRV:\mathcal{S}\to\mathbb{R} under the sup norm

V=maxsV(s).\|V\|_\infty = \max_s |V(s)|.

For any two bounded functions V1,V2:SRV_1,V_2:\mathcal{S}\to\mathbb{R},

TπV1TπV2=maxs(TπV1)(s)(TπV2)(s)=maxsEaπ(s), (r,s)p(s,a)[γ(V1(s)V2(s))]γmaxsEaπ(s), (r,s)p(s,a)[V1(s)V2(s)]γV1V2.\begin{aligned} \|T^\pi V_1 - T^\pi V_2\|_\infty &= \max_s \left| (T^\pi V_1)(s) - (T^\pi V_2)(s) \right| \\ &= \max_s \left| \mathbb{E}_{a \sim \pi(\cdot \mid s),\ (r,s') \sim p(\cdot \mid s,a)} \left[ \gamma \left(V_1(s') - V_2(s')\right) \right] \right| \\ &\le \gamma \max_s \mathbb{E}_{a \sim \pi(\cdot \mid s),\ (r,s') \sim p(\cdot \mid s,a)} \left[ \left|V_1(s') - V_2(s')\right| \right] \\ &\le \gamma \|V_1 - V_2\|_\infty. \end{aligned}

Therefore, TπT^\pi is a γ\gamma-contraction. By the Banach fixed point theorem, TπT^\pi has a unique fixed point, and repeatedly applying TπT^\pi from any bounded initial function V0V_0 converges to that fixed point.

Since VπV^\pi is already a fixed point, it must be the unique fixed point. Therefore, if any bounded function VV satisfies TπV=VT^\pi V=V, then V=VπV=V^\pi. Also,

limk(Tπ)kV0Vπ=0.\lim_{k\to\infty} \left\| (T^\pi)^k V_0 - V^\pi \right\|_\infty = 0.

The same idea holds for the state-action value function QπQ^\pi. Define the Bellman operator on Q:S×ARQ:\mathcal{S}\times\mathcal{A}\to\mathbb{R} by

(TπQ)(s,a)=E(r,s)p(s,a), aπ(s)[r+γQ(s,a)](T^\pi Q)(s,a) = \mathbb{E}_{(r,s') \sim p(\cdot \mid s,a),\ a' \sim \pi(\cdot \mid s')} \left[ r + \gamma Q(s',a') \right]

Theorem. Let π\pi be a fixed policy. Assume γ(0,1)\gamma \in (0,1), S<|\mathcal{S}|<\infty, A<|\mathcal{A}|<\infty, and rR<|r|\le R<\infty almost surely. Then QπQ^\pi exists and satisfies the Bellman equation

TπQπ=Qπ.T^\pi Q^\pi = Q^\pi.

Conversely, if a bounded function Q:S×ARQ:\mathcal{S}\times\mathcal{A}\to\mathbb{R} satisfies

TπQ=Q,T^\pi Q = Q,

then Q=QπQ=Q^\pi.

Moreover, if we start from any bounded initial function Q0Q_0 and repeatedly apply the Bellman operator, the result converges to QπQ^\pi:

limk(Tπ)kQ0Qπ=0.\lim_{k\to\infty} \left\| (T^\pi)^k Q_0 - Q^\pi \right\|_\infty = 0.

The proof is almost identical to the proof for VπV^\pi. 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.

Comments