Skip to content

Instantly share code, notes, and snippets.

@BaxterEaves
BaxterEaves / KMeans.hs
Created October 6, 2016 17:20
K-means algorithm in Haskell
-- This is the first thing I've ever written in Haskell by myself.
-- Be gentle.
import Data.List (genericLength)
type Assignment = [Int]
-- |Cluster data into k clusters
kmeans :: (Floating a, Ord a) => [[a]] -> Int -> Assignment
kmeans xs k = _kmeans xs $ nearestMeans xs (take k xs)
@BaxterEaves
BaxterEaves / pp_plot.py
Last active March 15, 2016 03:18
P-P plot of the empirical CDFs of values in two lists.
import numpy as np
import matplotlib.pyplot as plt
def pp_plot(f, p, nbins, ax=None):
""" P-P plot of the empirical CDFs of values in two lists, f and p. """
if ax is None:
ax = plt.gca()
uniqe_vals_f = list(set(f))
@BaxterEaves
BaxterEaves / scrape_pnas.py
Last active February 14, 2016 16:24
Scrape abstracts from PNAS.
"""
Copyright (C) 2015 Baxter Eaves
License: Do what the fuck you want to public license (WTFPL) V2
Scrape abstracts from the Proceedings of the National Academy of Sciences.
Requires: beutifulsoup4
"""
import re
@BaxterEaves
BaxterEaves / igmm.py
Last active February 18, 2016 21:06
Infinite Gaussian mixture model using the collapsed Gibbs sampler
"""
Copyright (C) 2016 Baxter Eaves
License: Do what the fuck you want to public license (WTFPL) V2
Infinite Gaussian Mixture Model
Requires: numpy, scipy, matplotlib, seaborn, pandas
"""
import numpy as np
@BaxterEaves
BaxterEaves / bhc.py
Created July 16, 2015 21:20
Bayesian hierarchical clustering
"""
Copyright (C) 2015 Baxter Eaves
License: Do what the fuck you want to public license (WTFPL) V2
Bayesian hierarchical clustering.
Heller, K. A., & Ghahramani, Z. (2005). Bayesian Hierarchical Clustering.
Neuroscience, 6(section 2), 297–304. doi:10.1145/1102351.1102389
"""
import itertools as it
@BaxterEaves
BaxterEaves / etrs.py
Last active August 29, 2015 14:24
Rejection sampler for the epistemic trust model of Shafto, Eaves, et al (2012)
"""
Copyright (C) 2015 Baxter Eaves
License : WTFPL V2
Rejection sampler for the epistemic trust model of Shafto, Eaves, et al (2012)
"""
import random
@BaxterEaves
BaxterEaves / lda-gibbs.py
Created July 4, 2015 15:03
Collapsed Gibbs sampler for Latent Dirichlet Allocation.
"""
Copyright (C) 2015 Baxter Eaves
License: Do what the fuck you want to public license (WTFPL) V2
Collapsed Gibbs sampler for Latent Dirichlet Allocation.
"""
import matplotlib.pyplot as plt
import numpy as np
import random