Skip to content

Instantly share code, notes, and snippets.

Avatar
Probably drinking coffee

George Ho eigenfoo

Probably drinking coffee
View GitHub Profile
View original-api.py
def linear_regression(x):
scale = yield tfd.HalfCauchy(0, 1)
coefs = yield tfd.Normal(tf.zeros(x.shape[1]), 1, )
predictions = yield tfd.Normal(tf.linalg.matvec(x, coefs), scale)
return predictions
View final-api.py
@Model
def linear_regression(x):
scale = tfd.HalfCauchy(0, 1)
coefs = tfd.Normal(tf.zeros(x.shape[1]), 1)
predictions = tfd.Normal(tf.linalg.matvec(x, coefs), scale)
return predictions
linear_regression.model_generator(tf.zeros([3, 10])) # Shape is irrelevant here
View model.py
class Model:
""" pm.Model decorator. """
def __init__(self, func):
self.func = func
# Introspect wrapped function, instead of the decorator class.
functools.update_wrapper(self, func)
# Uncompile wrapped function.
View function_to_generator.py
class FunctionToGenerator(ast.NodeTransformer):
"""
This subclass traverses the AST of the user-written, decorated,
model specification and transforms it into a generator for the
model. Subclassing in this way is the idiomatic way to transform
an AST.
Specifically:
1. Add `yield` keywords to all assignments
@eigenfoo
eigenfoo / trajectory.py
Created Dec 15, 2019
PyMC3 `pymc3/step_methods/hmc/trajectory.py` as of dc9fd725
View trajectory.py
from collections import namedtuple
import theano
import theano.tensor as tt
import numpy as np
from pymc3.theanof import join_nonshared_inputs, gradient, CallableTensor, floatX
Hamiltonian = namedtuple("Hamiltonian", "logp, dlogp, pot")
@eigenfoo
eigenfoo / setup.py
Created Sep 9, 2019
Template setup.py file
View setup.py
""" Template setup.py file """
from os.path import dirname, realpath, join, exists
from re import search, M
from setuptools import setup, find_packages
# TODO: add package details
NAME = ""
MAINTAINER = ""
@eigenfoo
eigenfoo / ipynb_toc.py
Created Jun 24, 2019
Print a Markdown table of contents for a Jupyter notebook.
View ipynb_toc.py
#!/bin/python
import argparse
import re
import json
import string
parser = argparse.ArgumentParser(
description="Print a Markdown table of contents for a Jupyter notebook."
)
@eigenfoo
eigenfoo / blog.png
Last active Jun 17, 2019
Personal website and blog
@eigenfoo
eigenfoo / NeutralPolitics.csv
Created Apr 18, 2019
Dump of r/NeutralPolitics comments.
View NeutralPolitics.csv
We can't make this file beautiful and searchable because it's too large.
text
View keybase.md

Keybase proof

I hereby claim:

  • I am eigenfoo on github.
  • I am eigenfoo (https://keybase.io/eigenfoo) on keybase.
  • I have a public key ASCsD4wjzqoNalT86VzogMM7vxt5G8z1qv6uFtYRWd9aOQo

To claim this, I am signing this object: