Skip to content

Instantly share code, notes, and snippets.

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

evanthebouncy

💯
每人都发小红花
View GitHub Profile
import numpy as np
np.random.seed(0)
def generate_pair():
# make two random numbers x and y
# make x first randomly from 1 to 10
x = np.random.randint(1, 11)
y = np.random.randint(1, 11)
x_y = x + y
@evanthebouncy
evanthebouncy / with_backoff.py
Last active June 27, 2022 22:21
armando car with backoff
track = track4()
car = newCar(track)
startDisplay(track, car)
def control(sd, pastsd):
# average these values to be more smooth
leftt = sd[0] + pastsd[0];
mid = sd[1] + pastsd[1];
# this bit of assymetry is actually very clever, because
# "intuitively" assymetrical things has more information on it
@evanthebouncy
evanthebouncy / best_first_stats.py
Created April 15, 2022 00:33
plotting queue size upon successful termination as a function of temperature
import numpy as np
import random
from queue import PriorityQueue
# here is the task
# we want to construct a goal number, starting from a template of expression
# i.e. (E * E) + E = 11
# we can expand the expression E node further following the grammar
# E -> E + E | E * E | -3 | -2 | -1 | 1 | 2 | 3
@evanthebouncy
evanthebouncy / best_first_search.py
Created March 31, 2022 01:49
best first search
import numpy as np
import random
from queue import PriorityQueue
# here is the task
# we want to construct a goal number, starting from a template of expression
# i.e. (E * E) + E = 11
# we can expand the expression E node further following the grammar
# E -> E + E | E * E | -3 | -2 | -1 | 1 | 2 | 3
@evanthebouncy
evanthebouncy / ancestor.smt
Created October 19, 2020 19:53
simple ancestor relation encoding in z3 smt solver
(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))
@evanthebouncy
evanthebouncy / get_close.py
Created September 23, 2020 01:11
get closeby words from w2v for small word set
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:
@evanthebouncy
evanthebouncy / bandit.py
Created September 3, 2020 08:54
find best arms
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:
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
@evanthebouncy
evanthebouncy / maze.py
Created September 30, 2019 15:02
make a maze out of mnist stuff
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
@evanthebouncy
evanthebouncy / lgrind.sty
Created August 11, 2019 20:10
odd style file
%%
%% 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.