don't stop believing

openAI gym 설치하고 sample 따라하기 (on Mac) 본문

Python/Tensorflow

openAI gym 설치하고 sample 따라하기 (on Mac)

Tongchun 2017. 11. 28. 17:09

OpenAI Gym이 어떤 것이냐면 아래 써있습니다.

[https://gym.openai.com/docs/]

OpenAI Gym is a toolkit for developing and comparing reinforcement learning algorithms. It makes no assumptions about the structure of your agent, and is compatible with any numerical computation library, such as TensorFlow or Theano. You can use it from Python code, and soon from other languages.


강화학습을 배우면서 OpenAI Gym을 사용해 보게 되었습니다.

우선 설치부터 sample 예제를 따라 해 봅시다.

[https://github.com/openai/gym]


Terminal을 열고  Download 폴더로 이동합니다. 그리고 git으로 gym을 다운받습니다.

$ cd ~/Download
$ git clone https://github.com/openai/gym.git
$ cd gym
$ pip3 install -e .

pip3로 gym을 설치해 줍니다. 

$ pip3 install gym
$ pip3 install -e '.[all]'

Mac 환경에서 필요한 package들을 설치해 줍니다.

$ brew install cmake boost boost-python sdl2 swig wget

Sample 설명은 아래 url을 확인해  주세요.

[https://www.oreilly.com/learning/introduction-to-reinforcement-learning-and-openai-gym]

import gym
import numpy as np

env = gym.make("Taxi-v2")
Q = np.zeros([env.observation_space.n, env.action_space.n])
G = 0
alpha = 0.618

for episode in range(1,1001):
	done = False
	G, reward = 0, 0
	state = env.reset()

	while done != True:
		action = np.argmax(Q[state])
		state2, reward, done, info = env.step(action)
		Q[state, action] += alpha * (reward + np.max(Q[state2]) - Q[state, action])
		G += reward
		state = state2

	if episode % 50 == 0:
		print('Episode {} Total Reward: {}'.format(episode, G))



'Python > Tensorflow' 카테고리의 다른 글

인공지능 학습 자료  (0) 2017.11.21
Mac에 TensorFlow 설치  (0) 2017.10.18
Windows에 Tensorflow 설치하기  (1) 2017.09.30
Comments