Understanding Policy Gradient Algorithms: A Sensitivity-Based Approach

Shuang Wu, Ling Shi, Jun Wang, Guangjian TianICML 2022

TL;DR

This paper bridges the long-standing gap between policy gradient (PG) theory and its practical implementations using a unified "perturbation" framework. The authors reveal that while many modern Reinforcement Learning (RL) libraries contain subtle mathematical "errors" in how they handle discount factors, these algorithms still succeed. This is largely because high discount factors minimize the error, and experience replay effectively re-aligns the gradients with the correct objective.

What Problem Does This Paper Address?

In the world of RL, there is a curious disconnect. On one hand, we have the theoretical foundation of Policy Gradients laid out by Sutton et al. (1999). On the other, we have the practical REINFORCE algorithm by Williams (1992). Most modern implementations (like those in OpenAI Spinning Up or MATLAB) actually follow a hybrid approach that researchers recently discovered is mathematically inconsistent. Specifically, they often drop a necessary discounting factor when calculating gradients from sampled trajectories.

Despite these "incorrect" implementations, PG algorithms like PPO and TRPO are wildly successful. This paper seeks to answer two main questions:

  1. Can we derive all these different PG formulas (stochastic, deterministic, discounted, average reward) from a single, unified principle?
  2. Why do "erroneous" implementations work so well in practice?

Methods

The authors use a perturbation approach (also known as sensitivity analysis). Instead of starting with complex integral calculus, they define the gradient as the limit of the performance difference between two slightly different policies ($\pi$ and $\pi + \delta\pi$).

By analyzing how a small "perturbation" in the policy affects the long-term performance metric, they derive a unified "Performance Difference Lemma." This allows them to:

  • Unify Derivations: Derive stochastic and deterministic PGs for discounted, total, and average reward setups using the exact same mathematical steps.
  • Bridge Theory and Practice: Precisely map the "spatial" theoretical formula (which sums over the entire state space) to the "temporal" empirical formula (which sums over a sampled trajectory).

Datasets and Environments

As a theoretical study, the paper uses controlled synthetic environments to isolate specific behaviors:

  • Controlled Restart Process: A Markov Decision Process (MDP) used to test continuing tasks and average reward objectives.
  • Binary Chain: A specific MDP setup designed to highlight how incorrect discounting leads to suboptimal policies.
The binary chain environment used to demonstrate the impact of discounting factors.

Key Insights and Ideas

  • The "Missing" Discount Factor: The authors confirm that to be strictly unbiased, the empirical PG formula needs an additional $\gamma^k$ term (where $k$ is the time step). Most modern codebases omit this.
  • The Safety of $\gamma \approx 1$: They prove that as the discount factor $\gamma$ approaches 1, the approximation error of the "incorrect" implementation vanishes. Since most practitioners use $\gamma = 0.99$ or higher, the error remains negligible.
  • Experience Replay as a "Fix": This is perhaps the most surprising insight. Experience replay (ER) breaks the correlation between transitions. The authors show that sampling from a replay buffer effectively changes the state distribution. Under this new distribution, the "incorrect" PG implementation actually becomes an unbiased estimate of a different objective—one that happens to have the exact same optimal policy (maximizer) as the original objective.
  • Maximizer Invariance: They demonstrate that the optimal policy $\pi^*$ is independent of the initial state distribution $\rho_0$. Since ER essentially creates a new "virtual" initial distribution, the gradient points toward the same peak, even if the path taken to get there is slightly different.

Key Results

The numerical experiments validate that "true" policy gradients (pg-true) always converge to the optimum. However, they show that:

  • In continuing tasks, "incorrect" discounting (pg-discount) leads to suboptimal performance because it effectively shortens the agent's "horizon."
  • When Experience Replay is simulated (pg-replay), the performance matches the true gradient much more closely, confirming that ER mitigates implementation errors.
Convergence trajectories showing how different PG variants perform across different task settings.

As seen in the convergence trajectories above, while the "incorrect" discounted version (pg-discount) might converge to a higher optimality gap (worse performance) in some settings, the inclusion of replay-style weighting helps stabilize and drastically improve the results.

Limitations and Future Work

The authors acknowledge that their "Maximizer Invariance" proof—which explains why Experience Replay helps—is strictly proven for tabular MDPs (where every state-action pair is tracked). In the real world, we use function approximators (like Deep Neural Networks). If a neural network doesn't have the capacity to represent the true optimal policy, the invariance might break, and the "incorrect" gradient could lead the agent astray.

Future work could involve extending this sensitivity-based analysis to more complex function approximation settings to see if the "ER-as-a-fix" theory holds up in massive, high-dimensional state spaces.

Summary updated

BibTeX
@inproceedings{wu2022understanding,
  author = {Shuang Wu and Ling Shi and Jun Wang and Guangjian Tian},
  title = {{Understanding Policy Gradient Algorithms: A Sensitivity-Based Approach}},
  booktitle = {International Conference on Machine Learning},
  year = {2022},
}
Figure