Skip to content

Instantly share code, notes, and snippets.

# written by Harri Edwards, edited by Gavin Gray
import pickle
import tensorflow as tf
import numpy as np
import tf_util
import gym
import load_policy
import gym
import tensorflow.contrib.slim as slim
@gngdb
gngdb / hw2_value_iter.py
Created April 17, 2017 14:16
Value iteration cell solution.
def value_iteration(mdp, gamma, nIt):
"""
Inputs:
mdp: MDP
gamma: discount factor
nIt: number of iterations, corresponding to n above
Outputs:
(value_functions, policies)
len(value_functions) == nIt+1 and len(policies) == n
@gngdb
gngdb / Nested-Gumbel-Softmax.ipynb
Last active October 11, 2018 21:06
The experiment for the forthcoming paper on Nested Gumbel-Softmaxes.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / Few-shot Learning with Relational Reasoning.ipynb
Last active October 9, 2018 12:50
Few-shot relational reasoning (second notebook shows better results but having batchnorm problems with both).
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / selu.ipynb
Last active July 31, 2017 10:47
Convolution with SeLUs
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / simple_sgdr.py
Created September 5, 2017 16:06
Simplest SGDR implementation around
import math
def sgdr(period, batch_idx):
# returns normalised anytime sgdr schedule given period and batch_idx
# best performing settings reported in paper are T_0 = 10, T_mult=2
# so always use T_mult=2
batch_idx = float(batch_idx)
restart_period = period
while batch_idx/restart_period > 1.:
batch_idx = batch_idx - restart_period
@gngdb
gngdb / pdf_booklet.py
Created October 23, 2017 11:00
python script to turn a standard pdf into an a5 booklet
import sys
try:
import pyPdf
except ImportError:
import PyPDF2 as pyPdf
def addPage(opdf, ipdf, pg):
if pg>=len(pages):
opdf.addBlankPage(w, h)
else:
@gngdb
gngdb / tf-autograd.py
Last active June 19, 2020 09:13
How to use autograd inside Tensorflow
import tensorflow as tf
import autograd.numpy as np
from autograd import grad
from tensorflow.python.framework import function
rng = np.random.RandomState(42)
x_np = rng.randn(4,4).astype(np.float32)
with tf.device('/cpu:0'):
x = tf.Variable(x_np)
@gngdb
gngdb / defun.py
Last active March 27, 2019 06:52
how to use Defun to define custom gradients in Tensorflow
import tensorflow as tf
from tensorflow.python.framework import function
@function.Defun()
def my_op_grad(op, grad): ### instead of my_op_grad(x)
return tf.sigmoid(op)
@function.Defun(grad_func=my_op_grad)
def my_op(a):
return tf.identity(a)
@gngdb
gngdb / Rough Notes on Reparameterization.ipynb
Last active October 26, 2017 12:07
Integration with multiple substitution
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.