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] |
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 | |
def clip_norm(x): | |
return x / abs(np.max(x)) * 0.001 | |
# random strat | |
# def p1_strat(p, v): | |
# fr = np.random.uniform(-1.0, 1.0, size=(2,)) | |
# return fr | |
def p2_strat(p, v): |
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
# consider the following game: | |
# we each have a coin, and we choose to vote either head or tail | |
# if the result is HH or TT, you gain 3 dollars or 1 dollars from me respectively | |
# but if the result is HT or TH, you lose 2 dollars to me | |
# would you play this game? | |
# expectation for a mixture strategy of x probabiliyt of head for u and y probabiliyt of head fo rme | |
def f(x,y): | |
return 3*x*y - 2*(1-x)*y - 2*x*(1-y) + 1*(1-x)*(1-y) |
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 | |
def flip(): | |
return 'H' if random.random() > 0.5 else 'T' | |
def trial(): | |
flips = [flip() for _ in range(100)] | |
for i in range(1, 99): | |
last = flips[i] | |
lastlast = flips[i-1] |
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 cv2 | |
import torch | |
from torch import nn | |
import torch.nn.functional as F | |
import random | |
seq_length = 10 | |
token_size = 4 | |
hidden_size = 20 | |
n_layer = 2 |
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
# length of board | |
L = 10 | |
boat_shapes = [(2,4), (1,5), (1,3), (1,3), (1,3)] | |
def get_board(): | |
total_mass = sum([x[0]*x[1] for x in boat_shapes]) | |
def _gen_boats(): | |
ret = np.zeros([L, L]) | |
occupied = [] | |
poses = [] |
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
<!DOCTYPE html> | |
<html> | |
<body> | |
<canvas id="myCanvas" width="800" height="800" | |
style="border:1px solid #d3d3d3;"> | |
Your browser does not support the canvas element. | |
</canvas> | |
<script> |