This repository contains code for implementing the Q-Learning algorithm using the Taxi-v3 environment from the OpenAI Gym.
To run this code, you need the following dependencies:
- Python 3.x
- Gym:
pip install gym
- NumPy:
pip install numpy
- Clone the repository:
git clone https://github.com/your_username/your_repository.git
- Navigate to the cloned repository:
cd your_repository
- Open the Python script
q_learning_taxi.py
. - Configure the number of episodes, learning parameters, and other settings as needed.
- Run the script:
python q_learning_taxi.py
.
The code performs the following steps:
- Imports the necessary libraries and initializes the Taxi-v3 environment.
- Runs a specified number of episodes, where each episode represents a learning iteration.
- Resets the environment for each episode and plays the game until completion.
- Renders the environment to visualize the game.
- Selects actions randomly for exploration or based on the learned Q-values for exploitation.
- Updates the Q-table based on the Q-Learning algorithm.
- Adjusts the exploration rate over time to balance exploration and exploitation.
- Stores the rewards obtained in each episode.
- Prints the Q-table after training.
- Calculates and prints the average reward per thousand episodes.
- Visualizes the agent's performance in a few test episodes.
Feel free to modify and adapt this code according to your needs.