This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """ | |
import numpy as np | |
import cPickle as pickle | |
import gym | |
import copy | |
# hyperparameters | |
H = 200 # number of hidden layer neurons | |
batch_size = 10 # every how many episodes to do a param update? | |
learning_rate = 1e-4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import gym | |
from gym.spaces import Discrete, Box | |
from gym import wrappers | |
#=================================== | |
#Polices | |
#================================== | |
class DeterministicDiscreteActionLinearPolicy(object): | |
def __init__(self, theta, ob_space, ac_space): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import gym | |
from gym.spaces import Discrete, Box | |
from gym import wrappers | |
#=================================== | |
#Polices | |
#================================== | |
class DeterministicDiscreteActionLinearPolicy(object): | |
def __init__(self, theta, ob_space, ac_space): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np, os | |
os.environ["THEANO_FLAGS"]="device=cpu,floatX=float64" | |
import theano, theano.tensor as T | |
import gym | |
from gym import wrappers | |
def discount(x, gamma): | |
""" | |
Given vector x, computes a vector y such that | |
y[i] = x[i] + gamma * x[i+1] + gamma^2 * x[i+2] ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gym | |
from gym import wrappers | |
import tensorflow as tf | |
import numpy as np | |
import random | |
from collections import deque | |
# Hyper Parameters for DQN | |
GAMMA = 0.9 # discount factor for target Q | |
INITIAL_EPSILON = 0.5 # starting value of epsilon |