A simple Deep Q-Network implementation in PyTorch
Project description
Got it โ you want one single markdown block containing the entire README from title to author so you can copy it in one click.
Hereโs your complete README:
# DeepQlearn
A simple and clean **Deep Q-Network (DQN)** implementation in PyTorch, packaged for easy installation via PyPI.
---
## โจ Features
- Minimal, readable code for learning DQN fundamentals
- Works with any [Gym](https://www.gymlibrary.dev/) environment
- Epsilon-greedy exploration strategy
- Replay buffer for experience sampling
- Target network updates for stable training
- Implemented in [PyTorch](https://pytorch.org)
---
## ๐ฆ Installation
```bash
pip install deepqlearn
Requirements:
Python >= 3.8
PyTorch
Gym
๐ Quick Start
from deepqlearn import train_dqn
# Train on CartPole for 200 episodes
train_dqn(episodes=200)
๐ API Reference
train_dqn(episodes=500, batch_size=64, target_update=10)
Train a DQN agent on CartPole-v1.
Parameters:
episodes(int) โ Number of episodes to train forbatch_size(int) โ Mini-batch size for replaytarget_update(int) โ Frequency (in episodes) to update the target network
DQNAgent
A reinforcement learning agent using Deep Q-Learning.
Constructor:
DQNAgent(
state_dim,
action_dim,
lr=1e-3,
gamma=0.99,
epsilon=1.0,
epsilon_min=0.01,
epsilon_decay=0.995
)
Key Methods:
act(state)โ Choose an action given a stateremember(state, action, reward, next_state, done)โ Store experience in replay bufferreplay(batch_size)โ Train from replay bufferupdate_target()โ Update target network with policy weights
๐ Example Training Script
import gym
from deepqlearn import DQNAgent
env = gym.make("CartPole-v1")
agent = DQNAgent(env.observation_space.shape[0], env.action_space.n)
for episode in range(100):
state = env.reset()[0]
done = False
total_reward = 0
while not done:
action = agent.act(state)
next_state, reward, done, _, _ = env.step(action)
agent.remember(state, action, reward, next_state, done)
agent.replay(batch_size=64)
state = next_state
total_reward += reward
agent.update_target()
print(f"Episode {episode} โ Reward: {total_reward}")
env.close()
๐ Project Structure
deepqlearn/
โ
โโโ src/
โ โโโ deepqlearn/
โ โโโ __init__.py
โ โโโ agent.py
โ โโโ network.py
โ โโโ replay_buffer.py
โ โโโ train.py
โ
โโโ pyproject.toml
โโโ setup.cfg
โโโ README.md
โโโ LICENSE
โโโ .gitignore
โ License
MIT License
๐ค Author
Prathamesh Jadhav
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deepqlearn-0.1.1.tar.gz.
File metadata
- Download URL: deepqlearn-0.1.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
611f9c6cad55b42cb477331267c31365bc102b5783d76620b30e1eef826c7965
|
|
| MD5 |
5ae38e41a8d8b9b9fd48b4cc17bedbc9
|
|
| BLAKE2b-256 |
f05d8645a9481e8f44c3fc1eedd3f80966e516dfd610f295dd399fb6aa1c5e91
|
File details
Details for the file deepqlearn-0.1.1-py3-none-any.whl.
File metadata
- Download URL: deepqlearn-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89de6d110825de9d533c1fb581cc00a77c4f3d67d9d5ee885607765369e80d38
|
|
| MD5 |
fbd43ccbef62823e925e878e41b0dbfd
|
|
| BLAKE2b-256 |
591145a69fb1169a25de9a0285db818d2ce6cd9e1b7652764b6c53c3d9ea0c74
|