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
# 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 |
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
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 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 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 |
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 sys | |
try: | |
import pyPdf | |
except ImportError: | |
import PyPDF2 as pyPdf | |
def addPage(opdf, ipdf, pg): | |
if pg>=len(pages): | |
opdf.addBlankPage(w, h) | |
else: |
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 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) |
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 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) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.