在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):thu-ml/tianshou开源软件地址(OpenSource Url):https://github.com/thu-ml/tianshou开源编程语言(OpenSource Language):Python 99.7%开源软件介绍(OpenSource Introduction):Tianshou (天授) is a reinforcement learning platform based on pure PyTorch. Unlike existing reinforcement learning libraries, which are mainly based on TensorFlow, have many nested classes, unfriendly API, or slow-speed, Tianshou provides a fast-speed modularized framework and pythonic API for building the deep reinforcement learning agent with the least number of lines of code. The supported interface algorithms currently include:
Here are Tianshou's other features:
In Chinese, Tianshou means divinely ordained and is derived to the gift of being born with. Tianshou is a reinforcement learning platform, and the RL algorithm does not learn from humans. So taking "Tianshou" means that there is no teacher to study with, but rather to learn by themselves through constant interaction with the environment. “天授”意指上天所授,引申为与生具有的天赋。天授是强化学习平台,而强化学习算法并不是向人类学习的,所以取“天授”意思是没有老师来教,而是自己通过跟环境不断交互来进行学习。 InstallationTianshou is currently hosted on PyPI and conda-forge. It requires Python >= 3.6. You can simply install Tianshou from PyPI with the following command: $ pip install tianshou If you use Anaconda or Miniconda, you can install Tianshou from conda-forge through the following command: $ conda install -c conda-forge tianshou You can also install with the newest version through GitHub: $ pip install git+https://github.com/thu-ml/tianshou.git@master --upgrade After installation, open your python console and type import tianshou
print(tianshou.__version__) If no error occurs, you have successfully installed Tianshou. DocumentationThe tutorials and API documentation are hosted on tianshou.readthedocs.io. The example scripts are under test/ folder and examples/ folder. 中文文档位于 https://tianshou.readthedocs.io/zh/master/。 Why Tianshou?Comprehensive Functionality
(1): access date: 2021-08-08 (2): not all algorithms support this feature (3): TQC and QR-DQN in sb3-contrib instead of main repo (4): super fast APPO! High quality software engineering standard
(1): it has continuous integration but the coverage rate is not available Reproducible and High Quality ResultTianshou has its unit tests. Different from other platforms, the unit tests include the full agent training procedure for all of the implemented algorithms. It would be failed once if it could not train an agent to perform well enough on limited epochs on toy scenarios. The unit tests secure the reproducibility of our platform. Check out the GitHub Actions page for more detail. The Atari/Mujoco benchmark results are under examples/atari/ and examples/mujoco/ folders. Our Mujoco result can beat most of existing benchmark. Modularized PolicyWe decouple all of the algorithms roughly into the following parts:
Within this API, we can interact with different policies conveniently. Quick StartThis is an example of Deep Q Network. You can also run the full script at test/discrete/test_dqn.py. First, import some relevant packages: import gym, torch, numpy as np, torch.nn as nn
from torch.utils.tensorboard import SummaryWriter
import tianshou as ts Define some hyper-parameters: task = 'CartPole-v0'
lr, epoch, batch_size = 1e-3, 10, 64
train_num, test_num = 10, 100
gamma, n_step, target_freq = 0.9, 3, 320
buffer_size = 20000
eps_train, eps_test = 0.1, 0.05
step_per_epoch, step_per_collect = 10000, 10
logger = ts.utils.TensorboardLogger(SummaryWriter('log/dqn')) # TensorBoard is supported!
# For other loggers: https://tianshou.readthedocs.io/en/master/tutorials/logger.html Make environments: # you can also try with SubprocVectorEnv
train_envs = ts.env.DummyVectorEnv([lambda: gym.make(task) for _ in range(train_num)])
test_envs = ts.env.DummyVectorEnv([lambda: gym.make(task) for _ in range(test_num)]) Define the network: from tianshou.utils.net.common import Net
# you can define other net by following the API:
# https://tianshou.readthedocs.io/en/master/tutorials/dqn.html#build-the-network
env = gym.make(task)
state_shape = env.observation_space.shape or env.observation_space.n
action_shape = env.action_space.shape or env.action_space.n
net = Net(state_shape=state_shape, action_shape=action_shape, hidden_sizes=[128, 128, 128])
optim = torch.optim.Adam(net.parameters(), lr=lr) Setup policy and collectors: policy = ts.policy.DQNPolicy(net, optim, gamma, n_step, target_update_freq=target_freq)
train_collector = ts.data.Collector(policy, train_envs, ts.data.VectorReplayBuffer(buffer_size, train_num), exploration_noise=True)
test_collector = ts.data.Collector(policy, test_envs, exploration_noise=True) # because DQN uses epsilon-greedy method Let's train it: 全部评论
专题导读
上一篇:blevesearch/bleve: A modern text indexing library for go发布时间:2022-08-15下一篇:rapidsai/cuml: cuML - RAPIDS Machine Learning Library发布时间:2022-08-15热门推荐
热门话题
阅读排行榜
|
请发表评论