Skip to content

Instantly share code, notes, and snippets.

View fredcallaway's full-sized avatar

Fred Callaway fredcallaway

View GitHub Profile
@fredcallaway
fredcallaway / psi_template.py
Last active July 7, 2017 19:33
A ~very~ simple template engine.
#!/usr/bin/env python
"""
A ~very~ simple template engine.
This script replaces variables in FILES with the values
found in variables.yml. This could be used to refer to
the HIT payment in multiple files without needing to update
every file when the payment changes.
The experiment directory is copied to an output directory, deploy/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fredcallaway
fredcallaway / gambler.ipynb
Created February 24, 2017 08:54
Gamblers Problem
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fredcallaway
fredcallaway / ed_hmm.py
Last active November 8, 2018 03:06
Hidden Markov Model implemented in edward
#!/usr/bin/env python
"""Hidden Markov Models
Abstract base class for HMMs and an implementation of an HMM
with discrete states and gaussian emissions.
"""
import tensorflow as tf
import edward as ed
from edward.models import Bernoulli, Categorical, Normal
from itertools import chain, combinations
def powerset(iterable):
xs = list(iterable)
return chain.from_iterable( combinations(xs,n) for n in range(len(xs)+1) )
# Features are binary. An item either has or does not have every feature.
features = 'abcde'
hypotheses_sets = {
from toolz import pipe
class Blank(object):
"""Forgive me Lord, for I have sinned.
Inspired by implicit partial application in Coconut:
http://coconut.readthedocs.io/en/master/DOCS.html#implicit-partial-application
"""
def __getattr__(self, attr):
@fredcallaway
fredcallaway / stochastic_matrix.py
Created November 10, 2016 06:11
Stochastic matrix in pymc3
import numpy as np
import pymc3 as pm
import theano
class StochasticMatrix(pm.Continuous):
"""A stochastic matrix has rows that sum to 1."""
def __init__(self, theta, *args, **kwargs):
shape = (theta.shape[-1], theta.shape[-1])
kwargs.setdefault('shape', shape)
super(StochasticMatrix, self).__init__(*args, **kwargs)
import itertools as it
import numpy as np
ivs = [
('hit', [0, 1, 2]),
('layout', 'ABCDEF'),
('cue', 'TF'),
]
# At present, the first iv defines the number and orderof trials. Thus,
@fredcallaway
fredcallaway / iterated_learning.ipynb
Last active October 18, 2016 05:05
MPL's don't like circles
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fredcallaway
fredcallaway / classypedia.css
Created September 12, 2016 18:39
Classypedia with improved TOC
@font-face {
font-family: 'Cinzel';
font-style: normal;
font-weight: 400;
src: local('Cinzel-Regular'), url(//themes.googleusercontent.com/static/fonts/cinzel/v1/mLL0ZqnXRx3m16FnBy9gcg.woff) format('woff');
}
@font-face {
font-family: 'Droid Sans';
font-style: normal;
font-weight: 400;