Skip to content

Instantly share code, notes, and snippets.

@awjuliani
awjuliani / cryptArithmetic.m
Created April 5, 2016 22:28
Matlab script to solve basic cryptarithmetic problems.
clear ; close all; clc
%Get input for three terms
prompt = 'First three letter term? ';
x1 = input(prompt, 's');
prompt = 'Second three letter term? ';
x2 = input(prompt, 's');
prompt = 'Four letter answer? ';
y = input(prompt, 's');
@awjuliani
awjuliani / pg-pong.py
Created June 5, 2016 02:12 — forked from karpathy/pg-pong.py
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
import tensorflow as tf
import numpy as np
import tensorflow.contrib.slim as slim
total_layers = 25 #Specify how deep we want our network
units_between_stride = total_layers / 5
def highwayUnit(input_layer,i):
with tf.variable_scope("highway_unit"+str(i)):
H = slim.conv2d(input_layer,64,[3,3])
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import tensorflow as tf
import numpy as np
import tensorflow.contrib.slim as slim
total_layers = 25 #Specify how deep we want our network
units_between_stride = total_layers / 5
def denseBlock(input_layer,i,j):
with tf.variable_scope("dense_unit"+str(i)):
nodes = []
import tensorflow as tf
import numpy as np
import tensorflow.contrib.slim as slim
total_layers = 25 #Specify how deep we want our network
units_between_stride = total_layers / 5
def resUnit(input_layer,i):
with tf.variable_scope("res_unit"+str(i)):
part1 = slim.batch_norm(input_layer,activation_fn=None)
class Worker():
....
....
....
def work(self,max_episode_length,gamma,global_AC,sess,coord):
episode_count = 0
total_step_count = 0
print "Starting worker " + str(self.number)
with sess.as_default(), sess.graph.as_default():
while not coord.should_stop():
# Copies one set of variables to another.
# Used to set worker network parameters to those of global network.
def update_target_graph(from_scope,to_scope):
from_vars = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, from_scope)
to_vars = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, to_scope)
op_holder = []
for from_var,to_var in zip(from_vars,to_vars):
op_holder.append(to_var.assign(from_var))
return op_holder
with tf.device("/cpu:0"):
master_network = AC_Network(s_size,a_size,'global',None) # Generate global network
num_workers = multiprocessing.cpu_count() # Set workers ot number of available CPU threads
workers = []
# Create worker classes
for i in range(num_workers):
workers.append(Worker(DoomGame(),i,s_size,a_size,trainer,saver,model_path))
with tf.Session() as sess:
coord = tf.train.Coordinator()
@awjuliani
awjuliani / rl-tutorial-2.ipynb
Last active May 2, 2018 18:55
Reinforcement Learning Tutorial 2 (Cart Pole problem)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.