Reinforcement Learning Replications is a set of Pytorch implementations of reinforcement learning algorithms.
Project description
Reinforcement Learning Replications
Reinforcement Learning Replications is a set of Pytorch implementations of reinforcement learning algorithms.
Features
- Use Python standard logging library
- Support TensorBoard
Benchmarks
The Reinforcement Learning Replications is benchmarked in two environments from the OpenAI Gym: CartPole-v0 and LunarLander-v2.
All experiments were run for 3 random seeds each. Graphs show the each experiment (solid line) on TensorBoard.
| CartPole-v0 | LunarLander-v2 |
|---|---|
Vanilla Policy Gradient (REINFORCE)
Example Code
You can run each benchmark experiment changing seed and env_name to reproduce the results.
import datetime
import logging
import sys
import gym
import torch
import torch.nn as nn
from rl_replicas.algorithms import VPG
from rl_replicas.common.networks import MLP
from rl_replicas.common.policies import CategoricalPolicy
from rl_replicas.common.value_function import ValueFunction
logging.basicConfig(level=logging.INFO, stream=sys.stdout, format="")
env_name = "CartPole-v0" # CartPole-v0 or LunarLander-v2
output_dir = "./runs/vpg/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
epochs = 200
seed = 0 # from 0 to 2
policy_network_architecture = [64, 64]
value_function_network_architecture = [64, 64]
policy_learning_rate = 3e-4
value_function_learning_rate = 1e-3
env = gym.make(env_name)
policy_network: nn.Module = MLP(
sizes=[env.observation_space.shape[0]]
+ policy_network_architecture
+ [env.action_space.n]
)
policy: CategoricalPolicy = CategoricalPolicy(
network=policy_network,
optimizer=torch.optim.Adam(policy_network.parameters(), lr=policy_learning_rate),
)
value_function_network: nn.Module = MLP(
sizes=[env.observation_space.shape[0]] + value_function_network_architecture + [1]
)
value_function: ValueFunction = ValueFunction(
network=value_function_network,
optimizer=torch.optim.Adam(
value_function_network.parameters(), lr=value_function_learning_rate
),
)
model: VPG = VPG(policy, value_function, env, seed=seed)
model.learn(epochs=epochs, output_dir=output_dir, tensorboard=True, model_saving=True)
CartPole-v0
Sample result and trained model stored at ./runs/vpg/CartPole-v0.
LunarLander-v2
Sample result and trained model stored at ./runs/vpg/LunarLander-v2.
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
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 rl-replicas-0.0.3.tar.gz.
File metadata
- Download URL: rl-replicas-0.0.3.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c1ba8178f1477887687828b6d74f3b7bce0a28de4047f24011479d26e5b49bd
|
|
| MD5 |
c7da4bd7b864932f3ddad507845e4bf1
|
|
| BLAKE2b-256 |
9a61f48748eabd612e1e8106c9459ed3f73f3cacce22b45a7cff4e68e314efe7
|
File details
Details for the file rl_replicas-0.0.3-py3-none-any.whl.
File metadata
- Download URL: rl_replicas-0.0.3-py3-none-any.whl
- Upload date:
- Size: 29.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d98c15b7b417de94112b3707c3992f65b3d64ea9a3e22b6773af821843b7cab6
|
|
| MD5 |
9a23efde9895e64769bfe56dc410cd8f
|
|
| BLAKE2b-256 |
2911e917005801b0b5b1a1e51a9952d97de046ba17dc992287ae7b55396b2816
|