Solving OpenAI Gym Environments with MATLAB RL Toolbox

Paulo Carvalho
Analytics Vidhya
Published in
3 min readApr 24, 2020

--

If you work with reinforcement learning you have probably heard of TensorFlow, PyTorch and the likes. However, in 2019 MathWorks introduced a new toolbox for reinforcement learning. This product provides a well supported alternative that may be worth checking out. Here, we show one approach for how to use this toolbox to solve OpenAI Gym environments.

OpenAI Gym CartPole-v1 solved using MATLAB Reinforcement Learning Toolbox

Setting Up Python Interpreter in MATLAB

Note: I am currently running MATLAB 2020a on OSX 10.15 using Anaconda 4.8.2 to create Python environments.

To setup Python and install the dependencies follow the steps below:

  1. In a system terminal, use the conda create --name matlab-rl python=3.6 command to create an environment with Python 3.6 where we can install packages without risk of conflicting with our system’s Python install.
  2. Run conda activate matlab-rl to enter this new environment.
  3. Install OpenAI Gym pip install gym. You can see how to install additional components of it here.
  4. Run which python to get this environment’s Python interpreter. You should see something along the lines of: /usr/local/anaconda3/envs/matlab-rl/bin/python
  5. To tell MATLAB to use this Python intepreter use the following command in…

--

--

Paulo Carvalho
Analytics Vidhya

Want to chat about startups, consulting or engineering? Just send me an email on paulo@avantsoft.com.br.