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 k_subset(s, k): | |
if k == len(s): | |
return (tuple([(x,) for x in s]),) | |
k_subs = [] | |
for i in range(len(s)): | |
partials = k_subset(s[:i] + s[i + 1:], k) | |
for partial in partials: | |
for p in range(len(partial)): | |
k_subs.append(partial[:p] + (partial[p] + (s[i],),) + partial[p + 1:]) | |
return k_subs |
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 gzip | |
import tensorflow as tf | |
import struct | |
import numpy as np | |
import random | |
def one_hot_encode(i): | |
ret = [0] * 10 | |
ret[i] = 1 | |
return ret |
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 gzip | |
import tensorflow as tf | |
import struct | |
import numpy as np | |
import random | |
def one_hot_encode(i): | |
ret = [0] * 10 | |
ret[i] = 1 | |
return ret |
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
from PIL import Image | |
from struct import unpack | |
from sys import argv | |
def rgb565torgb888(c): | |
return ((c&0xf800) >> 8, (c&0x07e0) >> 3, (c&0x001f) << 3) | |
if len(argv) < 2: | |
print('Usage: {} <filename>'.format(argv[0])) | |
exit() |
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 random | |
import copy | |
import sys | |
MINIBATCH_SIZE = 1000 | |
def gen_model(): | |
cell = tf.contrib.rnn.BasicRNNCell(128) |
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 random | |
W = tf.get_variable('W', shape=[1, 4]) | |
ph_y = tf.placeholder(tf.int32, [1]) # labels | |
prob = tf.nn.softmax(W) | |
loss = tf.reduce_mean( |
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 random | |
W = tf.get_variable('W', shape=[1, 4]) | |
ph_y = tf.placeholder(tf.int32, [1]) # labels | |
prob = tf.nn.softmax(W) | |
loss = tf.reduce_mean( |
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
-----BEGIN CERTIFICATE----- | |
MIIDJjCCAo+gAwIBAgIBATANBgkqhkiG9w0BAQQFADCBkDELMAkGA1UEBhMCS08x | |
DjAMBgNVBAgTBVN0YXRlMQ4wDAYDVQQHEwVTZW91bDEMMAoGA1UEChMDVUxDMQww | |
CgYDVQQLEwNSbkQxGzAZBgNVBAMTEk5lc3BvdFNlcnZlclJvb3RDYTEoMCYGCSqG | |
SIb3DQEJARYZTmVzcG90U2VydmVyUm9vdENhQGt0LmNvbTAeFw0xNzA0MTEwOTA0 | |
NTZaFw0yNzA0MDkwOTA0NTZaMIGMMQswCQYDVQQGEwJLTzEOMAwGA1UECBMFU3Rh | |
dGUxDjAMBgNVBAcTBVNlb3VsMQwwCgYDVQQKEwNVTEMxDDAKBgNVBAsTA1JuRDEX | |
MBUGA1UEAxQOTkVTUE9UX0FBQUNlcnQxKDAmBgkqhkiG9w0BCQEWGU5lc3BvdFNl | |
cnZlclJvb3RDYUBrdC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANOF | |
bvn37Kx3IPyD+NFUHc9yirHNWGa6odOGFc95E+55neQ2fcu+DoGgyB0fhyl3uroT |
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
from collections import defaultdict | |
metrics = defaultdict(float) | |
num_metrics = 0 | |
# training loop | |
for xs, ys in training_dataloader: | |
batch_size = xs.size(0) | |
loss = criterion(...) | |
metrics['loss'] += float(loss) * batch_size | |
num_metrics += batch_size |
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 torch | |
def calculate_loss(x, y): | |
clip_range = 100. | |
clipped = y + (x - y).clamp(-clip_range, clip_range) | |
l_vf = 0.5 * torch.max((clipped - y) ** 2, (x - y) ** 2).mean() | |
return l_vf | |
OlderNewer