This project implements a Deep Q-Learning (DQN) based AI brain using PyTorch. It's designed to learn and make decisions in an environment through reinforcement learning.
- Neural Network architecture for Q-value approximation
- Experience Replay for efficient learning
- Deep Q-Learning algorithm implementation
- Action selection using softmax distribution
- Model saving and loading capabilities
- Python 3.x
- PyTorch
- NumPy
- torch
- kivy
- Ensure you have Python 3.x installed.
- Install the required packages:
pip install numpy torch kivy
-
Import the
Dqn
class from the main script:from main import Dqn
-
Initialize the DQN agent:
input_size = <your_input_size> nb_action = <number_of_possible_actions> gamma = <discount_factor> agent = Dqn(input_size, nb_action, gamma)
-
Use the agent in your environment:
state = <current_state> action = agent.select_action(state) # After taking the action and observing the result: new_state = <new_state> reward = <observed_reward> next_action = agent.update(reward, new_state)
-
Save and load the model:
# To save agent.save() # To load agent.load()
The Network
class defines the neural network architecture used for Q-value approximation. It consists of two fully connected layers.
The ReplayMemory
class implements experience replay, storing and sampling past experiences for batch learning.
The Dqn
class ties everything together, implementing the Deep Q-Learning algorithm. It handles action selection, learning, and model updates.
You can customize various aspects of the AI brain:
- Adjust the network architecture in the
Network
class - Modify the learning rate in the
Dqn
class initialization - Change the temperature parameter in the
select_action
method - Adjust the replay memory size and batch size in the
Dqn
class