Deep-Q learning with pytorch
Project description
Welcome to the torchagent repository. This repository contains the sources for the torchagent library.
What is it?
torchagent
is a library that implements various reinforcement learning algorithms for PyTorch.
You can use this library in combination with openAI Gym to implement reinforcement learning solutions.
Which algorithms are included?
Currently the following algorithms are implemented:
Deep Q Learning
Double Q Learning
Installation
You can install the library using the following command:
pip install torchagent
Usage
The following code shows a basic agent that uses Deep Q Learning.
from torchagent.memory import SequentialMemory
from torchagent.agents import DQNAgent
import torch
import torch.nn as nn
import torch.optim as optim
class PolicyNetwork(nn.Module):
def __init__(self):
self.linear = nn.Linear(210 * 160, 3)
def forward(self, x):
return self.linear(x)
policy_network = PolicyNetwork()
memory = SequentialMemory(20)
agent = DQNAgent(2, policy_network, nn.MSELoss(), optim.Adam(policy_network.parameters()), memory)
env = gym.make('Assault-v0')
for _ in range(50):
state = env.reset()
for t in count():
action = agent.act(state)
next_state, reward, done, _ = env.step(agent.act(state))
agent.record(state, action, next_state, reward, done)
agent.train()
state = next_state
if done:
break
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
torchagent-0.2.4.tar.gz
(6.0 kB
view hashes)
Built Distribution
Close
Hashes for torchagent-0.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 723c8f9c4493fb5a8765f1f64125de3ee07b3cc8137006b88010db6fc10007f2 |
|
MD5 | 66f62f0bbc6d01337a2089bec4062174 |
|
BLAKE2b-256 | a0864017c9cbde1e15396fc942c2fc8c9c301025db3d14c2b51579882655d254 |