Policy Gradient Methods
Policy Gradient Methods are a class of algorithms in reinforcement-learning that optimize the policy directly, rather than learning a value function and selecting actions greedily based on it. The policy is parameterized as a function , where is the parameter vector (such as the weights of a neural network).
Unlike value-based methods like Q-learning, policy gradient methods find an optimal policy by performing gradient ascent on the expected cumulative reward.
Direct Parameterization vs. Value-Based Methods
| Feature | Value-Based (e.g., Q-Learning) | Policy Gradient (Direct Parameterization) |
|---|---|---|
| Objective | Learn action-value function | Learn policy parameters directly |
| Policy Formulation | Implicitly derived (e.g., -greedy) | Explicitly parameterized |
| Action Space | Typically discrete | Discrete and continuous action spaces |
| Stochasticity | Deterministic (requires exploratory noise) | Can naturally learn optimal stochastic policies |
| Convergence | Can oscillate or diverge with function approximation | Guaranteed convergence to a local (or global) optimum |
Mathematical Formulation
Let be a trajectory (or rollout) of states and actions. The probability of trajectory under a policy and transition dynamics is:
The expected return of the policy is defined as:
where is the cumulative discounted reward of the trajectory.
We want to find parameters that maximize :
To optimize this using gradient ascent, we compute the gradient :
The Likelihood Ratio / Log-Derivative Trick
Because the expectation depends on through the distribution , we cannot directly take the derivative inside the expectation. Instead, we use the identity :
Substituting the probability of the trajectory, the environmental transition dynamics drop out because they do not depend on :
Thus, the policy gradient is:
This is the foundational mathematical equation of policy gradient methods. Crucially, it does not require knowing the transition dynamics .
Policy Gradient Theorem
In continuing tasks (without a fixed episode length), the gradient can be expressed in terms of the stationary distribution :
Using the log-derivative trick:
Variance Reduction & Baselines
A major limitation of the basic policy gradient formula is high variance, since the return is computed from sample trajectories. We can subtract a state-dependent baseline from the return to reduce variance without introducing bias.
The baseline must not depend on the action . A common choice is the state-value function . The difference is known as the Advantage Function :
The advantage measures how much better action is than the average action in state . Using the advantage function yields the policy gradient update:
Key Algorithms
1. REINFORCE (Monte Carlo Policy Gradient)
REINFORCE is the simplest policy gradient algorithm. It estimates the return using Monte Carlo rollout returns :
- Pros: Unbiased gradient estimates, simple to implement.
- Cons: Extremely high variance, requires complete episodes before making updates.
2. Actor-Critic Methods
Actor-Critic methods reduce variance by combining policy gradient with a learned value function:
- Actor: Represents the policy and updates it via gradient ascent.
- Critic: Learns a parametric value function to estimate the expected return (e.g., temporal-difference learning).
- Update Rule: The policy update uses the TD error as an estimate of the advantage:
3. Proximal Policy Optimization (PPO) & Trust Region Policy Optimization (TRPO)
- TRPO constrains policy updates using the Kullback-Leibler (KL) divergence to prevent the policy from changing too drastically.
- proximal-policy-optimization (PPO) simplifies this by using a clipped surrogate objective that achieves similar stability with first-order optimization.
Advantages and Disadvantages
Advantages
- Continuous Action Spaces: Value-based methods require calculating , which is intractable for infinite action spaces. Policy gradient methods parameterize continuous distributions (e.g., Gaussian policies) and sample from them directly.
- Stochastic Policies: In partially observable environments or competitive games, the optimal policy may be stochastic (e.g., rock-paper-scissors). Policy gradient methods can learn these distributions naturally.
- Smooth Optimization: Because the policy is direct, small parameter changes lead to small policy changes. Value-based methods can have abrupt changes in behavior.
Disadvantages
- High Variance: High variance in returns leads to noisy gradients and slow learning.
- Sample Inefficiency: Typically require a vast number of environment steps to learn effective policies compared to off-policy value-based algorithms.
- Local Optima: Prone to converging to local optima rather than the global optimum.