Skip to content

Instantly share code, notes, and snippets.

@bwengals
bwengals / splines.py
Created September 2, 2016 20:40
Patsy b-splines with an option to return the derivative
# This file is part of Patsy
# Copyright (C) 2012-2013 Nathaniel Smith <njs@pobox.com>
# See file LICENSE.txt for license information.
# R-compatible spline basis functions
# These are made available in the patsy.* namespace
__all__ = ["bs"]
import numpy as np
@bwengals
bwengals / retrodesign.R
Last active January 19, 2017 23:27
R code for Gelman & Carlin --- Beyond Power Calculations
retrodesign <- function(A, s, alpha=.05, df=Inf, n.sims=10000){
z <- qt(1-alpha/2, df)
p.hi <- 1 - pt(z-A/s, df)
p.lo <- pt(-z-A/s, df)
power <- p.hi + p.lo
typeS <- p.lo/power
estimate <- A + s*rt(n.sims,df)
significant <- abs(estimate) > s*z
exaggeration <- mean(abs(estimate)[significant])/A
return(list(power=power, typeS=typeS, exaggeration=exaggeration))
@bwengals
bwengals / hpdplot2d.py
Created February 14, 2017 02:42
2d credible intervals in matplotlib from mcmc samples
def hpdplot2d(x_samples, y_samples, bins, perc=0.95, extent=None):
if extent is None:
xmin, xmax = np.min(x_samples), np.max(x_samples)
ymin, ymax = np.min(y_samples), np.max(y_samples)
else:
xmin, xmax, ymin, ymax = extent
x_flat = np.linspace(xmin, xmax, bins)
y_flat = np.linspace(ymin, ymax, bins)
x,y = np.meshgrid(x_flat, y_flat)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bwengals
bwengals / greek_alphabet.py
Created March 19, 2017 08:06 — forked from beniwohli/greek_alphabet.py
A Python dictionary mapping the Unicode codes of the greek alphabet to their names
greek_alphabet = {
u'\u0391': 'Alpha',
u'\u0392': 'Beta',
u'\u0393': 'Gamma',
u'\u0394': 'Delta',
u'\u0395': 'Epsilon',
u'\u0396': 'Zeta',
u'\u0397': 'Eta',
u'\u0398': 'Theta',
u'\u0399': 'Iota',
@bwengals
bwengals / gp_poisson.ipynb
Created March 19, 2017 10:13
poisson gp regression of old faithful histogram data fitted with pymc3
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bwengals
bwengals / gp_testing.ipynb
Last active June 16, 2017 04:56
Testing the FITC approximation code
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bwengals
bwengals / mvnormal-reparam.ipynb
Last active June 29, 2017 22:39
reparameterizing mvnormal
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bwengals
bwengals / gp-testing.ipynb
Last active July 8, 2017 02:46
some simple gp tests
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.