July 2018
Intermediate to advanced
254 pages
8h 12m
English
In this section, we will implement a full training script to solve the Cart Pole problem using the Shallow Q_Learner class that we developed in the previous section:
#!/usr/bin/env python import gym import random import torch from torch.autograd import Variable import numpy as np from utils.decay_schedule import LinearDecaySchedule from function_approximator.perceptron import SLPenv = gym.make("CartPole-v0")MAX_NUM_EPISODES = 100000MAX_STEPS_PER_EPISODE = 300class Shallow_Q_Learner(object): def __init__(self, state_shape, action_shape, learning_rate=0.005, gamma=0.98): self.state_shape = state_shape self.action_shape = action_shape self.gamma = gamma # Agent's discount factor self.learning_rate ...Read now
Unlock full access