Equations · Schulman et al., “Proximal Policy Optimization Algorithms” (2017)
The PPO clipped objective, explained term by term
PPO improves a policy using data collected by a slightly older copy of itself. The objective rewards making good actions more likely and bad ones less likely, but the clip removes any incentive to move the probability ratio more than away from 1 in one update. The objective is maximized.
Term by term
The probability ratio: how much more (or less) likely the new policy makes the action taken in state than the policy that collected the data. It is 1 at the start of each update. Here is not a reward, despite the letter.
Pi · Theta · Given (conditional bar) · State s and action a · Fraction
The estimated advantage: how much better action turned out than the policy's average in that state. Positive means "do this more". The hat marks an estimate, usually from GAE.
The smaller of the clipped and unclipped terms: a pessimistic bound. The clip can only lower the objective, never raise it, so the policy gains nothing by moving the ratio past the clip range in the helpful direction.
An empirical average over the time steps in the collected batch.
The superscript is a label naming this objective, not a power. The full PPO loss adds a value-function error and an entropy bonus.
A small worked example
With : a good action, , whose ratio has grown to . Unclipped: ; clipped: ; the min is , a constant, so there is no gradient pushing the ratio further. A bad action, , with : unclipped , clipped ; the min is , again flat in .
In code
import torch
def ppo_loss(logp_new, logp_old, adv, eps=0.2):
ratio = torch.exp(logp_new - logp_old) # r_t(theta)
unclipped = ratio * adv
clipped = torch.clamp(ratio, 1 - eps, 1 + eps) * adv
return -torch.min(unclipped, clipped).mean() # minimize the negativeEvery symbol in it
Other equations
- Scaled dot-product attention
- Softmax
- Cross-entropy loss
- Adam update
- Layer normalization
- RMSNorm
- The ELBO
- KL divergence
- Backpropagation through one layer
- LoRA
- GELU
- Dropout
- Batch normalization
- Rotary position embedding (RoPE)
- Multi-head attention
- DPO loss
- Policy gradient (REINFORCE)
- Bellman equation
- Q-learning update
- InfoNCE contrastive loss
- Diffusion forward process
- DDPM simplified loss
- VAE reparameterization trick
- GAN minimax objective
- AdamW
- Cosine learning-rate schedule
- Perplexity
- Logistic regression
- Normal equation (linear regression)
- Singular value decomposition (SVD)
- Principal component analysis (PCA)