Skip to content

Instantly share code, notes, and snippets.

View alexbw's full-sized avatar

Alex Wiltschko alexbw

  • Google
  • Boston, MA
View GitHub Profile
import numpy as np
import cPickle as pickle
import joblib
from moseq.train import ARHMM, train_model
from moseq.train.util import whiten_all
from collections import OrderedDict
from syllables import analysis
# Load the data
with open("/data/efs/drugs/alldoses/dataset.pkl","r") as f:
@alexbw
alexbw / assert.py
Created July 17, 2018 16:37
Asserts
def f(x):
assert x != 0, 'Do not pass zero!'
return x * x
@alexbw
alexbw / lists_with_autograph.py
Created July 17, 2018 16:37
Lists with AutoGraph
def f(n):
z = []
# We ask you to tell us the element dtype of the list
autograph.set_element_type(z, tf.int32)
for i in range(n):
z.append(i)
# when you're done with the list, stack it
# (this is just like np.stack)
return autograph.stack(z)
@alexbw
alexbw / nested_control_flow.py
Created July 17, 2018 16:36
Nested control flow in AutoGraph
def f(n):
if n >= 0:
while n < 5:
n += 1
print(n)
return n
@alexbw
alexbw / collatz.py
Created July 17, 2018 16:36
Collatz with AutoGraph
def collatz(a):
counter = 0
while a != 1:
if a % 2 == 0:
a = a // 2
else:
a = 3 * a + 1
counter = counter + 1
return counter
@alexbw
alexbw / calling_huber_loss.py
Created July 17, 2018 16:35
Calling the converted Huber loss code
with tf.Graph().as_default():
x_tensor = tf.constant(9.0)
# The converted function works like a regular op: tensors in, tensors out.
huber_loss_tensor = huber_loss(x_tensor)
with tf.Session() as sess:
print('TensorFlow result: %2.2f\n' % sess.run(huber_loss_tensor))
@alexbw
alexbw / converted_huber_loss.py
Created July 17, 2018 16:35
Auto-generated graph code for Huber loss
def tf__huber_loss(a):
with tf.name_scope('huber_loss'):
def if_true():
with tf.name_scope('if_true'):
loss = a * a / 2
return loss,
def if_false():
with tf.name_scope('if_false'):
@alexbw
alexbw / autograph_huber_loss.py
Created July 17, 2018 16:34
AutoGraph Huber Loss
@autograph.convert()
def huber_loss(a):
if tf.abs(a) <= delta:
loss = a * a / 2
else:
loss = delta * (tf.abs(a) - delta / 2)
return loss
@alexbw
alexbw / huber_loss.py
Last active July 17, 2018 16:34
Huber Loss
def huber_loss(a):
if tf.abs(a) <= delta:
loss = a * a / 2
else:
loss = delta * (tf.abs(a) - delta / 2)
return loss
@alexbw
alexbw / .slate
Last active September 18, 2017 13:51
slate config
config defaultToCurrentScreen false
# Shows app icons and background apps, spreads icons in the same place.
config windowHintsShowIcons true
config windowHintsIgnoreHiddenWindows false
config windowHintsSpread true
config nudgePercentOf screenSize
config resizePercentOf screenSize
bind e:cmd;alt hint QWERASDFZXCV # use whatever keys you want