Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Wiltschko alexbw

View GitHub Profile
View load labels and data
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:
View assert.py
def f(x):
assert x != 0, 'Do not pass zero!'
return x * x
View lists_with_autograph.py
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 Jul 17, 2018
Nested control flow in AutoGraph
View nested_control_flow.py
def f(n):
if n >= 0:
while n < 5:
n += 1
print(n)
return n
@alexbw
alexbw / collatz.py
Created Jul 17, 2018
Collatz with AutoGraph
View collatz.py
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 Jul 17, 2018
Calling the converted Huber loss code
View calling_huber_loss.py
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 Jul 17, 2018
Auto-generated graph code for Huber loss
View converted_huber_loss.py
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'):
View autograph_huber_loss.py
@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
View huber_loss.py
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 Sep 18, 2017
slate config
View .slate
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