Skip to main content

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 for
  • batch_size (int) โ†’ Mini-batch size for replay
  • target_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 state
  • remember(state, action, reward, next_state, done) โ†’ Store experience in replay buffer
  • replay(batch_size) โ†’ Train from replay buffer
  • update_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deepqlearn-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deepqlearn-0.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for deepqlearn-0.1.1.tar.gz
Algorithm Hash digest
SHA256 611f9c6cad55b42cb477331267c31365bc102b5783d76620b30e1eef826c7965
MD5 5ae38e41a8d8b9b9fd48b4cc17bedbc9
BLAKE2b-256 f05d8645a9481e8f44c3fc1eedd3f80966e516dfd610f295dd399fb6aa1c5e91

See more details on using hashes here.

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

Hashes for deepqlearn-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 89de6d110825de9d533c1fb581cc00a77c4f3d67d9d5ee885607765369e80d38
MD5 fbd43ccbef62823e925e878e41b0dbfd
BLAKE2b-256 591145a69fb1169a25de9a0285db818d2ce6cd9e1b7652764b6c53c3d9ea0c74

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page