Custom Open AI gym agent

  1. mkdir custom_agent & mkdir custom_agent/env
  2. echo from custom_agent.envs.custom_env import CustomEnv > custom_agent/__init__.py
echo """from gym.envs.registration import register
register(
id='CustomAgent-v0',
entry_point='custom_agent.envs:CustomEnv',
)
""" > custom_agent/env/__init__.py

3. Now cd custom_agent/env/

4. touch custom_env.py

custom_env.py must be of below structure

import gym
import numpy as np
from gym import error, spaces, utils
from gym.utils import seeding
class CustomEnv(gym.Env): def __init__(self):
pass
def step(self, action):
pass
def reset(self):
pass
def render(self, mode='human'):
pass

def close(self):
pass

Place the files in gym package

  1. Open python gym module in the site-packages directory. For me, it is located here /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/gym/envs
  2. Format __init__.py is
from gym.envs.registration import registry, register, make, spec# Algorithmic
# ----------------------------------------register(
id='Copy-v0',
entry_point='gym.envs.algorithmic:CopyEnv',
max_episode_steps=200,
reward_threshold=25.0,
)register(
id='RepeatCopy-v0',
entry_point='gym.envs.algorithmic:RepeatCopyEnv',
max_episode_steps=200,
reward_threshold=75.0,
)register(
id='ReversedAddition-v0',
entry_point='gym.envs.algorithmic:ReversedAdditionEnv',
kwargs={'rows' : 2},
max_episode_steps=200,
reward_threshold=25.0,
)

4. Place out dircustom_agent here

5. We need to register Custom environments here by editing __init__.py . Add the below lines to the file.

register(from custom_agent.envs.custom_env import CustomEnv > custom_agent/__init__.py
id='CustomAgent-v0',
entry_point='custom_agent.envs:CustomEnv',
)

5. In custom_agent the folder add the file custom_env.py

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

HeaRNNthstone: Generating Hearthstone cards with an LSTM network. Part two

Deep Learning Foundation from Udacity

K-means Clustering & it’s Real use-case in the Security Domain

[Beginner] Linear Algebra (Point and Vector)

What are Recurrent Neural Networks

Combining Generative and Discriminative Machine Learning to Combat Medical Misdiagnosis

Custom Keras model running on OpenCV AI Kit (OAK-1)

Implement Machine Learning Algorithm From Scratch

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amulya Reddy Konda

Amulya Reddy Konda

Consultant

More from Medium

Grassland: Block Reward = Distributed AI Fitness Function

Dilated Convolutions ( Deep Learning)

Generating subwords using BertTokenizer

The GPU Market Is Heating Up! A Third Player Enters The Scene!