Creating our first agent with Stable Baselines
Now, let's build our first deep RL algorithm using Stable Baselines. Let's create a simple agent using a Deep Q Network (DQN) for the mountain car climbing task. We know that in the mountain car climbing task, a car is placed between two mountains and the goal of the agent is to drive up the mountain on the right.
First, let's import gym
and DQN
from stable_baselines
:
import gym
from stable_baselines import DQN
Create a mountain car environment:
env = gym.make('MountainCar-v0')
Now, let's instantiate our agent. As we can observe in the following code, we are passing MlpPolicy
, which implies that our network is a multilayer perceptron:
agent = DQN('MlpPolicy', env, learning_rate=1e-3)
Now, let's train the agent by specifying the number of time steps we want to train:
agent.learn(total_timesteps=25000)
That's it. Building a DQN agent and training...