Skip to content

Instantly share code, notes, and snippets.

View cavaunpeu's full-sized avatar

William Wolf cavaunpeu

View GitHub Profile
@cavaunpeu
cavaunpeu / wills-31st-birthday-party.txt
Created May 14, 2020 02:24
Will's 31st Birthday Party!
Will Wolf is inviting you to a scheduled Zoom meeting.
Topic: Will's 31st Birthday Party!
Time: May 31, 2020 11:00 AM Eastern Time (US and Canada)
Join Zoom Meeting
https://asapp.zoom.us/j/98245285251?pwd=aVN2ZWZXRjVPU1A0TkhZcmRRNWpjQT09
Meeting ID: 982 4528 5251
Password: 076822
@cavaunpeu
cavaunpeu / gist:cb570b9464f2a300f8430891e9af373f
Created February 10, 2019 04:40
Constrain transition matrix s.t. all rows sum to 1
# Ensure that p(~ | z_k) = 1, i.e. the probability of jumping from a given state to any other state is 1
self._A = nn.Parameter(A)
_A_triu = self._A.triu().detach()
A_triu = []
for i, row in enumerate(_A_triu):
nz = row[row.nonzero().view(-1)]
if i == 0:
probs = F.softmax(nz, dim=-1)
else:
probs = nz.exp() * (1 - torch.stack(A_triu)[:, i].sum()) / nz.exp().sum()
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->

Random variables

A variable: a thing that can take on a bunch of different values.

Which part is random?

  • Formally, a random variable deterministically maps elements of one set to another.
  • Once we have the value in the first set, i.e. the "measurement" of "what kind of a Monday it is," we know the value in the second, i.e. the color of shirt I will wear.
# halp?
def foo(x, y):
return f(x, y) + g(x, y)
g_foo = grad(foo, argnum=1)
bar = a + b
g_bar = tf.gradients(bar, var_list)
# g_bar == g_foo(x, y) ... TRUE
x = np.linspace(0, 100, 1)
def transformation(my_x):
results = []
for x in my_x:
if x > 10:
results.append( x**2 )
else:
results.append( x**3 )
@cavaunpeu
cavaunpeu / generate_kmers.py
Created July 8, 2017 12:36
recursively generate kmers
GENES = 'ATGC'
def generate_next_kmers(kmer, k=3, genes=GENES):
if k == 0:
yield kmer
else:
for gene in genes:
yield from generate_next_kmers(kmer + gene, k=k-1)
@cavaunpeu
cavaunpeu / super_convoluted_code.py
Last active October 4, 2016 10:57
Udacity Deep Learning, word2vec Example
def generate_batch(batch_size, num_skips, skip_window):
global data_index
assert batch_size % num_skips == 0
assert num_skips <= 2 * skip_window
batch = np.ndarray(shape=(batch_size), dtype=np.int32)
labels = np.ndarray(shape=(batch_size, 1), dtype=np.int32)
span = 2 * skip_window + 1 # [ skip_window target skip_window ]
buffer = collections.deque(maxlen=span)
for _ in range(span):
buffer.append(data[data_index])