Skip to content

Instantly share code, notes, and snippets.

View evanthebouncy's full-sized avatar
💯
每人都发小红花

evanthebouncy

💯
每人都发小红花
View GitHub Profile
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)
@evanthebouncy
evanthebouncy / auto_enc_real.py
Created July 3, 2019 21:57
trying to auto-encode a real number
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):
@evanthebouncy
evanthebouncy / beam.py
Created May 21, 2019 03:54
beam search
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):
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]
@evanthebouncy
evanthebouncy / planet.py
Last active January 30, 2019 19:27
simple planetary simulation
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):
# 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)
@evanthebouncy
evanthebouncy / coin.py
Created June 3, 2018 06:26
python stuff
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]
@evanthebouncy
evanthebouncy / try2.py
Created May 18, 2018 01:05
trying to learn pytorch rnn by building a contextualized sequence gneerator
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
@evanthebouncy
evanthebouncy / battleship.py
Created April 26, 2018 17:23
battleship environment
# 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 = []
@evanthebouncy
evanthebouncy / do_not_run.html
Last active September 15, 2021 04:35
do not run this
<!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>