1. Introduction
In on-policy reinforcement learning (RL), training revolves around collecting data using the agent’s current policy and immediately leveraging this data to improve the same policy. Unlike off-policy methods, on-policy approaches rely exclusively on the most recent interactions with the environment, making them highly adaptive to policy changes but less sample-efficient.
This unique reliance requires a carefully structured approach to training and evaluation. Let’s explore how a typical setup is designed for effective learning and robust performance evaluation.
2. Training Configuration
Consider a setup designed for training over a fixed number of total interactions with the environment (N steps), with regular validation phases interspersed to monitor progress.
2a. Goal and Overall Structure
The training objective is to develop an optimal policy that maximizes cumulative rewards. This is achieved by:
- Data collection: The agent interacts with the environment using its current policy, gathering trajectories (state-action-reward sequences).
- Policy updates: Collected data is used to compute gradients and refine the policy.
- Validation phases: These occur periodically to assess the agent’s performance without altering the policy.
2b. Step-by-Step Process
1: Total Training Steps
Training spans a predetermined number of interactions (e.g., 100,000 or more, depending on the task's complexity). This total includes both training and validation periods.
2: Episodes and Interaction
- Training is structured into episodes, where each episode involves a sequence of interactions (state-action transitions) until a terminal state is reached or a predefined step limit (e.g., 200 steps per episode).
- Shorter episodes occur when the agent completes the task or fails earlier.
3: Data Collection and Immediate Use
On-policy methods differ from off-policy ones in their use of fresh data:
- Collected trajectories are used immediately for policy updates.
- A batch of experiences (states, actions, rewards) from recent episodes is processed to compute gradients and update the policy.
- The updated policy is used for subsequent interactions, ensuring alignment between data collection and training.
4: Why Immediate Updates Matter
On-policy methods require the policy used for data collection to match the one being updated. Delayed updates can introduce mismatches, leading to degraded learning.
5: Validation Phases
At regular intervals (e.g., every few thousand steps), a validation phase freezes the policy and evaluates its performance over several episodes.
6: Why Periodic Validation?
Regular validation strikes a balance between monitoring learning progress and uninterrupted training. This ensures issues like stagnation or overfitting are detected early, guiding potential adjustments to hyperparameters such as learning rate or entropy coefficients.
3. Outcome of the Training Process
By the end of the total training steps, the agent should have developed a well-optimized policy capable of achieving high performance. The structured alternation between data collection, immediate policy updates, and periodic validation ensures:
- Robust learning progress driven by recent interactions.
- Steady policy improvement aligned with the agent’s evolving behavior.
- Timely evaluations that provide actionable insights for fine-tuning training configurations.
4. Summary
On-policy training emphasizes adaptability by learning from the most recent data. While this approach can be sample-inefficient, it excels in dynamic environments requiring stable updates and quick adaptation. The combination of:
- Frequent data collection and immediate updates, and
- Regular validation phases makes on-policy methods such as REINFORCE, VPG, A3C, and GAE effective tools for policy optimization.
In the next lesson, we will implement these concepts in PyTorch, focusing on Vanilla Policy Gradient (VPG), Advantage Actor-Critic (A3C), and Generalized Advantage Estimation (GAE). These practical implementations will deepen your understanding of on-policy reinforcement learning algorithms and how to apply them to solve complex tasks.