gym

python binning data openAI gym

匿名 (未验证) 提交于 2019-12-03 01:36:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am attempting to create a custom environment for reinforcement learning with openAI gym. I need to represent all possible values that the environment will see in a variable called observation_space . There are 3 possible actions for the agent to use called action_space To be more specific the observation_space is a temperature sensor which will see possible ranges from 50 to 150 degrees and I think I can represent all of this by: EDIT, I had the action_space numpy array wrong import numpy as np action_space = np.array([ 0, 1, 2])

openAI Gym NameError in Google Colaboratory

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've just installed openAI gym on Google Colab, but when I try to run 'CartPole-v0' environment as explained here . Code: import gym env = gym.make('CartPole-v0') for i_episode in range(20): observation = env.reset() for t in range(100): env.render() print(observation) action = env.action_space.sample() observation, reward, done, info = env.step(action) if done: print("Episode finished after {} timesteps".format(t+1)) break I get this: WARN: gym.spaces.Box autodetected dtype as <class 'numpy.float32'>. Please provide explicit dtype. --------

gym安装出错:pip install gym[atari] 报错解决方法

匿名 (未验证) 提交于 2019-12-03 00:41:02
运行 import gym 没问题,但是 env = gym.make( 'MsPacman-v0' ) 报错, 安装依赖的包: sudo apt -get install -y python -numpy python -dev cmake zlib1g -dev libjpeg -dev xvfb libav -tools xorg -dev python -opengl libboost -all -dev libsdl2 -dev swig libglfw3 -dev 安装libav-tools报错Package has no installation candidate,用: # apt-get update # apt-get upgrade # apt-get install <packagename> 其中 libav-tools , libglfw3-dev 安装不上的话,用这个替代: sudo apt -get install ffmpeg sudo apt -get install libglfw3 -dev 还有安装 Pillow : pip install Pillow 最后安装: pip install gym [atari] 参考: http://lib.csdn.net/article/aimachinelearning/68113 文章来源:

基于DQN的五子棋算法

匿名 (未验证) 提交于 2019-12-03 00:22:01
五子棋的gym环境 import gym import logging import numpy import random from gym import spaces logger = logging.getLogger(__name__) class FiveChessEnv(gym.Env): metadata = { 'render.modes': ['human', 'rgb_array'], 'video.frames_per_second': 2 } def __init__(self): #棋盘大小 self.SIZE = 8 #初始棋盘是0 -1表示黑棋子 1表示白棋子 self.chessboard = [ [ 0 for v in range(self.SIZE) ] for v in range(self.SIZE) ] self.viewer = None self.step_count = 0 def seed(self, seed=None): self.np_random, seed = seeding.np_random(seed) return [seed] def is_valid_coord(self,x,y): return x>=0 and x<self.SIZE and y>=0 and y<self.SIZE def is

gym

匿名 (未验证) 提交于 2019-12-03 00:18:01
导入gym模块 import gym 创建一个小车倒立摆模型 env = gym.make(‘CartPole-v0’) 初始化环境 env.reset() 刷新当前环境,并显示 env.render() 重新初始化函数 在强化学习中,agent需要多次尝试,积累经验,然后从经验中学到好的动作。一次尝试我们称之为一条trajectory或一个episode。 每次尝试都需要从初始状态达到终止状态。 一次尝试结束后,需要从头开始,即重新初始化 源码: def _reset(): seif.state = self.np_random.uniform(low = -0.05,high=0.05,size=(4,)) ##利用均匀随机分布初始化环境的状态 self.steps_beyond_done =None ## 设置当前步数为None return np.array(self.state) ## 返回环境的初始化状态 图像引擎,一个仿真环境必不可少的两部分是物理引擎和图像引擎。物理引擎模拟环境中物体的运动规律;图像引擎用来显示环境中的物体图像。便于直观显示当前环境物体的状态。方便调试代码。 def _render(self,mode='human',close = False): if close: ... if self.viewer is None: from gym.envs

Gym 10102B 贪心

本小妞迷上赌 提交于 2019-11-28 12:20:21
原题连接:http://codeforces.com/gym/101102/problem/B 题意:用火柴棍摆数字,保证位数不变的情况下,相同数量的火柴棍,使数值尽量大。 思路:先建立一个数组,对应每一个数字需要的火柴棍数量。外层循环枚举每一位,内层循环选数字。每一位数字最少用2根火柴棍,最多用7根,所以剩下几位,就用位数乘以2作为下限,乘以7作为上限,只需判定选用本次数值后剩下的火柴棍是否再上下限范围内,即可完成判定。 完整代码: #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; #define N 100005 char s[N]; int d[10]={6,2,5,5,4,5,6,3,7,6}; int main(){ int t,n; scanf("%d",&t); while(t--){ int sum=0; scanf("%d%s",&n,s); for(int i=0;i<n;i++){ sum+=d[s[i]-'0']; } for(int i=1;i<=n;i++){ int l=(n-i)*2,r=(n-i)*7; for(int j=9;j>=0;j--){ int a=sum-d[j]; if(a>=l&&a<