Skip to content

Deep reinforcement learning and decision models · Method reference · DRL007 · Algorithm

Proximal policy optimization (PPO)

Enable several minibatch updates on a collected rollout using a surrogate designed to limit incentives for large policy changes.

Runs in CodeSplash (Experimental) Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page. The methods that run it are Experimental.

Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.

Availability
Runs in CodeSplash (Experimental)
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through decide.rl_ppo. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Enable several minibatch updates on a collected rollout using a surrogate designed to limit incentives for large policy changes. The clipped formulation is widely used, but PPO names a family that also includes KL-penalty variants.

Question / hypotheses

Can a simple first-order objective improve policy return without excessively changing the behavior policy that generated the batch? Clipping is an optimization device, not an exact trust-region guarantee or a statistical calibration procedure.

Architecture / computational structure

An actor outputs a stochastic action distribution, and a critic estimates state value; encoders may be shared or separate. Store old action log probabilities and advantage estimates from a rollout, then optimize minibatches over several epochs with an optional KL-based early stop.

Assumptions

Rollouts must correspond to the recorded old policy, and action probabilities must use the correct transformed distribution. Advantage estimates, terminal masks, and normalization need consistent treatment. Excessive reuse makes the current policy increasingly different from the behavior distribution.

Formula / computational definition

Lclip=E[min⁡(ρtA^t,clip⁡(ρt,1−ϵ,1+ϵ)A^t)]L^{\mathrm{clip}}=\mathbb E[\min(\rho_t\widehat A_t,\operatorname{clip}(\rho_t,1-\epsilon,1+\epsilon)\widehat A_t)]. Maximize this term while separately fitting the critic and optionally adding entropy; ρt=exp⁡(log⁡πθ−log⁡πold)\rho_t=\exp(\log\pi_\theta-\log\pi_{\mathrm{old}}).

Parameters and notation

Learned parameters are actor/critic weights and action distribution parameters. Hyperparameters include clipping epsilon, rollout length, minibatch size, update epochs, learning rate, discount, advantage lambda, entropy/value weights, gradient norm, and optional KL stop. These settings jointly govern effective update magnitude.

Fitting, fine-tuning, and adaptation

Transfer an encoder and compatible policy head, then collect new rollouts. Initially freeze the encoder or use a lower encoder learning rate; refit the critic if rewards change. Preserve a frozen old-policy snapshot per rollout and monitor KL during gradual unfreezing.

How to use and calibrate

Track return, KL, clip fraction, entropy, value fit, and environment steps across seeds. Use validation tasks and fixed evaluation conditions; a high fraction of clipped samples signals a changed optimization regime rather than automatically successful regularization.

Example application

Optimize a simulated continuous or discrete controller with batched policy updates. The code includes both positive and negative advantages to show why the clipped surrogate takes a minimum rather than clipping the loss indiscriminately.

Interpretation / pitfalls

Watch out

Clipping does not prevent all large KL changes. Incorrect treatment of truncated episodes or transformed continuous-action densities can silently bias updates. PPO performance depends strongly on implementation details, so a method label alone is insufficient for reproducibility.

Python and R code examples

Scope: computational component described in the application subsection; not a complete estimator, neural trainer, or environment loop. Dependencies/validation: Python with NumPy executed successfully; base R not executed. Targets and supplied network outputs are ordinary arrays here, so this does not validate automatic-differentiation boundaries.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — computational component described in the application subsection; not a complete estimator, neural trainer, or environment loop. · needs numpy

import numpy as np
ratio=np.array([1.3,.7,1.1,.9]); advantage=np.array([1.,1.,-1.,-1.]); epsilon=.2
unclipped=ratio*advantage; clipped=np.clip(ratio,1-epsilon,1+epsilon)*advantage
surrogate=np.minimum(unclipped,clipped)
actor_loss=-surrogate.mean(); print(surrogate,actor_loss)
assert np.all(surrogate<=unclipped+1e-12)
R

Component demo, not a trained model — computational component described in the application subsection; not a complete estimator, neural trainer, or environment loop.

ratio <- c(1.3,.7,1.1,.9); advantage <- c(1,1,-1,-1); epsilon <- .2
unclipped <- ratio*advantage; clipped <- pmin(pmax(ratio,1-epsilon),1+epsilon)*advantage
surrogate <- pmin(unclipped,clipped); actor_loss <- -mean(surrogate)
print(surrogate); print(actor_loss); stopifnot(all(surrogate<=unclipped+1e-12))

Sources

From the CodeSplash reference, entry DRL007.