OpenAI gym的官網案例

2021-08-11 04:49:32 字數 1755 閱讀 9196

tags: openai_gym

當然這只是gym的乙個遊戲,還有一些如: mountaincar-v0, mspacman-v0 (requires the atari dependency), or hopper-v1 (requires the mujoco dependencies). environments all descend from the env base class.

import gym

env = gym.make('cartpole-v0')

env.reset()

for _ in range(1000):

env.render()

env.step(env.action_space.sample()) # take a random action

往環境輸入乙個動作後返回,環境執行完該動作後的一些資訊env.step(action)

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

列印動作空間和狀態空間:

discrete(2)表示該環境的動作空間為離散的動作空間(0,1)

box(4,)表示該狀態空間是乙個一維向量構成

import gym

env = gym.make('cartpole-v0')

print(env.action_space)

#> discrete(2)

print(env.observation_space)

#> box(4,)

同時可以獲取狀態空間的每一維度的最值

print(env.observation_space.high)

#> array([ 2.4 , inf, 0.20943951, inf])

print(env.observation_space.low)

#> array([-2.4 , -inf, -0.20943951, -inf])

gym提供了自定義的空間

from gym import spaces

space = spaces.discrete(8) # set with 8 elements

x = space.sample()

assert space.contains(x)

assert space.n == 8

返回所有環境

from gym import envs

print(envs.registry.all())

10 10 010 簡介 官網 官網翻譯

netty是 乙個非同步事件驅動的網路應用程式框架,用於快速開發可維護的高效能協議伺服器和客戶端。netty是乙個nio客戶端伺服器框架,可以快速輕鬆地開發協議伺服器和客戶端等網路應用程式。它極大地簡化並簡化了tcp和udp套接字伺服器等網路程式設計。快速簡便 並不意味著最終的應用程式會受到可維護性...

Robolectric Shadows 官網翻譯

robolectric 通過建立乙個包含真實android 框架 的執行時環境來進行工作。這意味著,當你的測試或被測試 呼叫到android框架時,你會獲得更真實的體驗,因為這跟在實際裝置上執行的大部分 都是相同的。然而還是有一些限制 native code 源 android源 不能在你的開發機器...

Android官網探索

文章首先發表在 android官網首頁 首頁上面有三個大板塊 當然,還有右上角的搜尋。站點底部有一些android外圍的東西,關於啦 tv開發啦 wear開發啦甚至還有汽車 話說我到現在還不知道哪款車中控是android系統的 如果看不懂英文,可以使用這個 提供乙個material設計的概要 還有很...