Abstract
This study investigates the impact of reward function design on the performance of a Q-Learning agent in a cart position control task. We compare continuous quadratic and linear rewards against a sparse, discontinuous reward function. Results demonstrate that while sparse rewards are more challenging to learn, they yield superior steady-state precision and faster convergence to the target position compared to traditional continuous functions, which often suffer from steady-state oscillations or "chatter."
Introduction
In Reinforcement Learning (RL), the reward function is the primary tool for communicating goals to an agent. Designing an effective reward function is a non-trivial task, often involving a trade-off between providing a dense gradient for easier learning and ensuring high precision in the final policy. This paper explores this trade-off using the classic cart position problem, where an agent must move a cart from an initial position ($x=0$) to a target ($x=10$) by modulating motor voltage.
Methodology
The study utilizes a Q-Learning agent operating within a simulated environment governed by a second-order differential equation. The simulation employs Euler’s method with a time step of 0.2 seconds. The agent's action space consists of discrete integer voltages ranging from -5 to 5.
Three distinct reward functions were evaluated:
- Quadratic Reward: $R = -(x-r)^2$, providing a continuous penalty proportional to the squared distance from the target.
- Linear Piece-wise Reward: A positive reward that increases linearly as the agent enters a predefined zone around the target.
- Discontinuous (Sparse) Reward: A step function providing a small reward (1) for proximity within 1 unit and a large reward (5) for proximity within 0.1 units.
The agent was trained over 100 samples, with each sample comprising 30 rounds of 50 time steps, totaling 150,000 transitions.
Results and Analysis
The experimental results highlight a significant performance gap between continuous and sparse reward structures.
The "Good Enough" Trap and Steady-State Chatter
Continuous reward functions, particularly the quadratic variant, were found to induce "chatter"—a persistent steady-state oscillation around the target. Because these functions provide relatively high rewards for being merely near the target, the agent often fails to find the exact voltage sequence required for a perfect stop, settling instead for a stable oscillation.
Precision of Sparse Rewards
In contrast, the discontinuous reward function acted as a high-precision guide. By concentrating the highest reward in an extremely narrow band at the target, it incentivized the agent to achieve zero variability at the steady state. The sparse reward agent reached the target $x=10$ in just 0.8 seconds, significantly outperforming both the other RL agents (1.0s) and theoretical proportional control solutions.
Discussion
While the sparse reward function yielded superior precision, it introduced a significant training trade-off. The agent required more samples to discover the narrow reward zone compared to continuous functions, which provide a helpful gradient from the start of training.
Furthermore, several practical limitations were identified. The optimal RL policy relied on extreme accelerations (up to $200 m/s^2$) that would be physically damaging to real-world hardware. The model also exhibited high sensitivity to physical parameters; minor deviations in the system's constants led to unstable, chaotic behavior.
Conclusion
This research demonstrates that sparse, discontinuous reward functions can drive RL agents toward higher precision and faster convergence in control tasks compared to continuous rewards. However, the increased difficulty in exploration and the resulting sensitivity to model parameters suggest that future work should integrate techniques like Deep Q-Learning (DQN) to enhance robustness and real-world applicability.
Summary updated