11. Building an Artificial Intelligence Algorithm
Activity 11.01: Implementing a Double Deep Q-Learning Algorithm to Solve the Cart Pole Problem
Solution
- In the
Chapter11
directory, launch a Jupyter Notebook in your Terminal (macOS or Linux) or Command Prompt window (Windows). - After the Jupyter Notebook is launched, create a new directory named
Activity11.01
. Inside theActivity11.01
directory, create a Python 3 notebook. - Inside the Python 3 notebook, import all necessary modules and seed the environment as shown in the following code:
# import module import random import numpy as np from itertools import count from collections import deque import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim import gym # make game env = gym.make('CartPole-v1') # seed the experiment env.seed(9) np.random.seed(9) random.seed(9) torch.manual_seed(9)
- Let's define our DQN as shown in the following code:
# define our policy...