From REINFORCE to PPO
REINFORCE follows the gradient of the expected return, Its steps can be too large. One unlucky sample can push the policy far from where it was, and the policy can collapse onto one action or diverge. PPO keeps each update close to the policy that collected the data, an approximation of a trust region, by working with probability ratios.The PPO objective
PPO measures how far the new policy has moved from the old one with the probability ratio and maximizes the clipped surrogate objective where estimates the advantage of the action taken: how much better it was than the average action in that state. The clipped term only matters on one side of the window, and which side depends on the sign of the advantage. For a good action () the objective stops growing once . For a bad action () it stops growing once . In both cases the gradient becomes zero, so the policy stops moving further in the direction the sample favors. On the other side of the window the unclipped term is active and the gradient is the usual one.Code
Code
Single-state example
The policy chooses between two actions. It is written with one logit , which keeps the policy a valid distribution for every and keeps the score bounded: and . Action earns a reward of 1 and earns 0, so the best policy has . The value of the state under the old policy is its expected reward, , so the advantage of a sample is . It is positive for and negative for , which gives both actions a gradient. Each outer iteration freezes , samples one action under it, and takes four mini-epochs of gradient ascent on the clipped surrogate. The gradient of the surrogate with respect to is while the unclipped term is active, and zero otherwise.Two-state example
The second environment adds a trajectory. The agent acts in state 1, then in state 2, with logits and . The reward is 1 when the action in state 2 is and 0 otherwise, so the action in state 1 has no effect on the reward and the best policy in state 1 is any policy. The example compares two ways of crediting the reward:- Shared reward. Both decisions use the trajectory reward, . This is what REINFORCE does without a baseline.
- True advantages. In state 1 both actions lead to the same expected reward, so for both actions and . In state 2 the advantage is .
Summary
PPO writes the policy-gradient update with probability ratios between the new and the old policy, and stops following a sample once its ratio leaves the clip window in the direction the sample favors. The single-state example shows that clipping decides whether to take a step. It does not bound the size of the step. The two-state example shows that the update is only as good as its advantage estimates: with the trajectory reward as the advantage, an action that does not matter still collapses onto one choice. Key references: (Schulman et al., 2017; Sutton & Barto, 2018)References
- Schulman, J., Wolski, F., Dhariwal, P., Radford, A., Klimov, O. (2017). Proximal Policy Optimization Algorithms. arXiv [cs.LG]. Link
- Sutton, R., Barto, A. (2018). Reinforcement Learning: An Introduction. Link
Found an error on this page? Report an issue.

