Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Deep Reinforcement Learning with Python

You're reading from   Deep Reinforcement Learning with Python Master classic RL, deep RL, distributional RL, inverse RL, and more with OpenAI Gym and TensorFlow

Arrow left icon
Product type Paperback
Published in Sep 2020
Publisher Packt
ISBN-13 9781839210686
Length 760 pages
Edition 2nd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sudharsan Ravichandiran Sudharsan Ravichandiran
Author Profile Icon Sudharsan Ravichandiran
Sudharsan Ravichandiran
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Fundamentals of Reinforcement Learning 2. A Guide to the Gym Toolkit FREE CHAPTER 3. The Bellman Equation and Dynamic Programming 4. Monte Carlo Methods 5. Understanding Temporal Difference Learning 6. Case Study – The MAB Problem 7. Deep Learning Foundations 8. A Primer on TensorFlow 9. Deep Q Network and Its Variants 10. Policy Gradient Method 11. Actor-Critic Methods – A2C and A3C 12. Learning DDPG, TD3, and SAC 13. TRPO, PPO, and ACKTR Methods 14. Distributional Reinforcement Learning 15. Imitation Learning and Inverse RL 16. Deep Reinforcement Learning with Stable Baselines 17. Reinforcement Learning Frontiers 18. Other Books You May Enjoy
19. Index
Appendix 1 – Reinforcement Learning Algorithms 1. Appendix 2 – Assessments

Setting up our machine

In this section, we will learn how to install several dependencies that are required for running the code used throughout the book. First, we will learn how to install Anaconda and then we will explore how to install Gym.

Installing Anaconda

Anaconda is an open-source distribution of Python. It is widely used for scientific computing and processing large volumes of data. It provides an excellent package management environment, and it supports Windows, Mac, and Linux operating systems. Anaconda comes with Python installed, along with popular packages used for scientific computing such as NumPy, SciPy, and so on.

To download Anaconda, visit https://www.anaconda.com/download/, where you will see an option for downloading Anaconda for different platforms. If you are using Windows or macOS, you can directly download the graphical installer according to your machine architecture and install Anaconda using the graphical installer.

If you are using Linux, follow these steps:

  1. Open the Terminal and type the following command to download Anaconda:
    wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
    
  2. After downloading, we can install Anaconda using the following command:
    bash Anaconda3-5.0.1-Linux-x86_64.sh
    

After the successful installation of Anaconda, we need to create a virtual environment. What is the need for a virtual environment? Say we are working on project A, which uses NumPy version 1.14, and project B, which uses NumPy version 1.13. So, to work on project B we either downgrade NumPy or reinstall NumPy. In each project, we use different libraries with different versions that are not applicable to the other projects. Instead of downgrading or upgrading versions or reinstalling libraries every time for a new project, we use a virtual environment.

The virtual environment is just an isolated environment for a particular project so that each project can have its own dependencies and will not affect other projects. We will create a virtual environment using the following command and name our environment universe:

conda create --name universe python=3.6 anaconda

Note that we use Python version 3.6. Once the virtual environment is created, we can activate it using the following command:

source activate universe

That's it! Now that we have learned how to install Anaconda and create a virtual environment, in the next section, we will learn how to install Gym.

Installing the Gym toolkit

In this section, we will learn how to install the Gym toolkit. Before going ahead, first, let's activate our virtual environment, universe:

source activate universe

Now, install the following dependencies:

sudo apt-get update
sudo apt-get install golang libcupti-dev libjpeg-turbo8-dev make tmux htop chromium-browser git cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev python-opengl libboost-all-dev libsdl2-dev swig
conda install pip six libgcc swig
conda install opencv

We can install Gym directly using pip. Note that throughout the book, we will use Gym version 0.15.4. We can install Gym using the following command:

pip install gym==0.15.4

We can also install Gym by cloning the Gym repository as follows:

cd ~
git clone https://github.com/openai/gym.git
cd gym
pip install -e '.[all]'

Common error fixes

Just in case, if you get any of the following errors while installing Gym, the following commands will help:

  • Failed building wheel for pachi-py or failed building wheel for pachi-py atari-py:
    sudo apt-get update
    sudo apt-get install xvfb libav-tools xorg-dev libsdl2-dev swig cmake
    
  • Failed building wheel for mujoco-py:
    git clone https://github.com/openai/mujoco-py.git
    cd mujoco-py
    sudo apt-get update
    sudo apt-get install libgl1-mesa-dev libgl1-mesa-glx libosmesa6-dev python3-pip python3-numpy python3-scipy
    pip3 install -r requirements.txt
    sudo python3 setup.py install
    
  • error: command 'gcc' failed with exit status 1:
    sudo apt-get update
    sudo apt-get install python-dev 
    sudo apt-get install libevent-dev
    

Now that we have successfully installed Gym, in the next section, let's kickstart our hands-on reinforcement learning journey.

You have been reading a chapter from
Deep Reinforcement Learning with Python - Second Edition
Published in: Sep 2020
Publisher: Packt
ISBN-13: 9781839210686
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime