This file contains hidden or 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
| (declare-sort Person) | |
| (declare-fun ancestor (Person Person) Bool) | |
| ;; anti symmetry | |
| (assert (forall ((x Person) (y Person)) | |
| (=> (ancestor x y) (not (ancestor y x))))) | |
| ;; transitivity | |
| (assert (forall ((x Person) (y Person) (z Person)) | |
| (=> (and (ancestor x y) (ancestor y z)) |
This file contains hidden or 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 numpy as np | |
| # open whichever w2v file you want | |
| fd = open("glove.6B/glove.6B.50d.txt").readlines() | |
| # return a list of keys (words) and the w2v matrix Nxd | |
| def to_numpy(lines): | |
| keys = [] | |
| ary = [] | |
| for l in lines: |
This file contains hidden or 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 random | |
| import numpy as np | |
| # there are 10 casinos | |
| # each casino_i initially has 0 arms, however | |
| # each casino_i is equipted with a slot-machine maker | |
| # assume the slot machine maker is Unif(a_i, opt_i) | |
| # where a_i < opt_i < 1 | |
| # you can take 2 kinds of actions: |
This file contains hidden or 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 normalise(mat, axis): | |
| if axis == 0: | |
| row_sums = mat.sum(axis=1) | |
| new_matrix = mat / row_sums[:, np.newaxis] | |
| return new_matrix | |
| if axis == 1: | |
| col_sums = mat.sum(axis=0) | |
| new_matrix = mat / col_sums[np.newaxis, :] | |
| return new_matrix | |
This file contains hidden or 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 numpy as np | |
| from numpy import array | |
| from scipy.misc import imresize | |
| import copy | |
| from scipy.ndimage.filters import gaussian_filter | |
| import random | |
| from keras.datasets import mnist | |
| import matplotlib.pyplot as plt |
This file contains hidden or 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
| %% | |
| %% This is file `lgrind.sty', | |
| %% generated with the docstrip utility. | |
| %% | |
| %% The original source files were: | |
| %% | |
| %% lgrind.dtx (with options: `package') | |
| %% | |
| %% LGrind is used to format source code of different programming | |
| %% languages for LaTeX. |
This file contains hidden or 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, ImageDraw | |
| import numpy as np | |
| L = 1028 | |
| img = Image.new('RGBA', (L, L), (255, 0, 0, 0)) | |
| center = (L / 2, L / 2) | |
| def scale_w_by_d(d): | |
| return int(d / (L / 2) * 32) |
This file contains hidden or 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 | |
| import torch.nn as nn | |
| from torch.autograd import Variable | |
| import numpy as np | |
| import torch.nn.functional as F | |
| import random | |
| from tqdm import tqdm | |
| if torch.cuda.is_available(): | |
| def to_torch(x, dtype, req = False): |
This file contains hidden or 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 random | |
| import math | |
| import numpy as np | |
| # a random mock-up environment with a single state of a float | |
| # the goal is to get the float as close to 0 as possible with 2 possible moves | |
| # x <- x + 1 | |
| # x <- cos(x) | |
| class Env: | |
| def __init__(self): |
This file contains hidden or 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 train_dagger(env, teacher, student): | |
| init_state = env.reset() | |
| s_a_agg = [] | |
| for i in range(100): | |
| # learning | |
| print ("learning . . . ", i) | |
| trace = get_rollout(env, init_state, student) | |
| state_sample = [x[0] for x in trace] |