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