Skip to content

Instantly share code, notes, and snippets.

@beaucronin
beaucronin / example1.py
Created April 19, 2012 15:26
Veritable uncertainty quantification examples
pr = analysis.predict({'petal_length': 1.5, 'petal_width': None})
interval = pr.credible_values('petal_width')
# => (0.06619570898596525, 0.45519138428493605)
interval[1] - interval[0]
# => 0.38899567529897083
pr = analysis.predict({'petal_length': 5.0, 'petal_width': None})
interval = pr.credible_values('petal_width')
# => (1.3341578189754613, 2.4761532421771784)
interval[1] - interval[0]
@beaucronin
beaucronin / iris.csv
Created April 18, 2012 17:59
Veritable python analysis for Fisher iris data
sepal_length sepal_width petal_length petal_width class
5.1 3.5 1.4 0.2 Iris-setosa
4.9 3.0 1.4 0.2 Iris-setosa
4.7 3.2 1.3 0.2 Iris-setosa
4.6 3.1 1.5 0.2 Iris-setosa
5.0 3.6 1.4 0.2 Iris-setosa
5.4 3.9 1.7 0.4 Iris-setosa
4.6 3.4 1.4 0.3 Iris-setosa
5.0 3.4 1.5 0.2 Iris-setosa
4.4 2.9 1.4 0.2 Iris-setosa
@beaucronin
beaucronin / crp_generator.py
Created October 9, 2011 16:37
A Python generator for the Chinese Restaurant Process
from random import random
def crpgen(N = None, alpha = 1.0):
"""
A generator that implements the Chinese Restaurant Process
"""
counts = []
n = 0
while N == None or n < N:
# Compute the (unnormalized) probabilities of assigning the new object
@beaucronin
beaucronin / gist:1258210
Created October 3, 2011 00:55
Metropolis sampler pseudocode
x = initial()
prob = target_dist(x)
for i in range(steps):
x_star = propose(x)
prob_star = target_dist(x)
if prob_star > prob or random() < prob_star / prob:
x = x_star
prob = prob_star