Skip to content

Instantly share code, notes, and snippets.

@evancasey
evancasey / model.json
Last active July 9, 2019 20:36
tfjs-resnet
{"format": "graph-model", "generatedBy": "2.0.0-beta1", "convertedBy": "TensorFlow.js Converter v1.2.2.1", "modelTopology": {"node": [{"name": "statefulpartitionedcall_args_96", "op": "Placeholder", "attr": {"dtype": {"type": "DT_RESOURCE"}, "shape": {"shape": {"unknownRank": true}}}}, {"name": "statefulpartitionedcall_args_95", "op": "Placeholder", "attr": {"shape": {"shape": {"unknownRank": true}}, "dtype": {"type": "DT_RESOURCE"}}}, {"name": "statefulpartitionedcall_args_91", "op": "Placeholder", "attr": {"dtype": {"type": "DT_RESOURCE"}, "shape": {"shape": {"unknownRank": true}}}}, {"name": "statefulpartitionedcall_args_90", "op": "Placeholder", "attr": {"dtype": {"type": "DT_RESOURCE"}, "shape": {"shape": {"unknownRank": true}}}}, {"name": "statefulpartitionedcall_args_85", "op": "Placeholder", "attr": {"shape": {"shape": {"unknownRank": true}}, "dtype": {"type": "DT_RESOURCE"}}}, {"name": "statefulpartitionedcall_args_84", "op": "Placeholder", "attr": {"shape": {"shape": {"unknownRank": true}}, "dtype":
import tensorflow as tf
import tensorflow.contrib.eager as tfe
import matplotlib.pyplot as plt
from io import BytesIO
from PIL import Image
import requests
import numpy as np
@evancasey
evancasey / rollout.py
Created August 9, 2016 00:52
CEM rollout
def rollout(self, w, render):
"""
Plays one episode to `max_num_steps` or a terminal state, given a weight vector w.
Returns a scalar of the reward sum of the episode.
"""
self._update_network(w)
observation = self.env.reset()
@evancasey
evancasey / cem.py
Last active August 9, 2016 00:51
CEM agent
def train(self, render = False):
"""
Given an initial distribution vector of w_i, compute a new distribution
vector via the cross-entropy method.
Returns a policy network and stores performance history as `perf_hist`
"""
tf.initialize_all_variables().run()
@evancasey
evancasey / softmax_linear.py
Created August 6, 2016 20:06
CEM softmax_linear
class SoftmaxLinearModel(object):
def __init__(self,
sess,
num_features,
name = "SoftmaxLinear"):
self.sess = sess
with tf.variable_scope(name):
@evancasey
evancasey / linear.py
Created August 6, 2016 20:04
CEM Linear
class LinearModel(object):
def __init__(self,
sess,
num_features,
name = "BinaryLinear"):
self.sess = sess
with tf.variable_scope(name):
@evancasey
evancasey / main.py
Last active August 6, 2016 20:02
CEM main
# Gym params
EXPERIMENT_DIR = './cartpole-experiment-1'
if __name__ == "__main__":
np.random.seed(0)
env = gym.make('CartPole-v0')
env.monitor.start(EXPERIMENT_DIR, force=True)
num_features = env.observation_space.shape[0]
@evancasey
evancasey / lr.scala
Created March 16, 2016 20:36
Logistic Regression
package models
import java.util.Random
import breeze.linalg.{SparseVector, DenseVector}
import breeze.numerics.{round, exp}
case class DataPoint(featureVector: DenseVector[Double], label: Double)
// TODO: add defaults
(1 to 100).foreach { x =>
if (x % 3 == 0 && x % 5 ==0) println("CracklePop")
else if (x % 3 == 0) println("Crackle")
else if (x % 5 == 0) println("Pop")
else println(x)
}
@evancasey
evancasey / links.csv
Created August 31, 2015 14:45
csv_test