Introduction
A reinforcement learning agent rarely sees the true state of its environment. It sees an observation: a long vector of joint angles, velocities, and sensor readings for a robot, or the pixels of a screen for a game. A policy network trained on such observations can pick up on features that happen to go along with the reward during training but have nothing to do with the task. This is called observational overfitting [1]. The problem gets worse as the observation grows, since there are more irrelevant features to latch onto, and worse again when part of the observation is pure noise. An agent that overfits early in training often never recovers.
The usual remedy is data augmentation: transform the observation in ways that should not matter, such as scaling it by a random factor, and train the agent on the transformed versions. Methods such as RAD [2] and DRAC [3] do this and often help. But the choice of transformation is a form of prior knowledge. Someone has to decide which changes leave the task unchanged, and a wrong choice can hurt. On the DeepMind Control Quadruped Run task, RAD made a PPO agent about worse [4].
In 2023, Md Masudur Rahman and Yexiang Xue of Purdue University proposed APO (Adversarial Policy Optimization) [4], which learns the transformation instead of choosing it by hand. A second network, the perturber, learns to change the observation slightly in the way that changes the agent’s actions the most. The policy network, in turn, learns to keep its actions the same under those changes. The two networks play a max-min game, and the result is a policy that ignores the parts of the observation it should never have relied on. On the same Quadruped Run task, APO improved PPO by about .
Unlike most posts here, APO is not about language models. It is a deep reinforcement learning method for continuous control, but it is built directly on PPO, and the adversarial idea is close to the one behind GAPO. In this post, we go through the PPO objective APO starts from, the perturber and the policy losses, and the training algorithm, and end with its limitations.
The Starting Point: PPO
At every timestep , the agent receives an observation , takes an action , and gets a reward . These play the roles of the state and the token in the PPO post. The paper uses the words state and observation for the same thing, since in its experiments the agent sees the full state vector. APO adds its adversarial terms on top of a base policy optimization method, and in the paper that method is PPO [5]. Written as a loss to minimize, the PPO objective is:
This is the probability-ratio surrogate from Eq. (10) of the PPO post, with a minus sign so that it can be minimized. The ratio compares the current policy with the policy that collected the data, and the advantage says how much better the action turned out than expected. As in Eq. (2) of the PPO post, it is the action value minus the state value:
Both are measured in terms of the return , the discounted sum of the rewards from step onward, as in Eq. (3) of the PPO post, with in the paper:
The two halves are estimated exactly as in the PPO post. The return the agent actually collected after taking is one sample of . comes from a value network, trained with the mean squared error of Eq. (4) of the PPO post to predict the average return, , as in Eq. (5) of the PPO post.
There is one problem. PPO collects data in rollouts of a fixed length, steps in the paper, and the episode usually has not ended when the rollout stops at step . The rewards up to are known, but the rewards from step onward were never observed. So we split the return at step into the part we saw and the part we did not:
In the second sum, every term carries at least . Taking it out, and counting from step with , leaves exactly the return from step :
is unknown, but its expected value is exactly what the value network predicts, . Replacing with , and writing out the observed sum, gives the estimate of the action value:
If the episode did end before step , nothing comes after it, and is set to . This way of filling in the unseen future with a predicted value is called bootstrapping, as in the TD estimate of the PPO post.
Subtracting gives the advantage estimate used in the paper [4]:
How far ahead the observed rewards reach decides what kind of estimate this is. If the rollout stops one step after , so that , only one reward is observed, and Eq. (2) becomes:
which is the TD error from Eq. (7) of the PPO post. It relies mostly on the value network, so it has low variance but inherits the network’s errors. If instead the episode ends before , so that , every reward is observed, and it becomes the Monte Carlo estimate from Eq. (6) of the PPO post, which is unbiased but noisy. Eq. (2) lies between the two.
In the implementation, the ratio is clipped with , as in the clipped surrogate objective. And instead of a single estimate of Eq. (2), the advantage is computed with GAE, with , which averages such estimates over every lookahead [4]. Nothing in this part is new. APO’s contribution is what it adds to .
The Max-Min Game
APO trains two networks against each other. The perturber network, with parameters , takes an observation and returns a perturbed observation . The policy network is the agent itself. To measure how much the perturbation changes the agent’s behavior, APO compares the action distributions the policy gives for the two observations, and , with the KL divergence.
The perturber wants this KL divergence to be large: it looks for a change to the observation that makes the agent act differently. The policy wants it to be small: it should act the same way whether or not the observation was perturbed. One side maximizes the same quantity that the other minimizes, which is what makes it a max-min game.
The Perturber Network
A perturber that is free to change anything would win easily. It could replace the observation with noise, and no policy could act the same on noise as on the real observation. So the perturber is also asked to keep its change small, measured by the squared distance between the two observations. Its loss is [4]:
Minimizing the first term keeps the distortion small. Minimizing the second term, which has a minus sign, makes the KL divergence large. Together, the perturber is pushed toward the smallest change that moves the agent’s action the most. A small change that moves the action a lot is exactly a sign of overfitting. If a slight nudge to some features makes the agent behave very differently, the policy is relying heavily on those features.
The Policy Network
The policy network keeps learning from the reward with of Eq. (1), and adds the same KL divergence as a penalty [4]:
The KL term appears in Eq. (3) with a minus sign and in Eq. (4) with a plus sign. The perturber tries to make it larger, and the policy tries to make it smaller. For the policy, making it smaller means giving the same action distribution for and , which in turn means paying little attention to the features the perturber changed. Since the perturber always targets the features the policy is currently most sensitive to, the policy is steadily pushed away from relying on any small, easily changed part of the observation. The first term, meanwhile, keeps it learning the task.
This is how APO replaces a hand-chosen data augmentation. RAD decides in advance that, for example, scaling the observation should not change the action. APO lets the perturber find, at every step, the changes that the current policy is most vulnerable to. The two can also be combined: in the paper’s experiments, the observation is first scaled by a random factor between and , as in RAD, and then passed to the perturber and the policy [4].
The APO Algorithm
The two losses are minimized in turns. The agent first collects data with its current policy, then, for each collected observation, the perturber produces a perturbed observation, the policy is updated with Eq. (4), and the perturber is updated with Eq. (3) [4]:
Compared with PPO, the new parts are the perturber, in lines 1, 8, and 11, and the KL term inside line 10. The perturber is used during training only. At test time, the agent acts on the real observation, and the perturber is thrown away.
Limitations of APO
APO was tested only on vector observations, not on images, where data augmentation methods such as RAD are most often used, and only with PPO as the base algorithm. The APO agent in the experiments also used RAD’s random scaling, and the paper does not report APO without it, so how much of the gain comes from the adversarial game alone is not clear. The two terms of the perturber loss in Eq. (3), and the two terms of the policy loss in Eq. (4), are added with equal weight. The squared distance depends on the scale of the observation, so the balance between a small change and a large KL divergence may need tuning on other tasks. Finally, the gains vary a lot across random seeds, and on some tasks RAD or DRAC still did better.
APO showed that instead of guessing which changes to the observation should not matter, an agent can train against a network that searches for the changes it is most sensitive to, and learn to ignore them.
References
- Song, X., Jiang, Y., Tu, S., Du, Y., & Neyshabur, B. (2020). Observational Overfitting in Reinforcement Learning. ICLR.
- Laskin, M., Lee, K., Stooke, A., Pinto, L., Abbeel, P., & Srinivas, A. (2020). Reinforcement Learning with Augmented Data. NeurIPS.
- Raileanu, R., Goldstein, M., Yarats, D., Kostrikov, I., & Fergus, R. (2020). Automatic Data Augmentation for Generalization in Deep Reinforcement Learning. arXiv:2006.12862.
- Rahman, M. M., & Xue, Y. (2023). Adversarial Policy Optimization in Deep Reinforcement Learning. arXiv:2304.14533.
- Schulman, J., Wolski, F., Dhariwal, P., Radford, A., & Klimov, O. (2017). Proximal Policy Optimization Algorithms. arXiv:1707.06347.