mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-04-27 05:46:24 +02:00
Initial commit, setting up the laplace approximation for a student t
This commit is contained in:
parent
67248ab7c2
commit
68eb83955c
5 changed files with 175 additions and 0 deletions
37
python/examples/laplace_approximations.py
Normal file
37
python/examples/laplace_approximations.py
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue