When an agent chooses an action, its reward alone does not say whether the choice was good: some states offer better prospects than others. The advantage function compares the expected future reward from taking an action with the expected future reward from the state under the current policy. In shorthand, A(s, a) = Q(s, a) − V(s). A positive advantage favors that action relative to the state’s baseline; a negative one disfavors it. section 12.1.2 section 12.1.4
In a policy-gradient update, an estimated advantage gives feedback on an action sampled from the policy. Positive estimates increase the probability of choosing that action in similar states; negative estimates decrease it. In advantage actor-critic (A2C), the actor produces action probabilities, while the critic supplies value estimates that serve as a baseline for this feedback. section 12.1.2 section 12.1.4
A CartPole step
For CartPole, the actor chooses between pushing left and pushing right. A one-step advantage estimate is reward + (1 − done) × γ × V(next state) − V(current state). If the episode ends, the next-state term vanishes; otherwise, the discount factor γ weights its estimated future value. The implementation minimizes the mean squared advantage to update the critic, then uses the sampled action’s negative log probability times a detached advantage to update the actor. It tracks episode rewards to see whether balancing improves. section 12.3
advantage = reward + (1-
done)*gamma*critic(torch.from_numpy(next_state).float()) -
critic(torch.from_numpy(state).float()) #1
total_reward += reward #2
state = next_state #3
#1 Compute the advantage function.
#2 Update the total reward.
#3 Move to the next state.
Inspect the one-step calculation to see how the reward, terminal flag, discount factor, and two critic estimates combine. section 12.3
The estimate depends on the policy and the experiences collected under it. Repeatedly updating a policy on one batch can move it far from the policy that generated those experiences, making the advantage estimate inaccurate. Proximal policy optimization (PPO) addresses large policy shifts with penalty- or clipping-based variants. An advantage is useful feedback, but its reliability still matters when choosing how far to update. section 12.1.5


