Initial commit, setting up the laplace approximation for a student t

This commit is contained in:
Alan Saul 2013-03-12 17:42:00 +00:00
parent 67248ab7c2
commit 68eb83955c
5 changed files with 175 additions and 0 deletions

View file

@ -0,0 +1,37 @@
import GPy
import numpy as np
import scipy as sp
import scipy.stats
import matplotlib.pyplot as plt
def student_t_approx():
"""
Example of regressing with a student t likelihood
"""
#Start a function, any function
X = np.sort(np.random.uniform(0, 15, 70))[:, None]
Y = np.sin(X)
#Add some extreme value noise to some of the datapoints
percent_corrupted = 0.05
corrupted_datums = int(np.round(Y.shape[0] * percent_corrupted))
indices = np.arange(Y.shape[0])
np.random.shuffle(indices)
corrupted_indices = indices[:corrupted_datums]
print corrupted_indices
noise = np.random.uniform(-10,10,(len(corrupted_indices), 1))
Y[corrupted_indices] += noise
#A GP should completely break down due to the points as they get a lot of weight
# create simple GP model
m = GPy.models.GP_regression(X,Y)
# optimize
m.ensure_default_constraints()
m.optimize()
# plot
m.plot()
print m
#with a student t distribution, since it has heavy tails it should work well