Skip to content

Instantly share code, notes, and snippets.

Jessica Stringham jessstringham

Block or report user

Report or block jessstringham

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View plot_wordvecs.py
from bokeh.models import HoverTool
from bokeh.plotting import figure, show, output_file, ColumnDataSource
from bokeh.layouts import gridplot
from bokeh.palettes import magma
def plot(u, descs=index_to_interesting_subject):
source = ColumnDataSource(data=dict(
x1=u[:, 0],
x2=u[:, 1],
x3=u[:, 2],
View ipynb_to_jekyll.py
'''This is hacky code I use to convert Jupyter notebooks into Jekyll posts.
Notebooks' first line should be
# Title
and `Title` will be used as the post's title.
I convert LaTeX into the form MathJax needs.
To make plots work, see `get_maybe_image_code` comment.
View implicit_pasta.py
image = mpimg.imread(IMAGE_LOCATION)
# pasta the first image
h, w, c = image.shape
image = image.reshape(h // 2, 2, w, c)
image = image.transpose(1, 0, 2, 3)
image = np.hstack(image)
# rotate the image
image = image.transpose(1, 0, 2)
View pasta_machine.py
import numpy as np
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
PASTA_SIZE = 16
NUM_IMAGE_SPLITS = 2
IMAGE_LOCATION = 'something.png'
image = mpimg.imread(IMAGE_LOCATION)
View einsum.md

np.einsum

I had this gross reshape/tensor product/transpose stuff on huge matrices, and I knew it was making intermediate copies of the matrices that I didn't want to. So I tried out np.einsum, and I think it actually turned out simpler than thinking through the other matrix manipulation.

Here are some quick notes.

Real blogs/documentation

View hacking_the_matrix.py
import numpy as np
from numpy.lib.stride_tricks import as_strided
# Makes a new matrix like this:
# input: [0, 1, 2, 3]
# output: [[0, 1], [1, 2], [2, 3]]
# But, does it all in memory using `as_strided`, so it's speedy.
# And if you make a mistake, you can see fake numbers
@jessstringham
jessstringham / 0.notes.md
Last active Nov 17, 2017
Bayesian linear regression with polynomial basis functions
View 0.notes.md

Srry, this is a bit of an awkward format. I might move this and a few other demos to a repo.

This is code one could drop into Jupyter [1] notebook cells and draw some wicked-looking graphs. I wrote it to understand Bayesian linear regression (for this classMLPR, specifically this and this). No promises that I did it perfectly.

The graphs show samples from the posterior weights in pink.

You can’t perform that action at this time.