This project explores how one-step and multi-step temporal-difference (TD) learning algorithms perform in the Gymnasium Taxi-v3 environment.
Three tabular reinforcement learning algorithms are implemented and compared: Q-learning, 4-step Q-learning, and 4-step SARSA. The experiment examines how the choice of learning algorithm and the use of multi-step returns affect the agents' learning behavior and accumulated rewards.
Each algorithm is trained over multiple runs, and the resulting learning curves are used to compare their performance during training.
Install Python with gymnasium, numpy, matplotlib, and Jupyter. From the repository directory, open the notebook and run all cells in order:
jupyter notebook gym_taxiV3.ipynbThe notebook also saves the two comparison figures in plots/.
Q-learning is a model-free algorithm that updates action values after each transition.
This variant uses four observed rewards before bootstrapping from the maximum action value.
With
SARSA (State-Action-Reward-State-Action) uses the same four-reward horizon, but bootstraps from the action selected by its epsilon-greedy policy.
With
These returns stop without bootstrapping at true termination. At the 300-step time limit, pending returns instead bootstrap from the final nonterminal state, using the appropriate action value for each algorithm.
The Taxi-v3 experiment uses 500 episodes per run and 10 runs with seeds 123–132. Hyperparameters are fixed: learning rate
Each curve is the mean exponentially smoothed episode reward across the 10 runs. Within each run, smoothing starts at zero and follows
Main comparison: the reward-axis zoom emphasizes later training performance. Values below −200 are clipped; the horizontal axis still spans all 500 episodes.
Q-learning has higher mean smoothed reward early in training. Around the middle, 4-Step Q-learning moves ahead. 4-Step SARSA improves more strongly later and moves above Q-learning. Near the end, 4-Step Q-learning reaches the highest mean smoothed reward, followed by 4-Step SARSA and Q-learning (approximately −16.53, −23.26, and −38.98 at the final episode).
The animation below shows a trained 4-Step Q-learning agent solving the Taxi-v3 task.
Distributed under the MIT License. See LICENSE for more information.
– @Bortrex


