-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from hill-a/doc-env
Documentation Custom Environments
- Loading branch information
Showing
33 changed files
with
231 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
## Stable Baselines Documentation | ||
|
||
This folder contains documentation for the RL baselines. | ||
|
||
|
||
### Build the Documentation | ||
|
||
#### Install Sphinx and Theme | ||
|
||
``` | ||
pip install sphinx sphinx-autobuild sphinx-rtd-theme | ||
``` | ||
|
||
#### Building the Docs | ||
|
||
In the `docs/` folder: | ||
``` | ||
make html | ||
``` | ||
|
||
if you want to building each time a file is changed: | ||
|
||
``` | ||
sphinx-autobuild . _build/html | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
.. _custom_env: | ||
|
||
Using Custom Environments | ||
========================== | ||
|
||
To use the rl baselines with custom environments, they just need to follow the *gym* interface. | ||
That is to say, your environment must implement the following methods (and inherits from OpenAI Gym Class): | ||
|
||
|
||
.. code-block:: python | ||
import gym | ||
from gym import spaces | ||
class CustomEnv(gym.Env): | ||
"""Custom Environment that follows gym interface""" | ||
metadata = {'render.modes': ['human']} | ||
def __init__(self, arg1, arg2, ...): | ||
super(CustomEnv, self).__init__() | ||
# Define action and observation space | ||
# They must be gym.spaces objects | ||
# Example when using discrete actions: | ||
self.action_space = spaces.Discrete(N_DISCRETE_ACTIONS) | ||
# Example for using image as input: | ||
self.observation_space = spaces.Box(low=0, high=255, | ||
shape=(HEIGHT, WIDTH, N_CHANNELS), dtype=np.uint8) | ||
def step(self, action): | ||
... | ||
def reset(self): | ||
... | ||
def render(self, mode='human', close=False): | ||
... | ||
Then you can define and train a RL agent with: | ||
|
||
.. code-block:: python | ||
# Instantiate and wrap the env | ||
env = DummyVecEnv([lambda: CustomEnv(arg1, ...)]) | ||
# Define and Train the agent | ||
model = A2C(CnnPolicy, env).learn(total_timesteps=1000) | ||
You can find a `complete guide online <https://github.com/openai/gym/tree/master/gym/envs#how-to-create-new-environments-for-gym>`_ | ||
on creating a custom Gym environment. | ||
|
||
|
||
Optionnaly, you can also register the environment with gym, | ||
that will allow you to create the RL agent in one line (and use ``gym.make()`` to instantiate the env). | ||
|
||
|
||
In the project, for testing purposes, we use a custom environment named ``IdentityEnv`` | ||
defined `in this file <https://github.com/hill-a/stable-baselines/blob/master/stable_baselines/common/identity_env.py>`_. | ||
An example of how to use it can be found `here <https://github.com/hill-a/stable-baselines/blob/master/tests/test_identity.py>`_. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
.. _install: | ||
|
||
============ | ||
Installation | ||
============ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.. _results_plotter: | ||
|
||
|
||
Plotting Results | ||
================ | ||
|
||
.. automodule:: stable_baselines.results_plotter | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,3 @@ Parameters | |
|
||
.. autoclass:: HER | ||
:members: | ||
:inherited-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.