“The first duty in life is to be as artificial as possible. What the second duty is no one has as yet discovered.” Oscar Wilde
 
Windy Walk (part 2)

Windy Walk (part 2)

Recap: Previously we constructed a very simple class to emulate the type of environment which is provided by OpenAI. Then we simulated two windy walks and used the result of these walks to produce some plots.

Now we want to produce the same results again but via a different and more interesting route. This time we want a windy walk model that is implemented as an extension to OpenAI.

For this we create a custom python package, we name it gym_drifty_walk.

You can pull the source code of gym_drifty_walk from github .

To install gym_drifty_walk locally do a clone, cd into the gym_drifty_walk directory,  then run python setup.py install.

How the package is created in the first place will be explained in the next post. Let’s look how we use it first.

So first import some packages (the usual suspects … numpy, matplotlib)
In [23]:
# import packages
import numpy as np
import matplotlib.style as style
import matplotlib.pyplot as plt
style.use('ggplot')

Now import the custom environment …

In [26]:
import gym
import gym_drifty_walk # custom environment

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

Run the simulation and plot

In [25]:
# set random seed, for reproducibility
np.random.seed(166)

env.reset()
X=[]
for i in range(50):
    
    state, reward, done, _ = env.step(0.1)
    X.append(state)

plt.plot(X)
Out[25]:
[<matplotlib.lines.Line2D at 0x7f44a46b1dd8>]
So this plot, depicting the Position as a function of time of the the first walk, is exactly equal to that of the previous post. That is the way is should be. This  is due to the fact that the same random seed was used, for reproducibility, a standard technique, of course.
So it works!
PHP Code Snippets Powered By : XYZScripts.com