Intuition The ONE core idea
PPO is a recipe for making a decision-maker (a "policy") a little bit better each round using experience it already collected, while a safety rule stops it from changing so much that it wrecks itself. Everything below is just the vocabulary you need to read that one sentence precisely.
Before you can read the Proximal Policy Optimization (PPO) page, you meet a wall of symbols: π θ , A ^ t , r t , γ , λ , ϵ , E , ∇ , log . This page builds each one from nothing, in an order where every symbol is earned before it is used.
Intuition The picture everything sits on
Imagine a little robot in a maze. At every tick of a clock it looks (sees where it is), acts (steps some direction), and gets a reward (a number: +1 for cheese, 0 for a plain tile, −1 for a trap). Then the world moves it to a new spot, and it repeats. That endless look → act → reward → new-look cycle is the whole game.
Figure s01 (below) draws exactly this loop: the four rounded boxes are the four things that happen every tick — read State (top-left) → Policy picks Action (top-right, the agent decides arrow) → Reward (bottom-right) → World gives a new state (bottom-left, the world reacts arrow) → back up to State. Trace the arrows once and you have seen the entire game an RL agent plays.
We give names to the pieces of this loop. Each name is a symbol you will see everywhere in PPO.
s
s (for s tate) is a snapshot of "where the robot is / what it currently sees." In the maze picture it is which tile the robot stands on. We write s t for the state at time-step t (tick number t of the clock).
a
a (for a ction) is the choice the robot makes: up, down, left, right. a t is the action taken at time t . The world reacts to a t by moving the robot to the next state s t + 1 .
r t and return
The reward r t is the immediate number the world hands back at step t , right after the agent takes action a t in state s t (e.g. + 1 for cheese). It is a single number, indexed by the time-step, so r 0 , r 1 , r 2 , … is the stream of rewards along one run.
⚠️ In RL the letter r is overloaded: r t here means reward at step t ; much later the same letter appears as the probability ratio r t ( θ ) . They are unrelated — the probability ratio always carries the argument ( θ ) , the reward never does. Watch for that.
The return is the total (discounted) reward collected over a whole run — that is what we ultimately want to be large.
= return
Why they get confused: both are "how good things are."
The difference: reward r t = this step's number. Return = the sum over the whole episode . A move with tiny reward now can lead to huge return later. PPO cares about return, not just the next reward.
τ
A trajectory τ (Greek "tau") is one complete run through the loop — the whole ordered list of what happened:
τ = ( s 0 , a 0 , r 0 , s 1 , a 1 , r 1 , s 2 , a 2 , r 2 , … )
Picture it as a single path the robot traced through the maze from start to finish. Because the policy is random, running it again gives a different τ — so τ is itself a random object.
Definition Return of a trajectory
R ( τ )
R ( τ ) is the total reward earned along that one path — you add up the rewards, discounting later ones by γ (defined below):
R ( τ ) = ∑ t = 0 ∞ γ t r t
So R ( τ ) turns an entire run into a single score. "Which run was better?" = "which τ has the larger R ( τ ) ?" The whole point of learning is to make runs with big R ( τ ) more likely.
J ( θ )
J ( θ ) is the average return over all the random paths the policy might take :
J ( θ ) = E τ ∼ π θ [ R ( τ ) ]
The subscript τ ∼ π θ reads "τ is drawn from policy π θ " — i.e. the paths are generated by rolling out the current policy. (E is defined two sections down.) Training = adjust the knobs θ to push J ( θ ) up.
π ( a ∣ s )
A policy is the robot's brain: given the state s , it outputs how likely it is to take each action . The bar "∣ " reads "given ." So π ( a ∣ s ) = "probability of doing action a given we're in state s ." These probabilities are non-negative and add up to 1 across all actions.
Figure s02 (below) shows one such policy as a bar chart: four bars (up/down/left/right), heights are the probabilities, and they sum to 1 . Notice "up" is tallest (most likely) while "left" is a short-but-nonzero bar — that surviving small bar is the exploration the entropy bonus later protects.
probability , not a fixed choice?
If the robot always did the exact same thing in a state, it could never discover a better move. Randomness = built-in curiosity. Look at the bars in the figure: "up" has the tallest bar, so it's most likely, but "left" still has a small bar — the robot occasionally tries it and might learn it's great. Keeping those small bars alive is exactly what the entropy bonus later protects.
θ and π θ
θ (Greek "theta") is the giant list of numbers inside the neural network — every weight, every dial. Change θ and you change the policy. We write π θ to say "the policy produced by the current setting of the knobs." Learning = searching for the θ that makes returns large.
π θ o l d — the frozen snapshot
π θ o l d is the policy as it was when we collected our batch of experience , before this round of learning. During a learning round we keep it frozen as a reference. The new, being-updated policy is just π θ . PPO's whole safety rule is "don't let π θ drift too far from π θ o l d ." You cannot even state that rule without both symbols — see Importance Sampling .
E [ ⋅ ]
E (a fancy "E") means expected value = the long-run average of the thing in the brackets. Because actions are random, any single run is luck; E asks "what happens on average over many runs?"
E [ X ] = ∑ outcomes ( probability of outcome ) × ( value X of outcome )
Worked example Concrete expectation
A die-roll rewards you the number shown. Each face has probability 6 1 .
E [ roll ] = 6 1 ( 1 + 2 + 3 + 4 + 5 + 6 ) = 6 21 = 3.5
You never roll a 3.5 — it's the average. This is exactly the E in J ( θ ) = E τ ∼ π θ [ R ( τ )] : the average of the run-scores R ( τ ) over all paths the policy might take.
V ( s )
V ( s ) (V alue of a state) is the expected return if we start in state s and follow the policy from there . It's a single number scoring "how promising is this spot?" A critic network estimates it.
A ^ ( s , a )
The advantage answers: "was action a better than what I'd normally do in state s ?" It compares the outcome of the action to the state's baseline value V ( s ) :
A ^ = ( return we actually got after a ) − V ( s )
The hat " ^ " means estimated (from data, not known exactly). A ^ > 0 = "better than average, do more of it." A ^ < 0 = "worse than average, do less."
Figure s03 (below) makes this concrete: three actions all give returns near + 100 (mint bars), and the red dashed line is the baseline V ( s ) = 100 . The label above each bar is A ^ = return − V ( s ) — only + 3 , − 2 , + 1 survive. That subtraction is what separates good from bad when raw numbers all look alike.
V ( s ) at all?
Suppose every action in a state gives return around +100. Raw returns tell you nothing about which action to prefer — they're all big. Subtract the baseline V ( s ) ≈ 100 and only the differences survive: now +2 vs −3 clearly separate good from bad. This "subtract the average" trick slashes noise (variance) without biasing the direction — the heart of Actor-Critic Methods .
Definition Discount factor
γ
γ (Greek "gamma"), between 0 and 1 , makes future rewards worth slightly less than immediate ones . A reward l steps away is multiplied by γ l . With γ = 0.99 , a reward 100 steps away still counts a fair amount; with γ = 0.9 it's nearly forgotten. It keeps infinite-horizon sums finite and encodes "sooner is better."
δ t
The temporal-difference error measures surprise at one step:
δ t = r t + γ V ( s t + 1 ) − V ( s t )
In words: (reward I just got, r t ) + (discounted value of where I landed) − (value I expected from where I was). Positive = "better than expected." It's a one-step estimate of advantage. See Generalized Advantage Estimation (GAE) .
λ and the full estimate A ^ t G A E
λ (Greek "lambda"), between 0 and 1 , blends many one-step surprises into a single advantage estimate. The full Generalized Advantage Estimation formula is a λ -weighted sum of all future TD errors:
A ^ t G A E = ∑ l = 0 ∞ ( γ λ ) l δ t + l = δ t + ( γ λ ) δ t + 1 + ( γ λ ) 2 δ t + 2 + ⋯
Each step further into the future is down-weighted by another factor γ λ .
λ = 0 → only the first term survives, A ^ t = δ t : trusts one step (low noise, but biased by a possibly-wrong V ).
λ = 1 → the sum telescopes into the full real return minus V ( s t ) : unbiased, but noisy.
λ ≈ 0.95 → the sweet spot — a bias–variance dial .
log — the logarithm
log ( x ) answers "what power do I raise the base to, to get x ?" We use log π θ ( a ∣ s ) = the log-probability of the chosen action. Two reasons: (1) it turns the tiny multiplied probabilities of a long path into a friendly sum , and (2) its derivative gives the clean policy-gradient formula below.
∇ θ — the gradient
∇ θ (the "nabla") is the vector of slopes of a quantity with respect to every knob in θ at once. It points in the direction of steepest increase . "Take a gradient step" = nudge θ a little along ∇ θ J to make J bigger. This is the engine of all deep learning — see the Policy Gradient Theorem .
Definition Probability ratio
r t ( θ )
r t ( θ ) = π θ o l d ( a t ∣ s t ) π θ ( a t ∣ s t )
"How much more or less likely does the new policy make the action that the old policy actually chose?" r t = 1 → unchanged. r t = 1.2 → 20% more likely. r t = 0.8 → 20% less likely. (Note the ( θ ) argument — this is the ratio r t , not the reward r t .) It is how we reuse old data (via Importance Sampling ) and it is the exact quantity PPO clips .
ϵ and the clip function
ϵ (Greek "epsilon", typically 0.2 ) sets the safe band [ 1 − ϵ , 1 + ϵ ] = [ 0.8 , 1.2 ] . The function clip ( r , 0.8 , 1.2 ) squashes r back into that band: anything below 0.8 becomes 0.8 , anything above 1.2 becomes 1.2 , in-between passes through untouched.
Figure s04 (below) graphs this: the dotted diagonal is the untouched ratio r , the lavender curve is clip ( r , 0.8 , 1.2 ) . Inside the mint band the two coincide (clip does nothing); outside, the lavender line goes flat — a ratio of 1.5 is pinned to 1.2 , a ratio of 0.5 is lifted to 0.8 .
Now that every symbol is defined, here is the objective PPO maximizes — the clipped surrogate :
Policy pi outputs action probabilities
Parameters theta are the knobs of pi
Trajectory tau and return R of tau
Objective J is average return
Expectation E averages over randomness
Advantage A hat = better than average
Discount gamma and TD error
GAE lambda blends estimates of A hat
Policy Gradient direction
Frozen pi old vs new pi gives ratio r
Clip with epsilon keeps r in safe band
Test yourself — cover the right side.
What does s t stand for? The state (snapshot of where the agent is / what it sees) at time-step t .
What is a trajectory τ ? One complete run through the loop — the ordered list ( s 0 , a 0 , r 0 , s 1 , a 1 , r 1 , … ) ; a random object since the policy is random.
Write R ( τ ) and say what it measures. R ( τ ) = ∑ t ≥ 0 γ t r t — the total discounted reward of one whole run.
What does J ( θ ) equal? J ( θ ) = E τ ∼ π θ [ R ( τ )] — the average return over all paths the policy might take.
What does π ( a ∣ s ) output, and what must the outputs sum to? The probability of each action given state s ; they sum to 1 .
What is the difference between θ and π θ ? θ is the list of network knobs; π θ is the policy those knobs produce.
Why keep a frozen π θ o l d ? It's the reference the new policy must not drift too far from; it's also the policy that collected the data.
What does E [ X ] mean and equal for a fair die reward? The long-run average of X ; for a die it is 3.5 .
Why does the policy gradient use ∇ θ log π θ ? The log-derivative identity ∇ π = π ∇ log π turns ∇ θ J into an average we can estimate from sampled runs.
Why do we subtract V ( s ) to form the advantage? To remove the state's baseline so only the difference between actions remains — cutting variance without bias.
Give the TD error formula. δ t = r t + γ V ( s t + 1 ) − V ( s t ) .
Write the full GAE advantage. A ^ t G A E = ∑ l ≥ 0 ( γ λ ) l δ t + l .
What does λ trade off in GAE? Bias vs variance (λ = 0 low-variance biased one-step; λ = 1 unbiased noisy full return).
What does the gradient ∇ θ point toward? The direction in knob-space of steepest increase of the quantity.
Write the probability ratio and say what r t = 0.8 means. r t ( θ ) = π θ ( a t ∣ s t ) / π θ o l d ( a t ∣ s t ) ; r t = 0.8 means the new policy makes the action 20% less likely.
Write the PPO clipped-surrogate objective. L C L I P = E t [ min ( r t A ^ t , clip ( r t , 1 − ϵ , 1 + ϵ ) A ^ t )] .
What does clip ( r , 0.8 , 1.2 ) do to r = 1.5 and to r = 1.05 ? Squashes 1.5 → 1.2 ; leaves 1.05 unchanged.