Skip to content

Instantly share code, notes, and snippets.

Avatar

Sam greydanus

View GitHub Profile
@greydanus
greydanus / rl_pong.py
Last active Nov 24, 2018
Solves Pong with Policy Gradients in Tensorflow.
View rl_pong.py
'''Solves Pong with Policy Gradients in Tensorflow.'''
# written October 2016 by Sam Greydanus
# inspired by karpathy's gist.github.com/karpathy/a4166c7fe253700972fcbc77e4ea32c5
import numpy as np
import gym
import tensorflow as tf
# hyperparameters
n_obs = 80 * 80 # dimensionality of observations
h = 200 # number of hidden layer neurons
@greydanus
greydanus / dynamic_plotting.py
Created Oct 14, 2016
Dynamic plotting for matplotlib
View dynamic_plotting.py
"Dynamic plotting in matplotlib. Copy and paste into a Jupyter notebook."
# written October 2016 by Sam Greydanus
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
import time
def plt_dynamic(x, y, ax, colors=['b']):
for color in colors:
ax.plot(x, y, color)
@greydanus
greydanus / cartpole.py
Last active Jan 29, 2019
Solution to the Cartpole problem using Policy Gradients in TensorFlow
View cartpole.py
'''Solution to the Cartpole problem using Policy Gradients in Tensorflow.'''
# written October 2016 by Sam Greydanus
# inspired by gist.github.com/karpathy/a4166c7fe253700972fcbc77e4ea32c5
import numpy as np
import gym
import tensorflow as tf
# hyperparameters
n_obs = 4 # dimensionality of observations
h = 128 # hidden layer neurons
@greydanus
greydanus / synthgrad.py
Last active Sep 23, 2018
Trains an MNIST classifier using Synthetic Gradients. See Google DeepMind paper @ arxiv.org/abs/1608.05343.
View synthgrad.py
""" Trains an MNIST classifier using Synthetic Gradients. See Google DeepMind paper @ arxiv.org/abs/1608.05343. """
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from tensorflow.examples.tutorials.mnist import input_data # just use tensorflow's mnist api
mnist = input_data.read_data_sets('MNIST_data', one_hot=False)
# hyperparameters
global_step = 0
batch_size = 10
You can’t perform that action at this time.