mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-04-27 05:46:24 +02:00
Got the mode finding without computing Ki
This commit is contained in:
parent
2006a94caa
commit
4a14a82dfb
2 changed files with 152 additions and 63 deletions
|
|
@ -6,6 +6,38 @@ from coxGP.python.likelihoods.Laplace import Laplace
|
|||
from coxGP.python.likelihoods.likelihood_function import student_t
|
||||
|
||||
|
||||
def timing():
|
||||
real_var = 0.1
|
||||
times = 1000
|
||||
deg_free = 10
|
||||
real_sd = np.sqrt(real_var)
|
||||
the_is = np.zeros(times)
|
||||
X = np.linspace(0.0, 10.0, 30)[:, None]
|
||||
for a in xrange(times):
|
||||
Y = np.sin(X) + np.random.randn(*X.shape)*real_var
|
||||
Yc = Y.copy()
|
||||
|
||||
Yc[10] += 100
|
||||
Yc[25] += 10
|
||||
Yc[23] += 10
|
||||
Yc[24] += 10
|
||||
|
||||
edited_real_sd = real_sd
|
||||
kernel1 = GPy.kern.rbf(X.shape[1])
|
||||
|
||||
t_distribution = student_t(deg_free, sigma=edited_real_sd)
|
||||
corrupt_stu_t_likelihood = Laplace(Yc.copy(), t_distribution, rasm=True)
|
||||
m = GPy.models.GP(X, corrupt_stu_t_likelihood, kernel1)
|
||||
m.ensure_default_constraints()
|
||||
m.update_likelihood_approximation()
|
||||
m.optimize()
|
||||
the_is[a] = m.likelihood.i
|
||||
|
||||
print the_is
|
||||
print np.mean(the_is)
|
||||
import ipdb; ipdb.set_trace() ### XXX BREAKPOINT
|
||||
|
||||
|
||||
def student_t_approx():
|
||||
"""
|
||||
Example of regressing with a student t likelihood
|
||||
|
|
@ -80,32 +112,6 @@ def student_t_approx():
|
|||
plt.suptitle('Student-t likelihood')
|
||||
edited_real_sd = real_sd
|
||||
|
||||
print "Clean student t, ncg"
|
||||
t_distribution = student_t(deg_free, sigma=edited_real_sd)
|
||||
stu_t_likelihood = Laplace(Y, t_distribution, rasm=False)
|
||||
m = GPy.models.GP(X, stu_t_likelihood, kernel3)
|
||||
m.ensure_default_constraints()
|
||||
m.update_likelihood_approximation()
|
||||
m.optimize()
|
||||
print(m)
|
||||
plt.subplot(221)
|
||||
m.plot()
|
||||
plt.plot(X_full, Y_full)
|
||||
plt.ylim(-2.5, 2.5)
|
||||
|
||||
print "Corrupt student t, ncg"
|
||||
t_distribution = student_t(deg_free, sigma=edited_real_sd)
|
||||
corrupt_stu_t_likelihood = Laplace(Yc.copy(), t_distribution, rasm=False)
|
||||
m = GPy.models.GP(X, corrupt_stu_t_likelihood, kernel5)
|
||||
m.ensure_default_constraints()
|
||||
m.update_likelihood_approximation()
|
||||
m.optimize()
|
||||
print(m)
|
||||
plt.subplot(223)
|
||||
m.plot()
|
||||
plt.plot(X_full, Y_full)
|
||||
plt.ylim(-2.5, 2.5)
|
||||
|
||||
print "Clean student t, rasm"
|
||||
t_distribution = student_t(deg_free, sigma=edited_real_sd)
|
||||
stu_t_likelihood = Laplace(Y.copy(), t_distribution, rasm=True)
|
||||
|
|
@ -133,6 +139,33 @@ def student_t_approx():
|
|||
plt.ylim(-2.5, 2.5)
|
||||
import ipdb; ipdb.set_trace() ### XXX BREAKPOINT
|
||||
|
||||
print "Clean student t, ncg"
|
||||
t_distribution = student_t(deg_free, sigma=edited_real_sd)
|
||||
stu_t_likelihood = Laplace(Y, t_distribution, rasm=False)
|
||||
m = GPy.models.GP(X, stu_t_likelihood, kernel3)
|
||||
m.ensure_default_constraints()
|
||||
m.update_likelihood_approximation()
|
||||
m.optimize()
|
||||
print(m)
|
||||
plt.subplot(221)
|
||||
m.plot()
|
||||
plt.plot(X_full, Y_full)
|
||||
plt.ylim(-2.5, 2.5)
|
||||
|
||||
print "Corrupt student t, ncg"
|
||||
t_distribution = student_t(deg_free, sigma=edited_real_sd)
|
||||
corrupt_stu_t_likelihood = Laplace(Yc.copy(), t_distribution, rasm=False)
|
||||
m = GPy.models.GP(X, corrupt_stu_t_likelihood, kernel5)
|
||||
m.ensure_default_constraints()
|
||||
m.update_likelihood_approximation()
|
||||
m.optimize()
|
||||
print(m)
|
||||
plt.subplot(223)
|
||||
m.plot()
|
||||
plt.plot(X_full, Y_full)
|
||||
plt.ylim(-2.5, 2.5)
|
||||
|
||||
|
||||
###with a student t distribution, since it has heavy tails it should work well
|
||||
###likelihood_function = student_t(deg_free, sigma=real_var)
|
||||
###lap = Laplace(Y, likelihood_function)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue