Article
Fundamentals of Reinforcement Learning
On this page 9
Background
Markov
Markov chains and Markov decision processes
In a Markov decision process, taking an action leads to a new state and a reward: .
Typical applications include:
- Game decisions
- Robot control
- Autonomous driving
In all these problems, an action affects both the next decision and outcomes further into the future. Reinforcement learning was originally developed to learn how to make such sequential decisions.
How Reinforcement Learning Works
In state , the agent chooses an action in an environment and moves to a new state . The environment assigns a reward to the transition. Reinforcement learning uses that reward to update the model that makes decisions.
A few more definitions:
-
: the expected return from taking action in state .
-
: a trajectory spanning multiple steps.
-
: the long-term return from time , given by . The discount factor gives less weight to more distant rewards.
Three Main Families of RL Methods
Reinforcement learning methods fall into three broad families depending on what they learn:
- Value-based
- Policy-based
- Actor-Critic
Value-based
We train a scoring model that takes and and returns . An interesting feature of this process is bootstrapping.
Here is the workflow:

For example, here I estimate the long-term return from taking action in state .
The training signal is therefore a long-term return. The target is .
The long-term return is the immediate reward, which comes directly from the environment, plus the discounted future return estimated by the Q model itself.
This is bootstrapping. You can think of the signal as propagating backward from the terminal step, where equals .
Policy-based
Here we learn a policy model.
The classic approach is policy gradient, which aims to increase the probability of choosing good actions. The diagram below shows the workflow.

After completing a trajectory, we update the policy using the outcome of that trajectory.
The update is the tricky part. Our objective is , where is the expected return across trajectories.
The objective is:
Here:
- denotes the policy parameters.
- is the probability that the current policy produces trajectory .
- is the cumulative return for that trajectory.
Expanding the expectation gives:
The expectation is an exact weighted sum over all possibilities. In training, we cannot enumerate the potentially unbounded number of trajectories, so we sample them.
We approximate the expectation with a Monte Carlo estimate, . As grows, the typical estimation error decreases at a rate of .
The probability weights are implicit in how often each outcome is sampled.
Plugging that approximation straight into gives . If we treat the sampled trajectories as fixed and differentiate this average, the gradient is zero. The environment supplies the scores, and there is no differentiable path from those scores back to the model parameters.
To retain the dependence on while still using samples, we use the identity . Differentiating first gives a term of the form . The sampling distribution accounts for , leaving the gradient of in the estimator.
In equations:
Since has no explicit dependence on , we can move inside the sum:
\nabla_\theta J(\theta) = \sum_{y} G(y) \nabla_\theta P_\theta(y)\tag{1}
Applying the identity gives:
\nabla_\theta J(\theta) = \sum_{y} G(y) \cdot P_\theta(y) \nabla_\theta \log P_\theta(y) \tag{3}
We can now sample to obtain the final gradient estimate:
The order of operations matters:
Differentiate the expectation to expose the gradient of the parameterized probability distribution, then apply Monte Carlo estimation to the resulting expectation.
Substitute , where .
After rolling out trajectories, the gradient estimate is:
This is a trajectory-level update.
We wait for the complete trajectory before updating, as in REINFORCE.
Actor-critic, below, shows how to update at each step.
Actor-Critic
state
│
┌────────┴────────┐
↓ ↓
Actor Critic
↓ ↓
Select action Evaluate state
│ │
└──────┬──────────┘
↓
Update Actor
Policy gradients can be unstable. Using the total return can give more weight to trajectories that already perform well, and variability in the environment can make the gradient estimate noisy.
A relative score helps. The advantage is the observed return minus the expected return.
This introduces the state value function , which the critic estimates.
The resulting advantage is .
With a value function, we can bootstrap as in the value-based method. Here we estimate using .
This yields the advantage estimate , also known as the temporal-difference error or TD error.
At step , we can compute the TD error and backpropagate without waiting for the trajectory to end. The actor loss at each step is .
Likewise, following the approach used in Q-learning, we can use as the target for updating the critic.
The critic evaluates the state. The actor provides the policy.
Combining RL and LLMs
A language model naturally acts as a policy if we take the full token prefix as its state. It predicts .
The concepts line up as follows:
RL LLM
state s = Current context
action a = Next token
policy π(a|s) = LLM's next-token distribution
trajectory = Full generated text
As we ask more of LLMs, we want them to:
- Solve more problems
- Behave more safely
- Reason their way to correct answers
- Write code that passes tests
These goals can be hard to achieve with supervised learning alone. This is a motivation for reinforcement learning from human feedback (RLHF).
PPO
Proximal Policy Optimization
The basic setup is still actor-critic, with a limit on how far the policy moves in one update.
PPO was introduced because an ordinary policy-gradient update can take too large a step. Clipping limits the incentive for large changes.
Define the probability ratio:
Then add a clipped ratio, .
The clipped objective is .
The first term inside the minimum expands to:
The ratio is the extra factor relative to the usual actor-critic loss, .
GRPO
Group Relative Policy Optimization uses a score relative to the rollout group in place of a critic prediction.
Think of it as a PPO-style policy update with a group-relative advantage and no critic.
If is the mean final reward for a group of rollouts, a simple advantage estimate is .
This example uses the final reward .
You could also use a return , though it may be harder to compute.