Skip to content

numblr/drlnd-cocontrol

Repository files navigation

Continuous Control in Reinforcement Learning

This repository is based on the continuous control problem studied in the Deep Reinforcement Learning Nanodegree program and demonstrates a variant of the PPO algorithm in an environment with a continuous action space.

General Settings (see also the original repo)

In this project we use the Reacher environment.

Trained Agent

In this environment, a double-jointed arm can move to target locations. A reward of +0.1 is provided for each step that the agent's hand is in the goal location. Thus, the goal of your agent is to maintain its position at the target location for as many time steps as possible.

The observation space consists of 33 variables corresponding to position, rotation, velocity, and angular velocities of the arm. Each action is a vector with four numbers, corresponding to torque applicable to two joints. Every entry in the action vector should be a number between -1 and 1.

Distributed Training

The environment is implemented as a predefined Unity environment, and two two separate versions of this environment are available:

  • The first version contains a single agent.
  • The second version contains 20 identical agents, each with its own copy of the environment.

You can use the code in this repository with both versions. The presented results are obtained with the second version though.

Solving the Environment

The environment is considered solved if the agents achieve an average score of +30 (over 100 consecutive episodes, and over all agents). Specifically,

  • After each episode, we add up the rewards that each agent received (without discounting), to get a score for each agent. This yields 20 (potentially different) scores. We then take the average of these 20 scores.
  • This yields an average score for each episode (where the average is over all 20 agents).

The environment is considered solved, when the average (over 100 episodes) of those average scores is at least +30.

Getting started (see also the original repo)

To set up your python environment to run the code in this repository, follow this steps:

  1. Create (and activate) a new environment with Python 3.6.

    • Linux or Mac:
    conda create --name cocontrol python=3.6
    source activate cocontrol
    • Windows:
    conda create --name cocontrol python=3.6
    activate cocontrol
  2. Then install the dependencies from the requirements.txt file in this repository:

pip install requirements.txt
  1. Download the Unity environment from one of the links below. You must select only the environment that matches your operating system:

(For Windows users) Check out this link if you need help with determining if your computer is running a 32-bit version or 64-bit version of the Windows operating system.

(For AWS) If you'd like to train the agent on AWS (and have not enabled a virtual screen), then please use this link (version 1) or this link (version 2) to obtain the "headless" version of the environment. You will not be able to watch the agent without enabling a virtual screen, but you will be able to train the agent. (To watch the agent, you should follow the instructions to enable a virtual screen, and then download the environment for the Linux operating system above.)

  1. Place and unzip the downloaded file into one of the following locations corresponding to your operating system:
  • Mac: "cocontrol/resources/Reacher.app"
  • Windows (x86): "cocontrol/resources/Reacher_Windows_x86/Reacher.exe"
  • Windows (x86_64): "cocontrol/resources/Reacher_Windows_x86_64/Reacher.exe"
  • Linux (x86): "cocontrol/resources/Reacher_Linux/Reacher.x86"
  • Linux (x86_64): "cocontrol/resources/Reacher_Linux/Reacher.x86_64"
  • Linux (x86, headless): "cocontrol/resources/Reacher_Linux_NoVis/Reacher.x86"
  • Linux (x86_64, headless): "cocontrol/resources/Reacher_Linux_NoVis/Reacher.x86_64"

It is important that the cocontrol/resources folder only contains the agent for your operating system!

  1. To be able to run the Continuous_Control.ipynb notebook, create an IPython kernel for the cocontrol environment.
python -m ipykernel install --user --name cocontrol --display-name "cocontrol"
  1. Before running code in the notebook, change the kernel to match the cocontrol environment by using the drop-down Kernel menu.

Instructions

The main script in the repository is cocontrol.py, which can be invoked to train the agent and store the result, as well as to replay the agent on a single episode from the stored learning results.

After all dependencies are set up as described in the Getting started section, the script can be invoked from the root directory of the repository as e.g.

> python cocontrol.py --dummy

to show the untrained agent on a single episode,

> python cocontrol.py --epochs 20

to execute learning on 20 epochs,

> python cocontrol.py --show

to replay the trained agent on a single episode and

> python cocontrol.py --replay

to run the trained agent on 100 episodes and print the obtained average score.

When invoked without command line parameters, the script will execute learning on 16 epochs. For help on the possible command line options execute the script with the --help option.

Results

The parameters of the trained models can be found in the actor_parameters.pt and critic_parameters.pt files. The scores obtained during training are plotted in the scores.png file.

The included results are obtained using 20 parallel agents and achieve the target of an average score of +30 over 100 episodes in 128 episodes (per agent). They reach the target score of +30 in a single episode after 56 episodes and reach a top episode score close to 39 after.

Scores

About

RL with continuous action space

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published