当前位置:网站首页>stable_baselines快速入门
stable_baselines快速入门
2022-07-25 13:14:00 【抓紧爬起来不许摆烂】
0 简介
baselines是OpenAI推出的一套强化学习算法组件,用于快速配置强化学习算法,对入门者比较友好
1 安装
pip install stable-baselines
2 参数介绍
Base RL Class
common interface for all the RL algorithms
class stable_baselines.common.base_class.BaseRLModel(policy,env,verbos=0,*,requires_vec_env,policy_base,policy_kwargs=None,seed=None,n_cpu_tf_sess=None)
The base RL model
Parameters:
policy - ( BasePolicy )Policy object
policy: 策略模型选择,用于建立状态/状态-动作对和策略之间的联系,底层是多层感知机或卷积网络。
env: [Gym environment] The environment to learn from [if registered in Gym, can be str. Can be None for loading trained models]
env:
必要方法:step(action)、reset()、render()
必要元素:action_space、observation_space
step(action):仿真的步进,如何接受一个action然后进行一步仿真
reset():重置
render():显示
action_space:连续的/离散的。比如离散的,东西南北四个方向。比如连续的,选择一个区间产生一个数字,作为他的一个运动步长。
observation_space也是一样的,比如机器人右6个关节,他的状态就用他的6个位置和6个速度来表示。这个速度和位置都有一个上下线的范围。这个范围就可以作为他的observation_space
满足上述5个要素的存在的话,这个环境就可以传送到stable-baselines里面进行下一步的训练了
应用
通过stable_baselines建立DQN框架,训练并运行倒立摆(CartPole-v0)
from stable_baselines import DQN
from stable_baselines.common.evaluation import evaluate_policy
import gym
import time
env = gym.make('CartPole-v0') # 传入倒立摆
TRAIN = 0
if TRAIN: # 训练的部分
model = DQN('MlpPolicy', env, learning_rate=1e-3, prioritized_replay=True, verbose=1) # 属于一个可接受离散的这样的一个网络
# MlpPolicy,多层感知机或者神经网络的一个策略
# env,传入的一个环境
# 其他的一些参数,到这个文件夹下面去看一下,不想细说了,每一个都有一个详细的解释
model.learn(total_timesteps=int(1e5)) # 开始训练,直接用model.learn就可以了,这个learn中也会涉及一些参数
model.save("dqn_cartpole") #训练之后呢,就可以保存这样的一个模型
del model #训练结束后,这个模型就用不到了,就可以删掉了
else: # 演示的部分
model = DQN.load("dqn_cartpole", env) # 调用已经训练好的模型,从神经网络中调用
mean_reward, std_reward = evaluate_policy(model, model.get_env(), n_eval_episodes=10)
obs = env.reset() # 状态重置
for i in range(1000):
action, _states = model.predict(obs) # 将当前的状态传入,告诉我们会做出什么样的动作。
obs, rewards, done, info = env.step(action)# 返回一个新的状态
env.render() # 做一个显示
time.sleep(2) # for showing render()
边栏推荐
- Chapter5 : Deep Learning and Computational Chemistry
- Word style and multi-level list setting skills (II)
- 【CTR】《Towards Universal Sequence Representation Learning for Recommender Systems》 (KDD‘22)
- 【重温SSM框架系列】15 - SSM系列博文总结【SSM杀青篇】
- Convolutional neural network model -- lenet network structure and code implementation
- Mu Changchun, data Research Institute of the central bank: controllable anonymity of digital RMB is an objective need to safeguard public interests and financial security
- Simple understanding of flow
- 【视频】马尔可夫链蒙特卡罗方法MCMC原理与R语言实现|数据分享
- 【CSDN 年终总结】结束与开始,一直在路上—— “1+1=王”的2021总结
- Substance Designer 2021软件安装包下载及安装教程
猜你喜欢

Zero basic learning canoe panel (12) -- progress bar

领域驱动模型设计与微服务架构落地-模型设计

【AI4Code】《Unified Pre-training for Program Understanding and Generation》 NAACL 2021

G027-OP-INS-RHEL-04 RedHat OpenStack 创建自定义的QCOW2格式镜像

Friends let me see this code

0710RHCSA

ESP32-C3 基于Arduino框架下Blinker点灯控制10路开关或继电器组
![[six articles talk about scalablegnn] around www 2022 best paper PASCA](/img/ac/150f6397724593a30aab2805ba5084.png)
[six articles talk about scalablegnn] around www 2022 best paper PASCA

Introduction and features of numpy (I)

【CTR】《Towards Universal Sequence Representation Learning for Recommender Systems》 (KDD‘22)
随机推荐
Convolutional neural network model -- alexnet network structure and code implementation
The programmer's father made his own AI breast feeding detector to predict that the baby is hungry and not let the crying affect his wife's sleep
Django 2 ----- database and admin
C#基础学习(二十三)_窗体与事件
Basic knowledge of binary tree
[today in history] July 25: IBM obtained the first patent; Verizon acquires Yahoo; Amazon releases fire phone
Excel录制宏
Mu Changchun, data Research Institute of the central bank: controllable anonymity of digital RMB is an objective need to safeguard public interests and financial security
0715RHCSA
并发编程之并发工具集
Online Learning and Pricing with Reusable Resources: Linear Bandits with Sub-Exponential Rewards: Li
面试官问我:Mysql的存储引擎你了解多少?
Online Learning and Pricing with Reusable Resources: Linear Bandits with Sub-Exponential Rewards: Li
为提高效率使用ParallelStream竟出现各种问题
【GCN-CTR】DC-GNN: Decoupled GNN for Improving and Accelerating Large-Scale E-commerce Retrieval WWW22
pytorch创建自己的Dataset加载数据集
Atcoder beginer contest 261 f / / tree array
简单了解流
The world is exploding, and the Google server has collapsed
错误: 找不到或无法加载主类 xxxx