r/learnmachinelearning • u/JuggernautHeavy6839 • 14d ago
[RL / Gymnasium] Need help designing a custom reward function for a "shuttle" behavior in CartPole-v1
Hi everyone! I'm working on a custom reward function for the CartPole-v1 environment in Gymnasium and could use some advice.
The Objective ("Shuttle" Task)
I need to write a custom reward function (reward_type == "shuttle") that incentivizes the agent to:
- Balance the pole continuously.
- Move back and forth across the track from the leftmost to the rightmost side (wide oscillations, not just jittering around the center x=0).
- Maintain a high velocity and change direction at least once (avoiding random drift).
State Variables Available
- x: cart position (range approx. [-2.4, 2.4])
- dot{x}: cart velocity
- theta: pole angle
- dot{theta}: pole angular velocity
Does anyone have suggestions or standard mathematical formulations (e.g., combining position tracking, velocity rewards, or oscillating targets) to achieve this behavior effectively? Thanks!