Policy Gradient Methods in Reinforcement Learning
Policy Gradient Methods are a class of model-free reinforcement learning (RL) algorithms that optimize the policy directly by adjusting its parameters based on the gradients of the expected cumulative reward with respect to the policy parameters. These methods are particularly useful in environments with continuous action spaces or where value-based methods (like Q-learning) struggle or fail to perform well.
In contrast to value-based methods (like Q-learning and SARSA), which learn a value function (such as the Q-function) to estimate the expected reward for state-action pairs, policy gradient methods directly learn the policy itself, which maps states to actions.
Key Concepts of Policy Gradient Methods
-
Policy (π):
- A policy defines the agent's behavior by mapping each state to a probability distribution over possible actions . The policy can be deterministic or stochastic.
- The policy is parameterized by , which are the parameters (weights) of the model that need to be learned. The goal of policy gradient methods is to find the optimal parameters that maximize the expected cumulative reward.
-
Objective Function (Expected Reward):
- The agent's goal is to maximize the expected cumulative reward over time. This is usually represented as:
Where:
- denotes the expected value under the policy .
- is the discount factor.
- is the reward received at time .
- The agent's goal is to maximize the expected cumulative reward over time. This is usually represented as:
Where:
-
Gradient Ascent:
- Since we want to maximize the expected reward, we use gradient ascent to update the policy parameters in the direction that increases the objective function. The policy gradient is the gradient of the expected reward with respect to the policy parameters:
Where:
- is the score function (or log likelihood), which is the gradient of the log of the policy with respect to its parameters.
- is the return or discounted cumulative reward starting from time step .
The return can be computed in different ways, such as using Monte Carlo methods or temporal difference (TD) learning.
- Since we want to maximize the expected reward, we use gradient ascent to update the policy parameters in the direction that increases the objective function. The policy gradient is the gradient of the expected reward with respect to the policy parameters:
Where:
-
Stochastic Gradient Ascent:
- The policy gradient is typically estimated through Monte Carlo sampling or bootstrapping methods. Since computing the exact expectation is often not feasible, we approximate the gradient using samples from the environment.
Policy Gradient Theorem
The Policy Gradient Theorem provides the mathematical foundation for policy gradient methods. It states that the gradient of the expected return with respect to the policy parameters can be expressed as:
This theorem allows us to adjust the parameters of the policy in the direction of the gradient, thereby improving the policy.
Key Types of Policy Gradient Methods
-
REINFORCE (Monte Carlo Policy Gradient)
REINFORCE is one of the most basic policy gradient algorithms. It uses Monte Carlo sampling to estimate the gradient of the objective function.
- In REINFORCE, the agent interacts with the environment and collects episodes of state-action-reward trajectories. After completing an episode, the agent updates its policy based on the return of the episode.
- The update rule for REINFORCE is:
Where:
- is the learning rate.
- is the total return from time step .
Advantages:
- Simple and easy to implement.
- Can work well in environments with large state or action spaces.
Disadvantages:
- High variance in the gradient estimates due to the use of Monte Carlo methods.
- It may require many episodes to get an accurate estimate of the gradient, which can be computationally expensive.
-
Actor-Critic Methods
Actor-Critic is a more sophisticated approach that combines value-based and policy-based methods. The actor is responsible for selecting actions based on the policy, while the critic estimates the value function (often the state-value function or action-value function ) to guide the actor.
- Actor: Learns and updates the policy directly using the gradient of the expected return.
- Critic: Estimates the value function, which helps the actor reduce variance in the policy gradient updates.
The advantage function is used to estimate how much better or worse the chosen action was compared to the average action in that state. It is defined as:
Where:
- is the return (cumulative reward) starting at time step .
- is the value estimate for state .
The update rule for the actor is:
Advantages:
- Reduces variance in policy gradient estimates by using the critic’s value estimates.
- Typically more efficient than REINFORCE, as it does not require full episodes to update the policy.
Disadvantages:
- Requires both policy and value function estimations, which adds complexity.
- Convergence may still be slow depending on the choice of value function and learning rate.
-
Proximal Policy Optimization (PPO)
PPO is an advanced policy gradient method that aims to improve stability and performance by limiting the size of policy updates.
- PPO uses clipped objective functions to restrict the change in the policy between updates. The idea is to avoid large updates that can destabilize training.
- The objective function for PPO is designed to prevent the new policy from deviating too far from the old policy, which helps prevent policy collapse.
The objective for PPO is:
Where:
- is the advantage function.
- is a small constant (e.g., 0.2), controlling the range of policy updates.
Advantages:
- More stable than methods like REINFORCE and Actor-Critic.
- Often leads to better performance and faster convergence.
Disadvantages:
- More complex to implement and requires tuning of hyperparameters.
Summary of Policy Gradient Methods
- Policy gradient methods learn directly from the gradients of the expected reward, adjusting the policy parameters to maximize cumulative reward.
- REINFORCE is a simple policy gradient method that uses Monte Carlo sampling to estimate the gradients, but suffers from high variance.
- Actor-Critic methods combine policy gradient with value function estimation to reduce variance in updates and improve performance.
- Proximal Policy Optimization (PPO) is a more advanced algorithm that improves stability and efficiency by clipping the policy updates to prevent large, destabilizing changes.
These methods are useful for a variety of RL problems, especially those with large or continuous action spaces where traditional Q-learning or value-based methods struggle to perform well.