mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-24 14:15:14 +02:00
Other changes.
This commit is contained in:
parent
fad0e07624
commit
29ec128c9d
7 changed files with 164 additions and 143 deletions
|
|
@ -11,11 +11,9 @@ import GPy
|
|||
pb.ion()
|
||||
|
||||
pb.close('all')
|
||||
default_seed=10000
|
||||
|
||||
model_type='Full'
|
||||
inducing=4
|
||||
seed=default_seed
|
||||
"""Simple 1D classification example.
|
||||
:param model_type: type of model to fit ['Full', 'FITC', 'DTC'].
|
||||
:param seed : seed value for data generation (default is 4).
|
||||
|
|
@ -23,21 +21,19 @@ seed=default_seed
|
|||
:param inducing : number of inducing variables (only used for 'FITC' or 'DTC').
|
||||
:type inducing: int
|
||||
"""
|
||||
data = GPy.util.datasets.toy_linear_1d_classification(seed=seed)
|
||||
data = GPy.util.datasets.toy_linear_1d_classification(seed=0)
|
||||
likelihood = GPy.inference.likelihoods.probit(data['Y'][:, 0:1])
|
||||
|
||||
m = GPy.models.GP(data['X'],likelihood=likelihood)
|
||||
#m = GPy.models.GP(data['X'],Y=likelihood.Y)
|
||||
#m = GPy.models.GP(data['X'],likelihood.Y)
|
||||
|
||||
m.constrain_positive('var')
|
||||
m.constrain_positive('len')
|
||||
m.tie_param('lengthscale')
|
||||
m.ensure_default_constraints()
|
||||
if not isinstance(m.likelihood,GPy.inference.likelihoods.gaussian):
|
||||
m.approximate_likelihood()
|
||||
print m.checkgrad()
|
||||
# Optimize and plot
|
||||
m.optimize()
|
||||
#m.em(plot_all=False) # EM algorithm
|
||||
m.plot()
|
||||
m.plot(samples=3)
|
||||
|
||||
print(m)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ Y = F + E
|
|||
pb.plot(X,F,'k-')
|
||||
pb.plot(X,Y,'ro')
|
||||
pb.figure()
|
||||
likelihood = GPy.inference.likelihoods.poisson(Y,scale=4.)
|
||||
likelihood = GPy.inference.likelihoods.poisson(Y,scale=6.)
|
||||
|
||||
m = GPy.models.GP(X,likelihood=likelihood)
|
||||
#m = GPy.models.GP(data['X'],Y=likelihood.Y)
|
||||
|
|
|
|||
|
|
@ -31,46 +31,18 @@ noise = GPy.kern.white(1)
|
|||
kernel = rbf + noise
|
||||
|
||||
# create simple GP model
|
||||
#m1 = GPy.models.sparse_GP_regression(X, Y, kernel, M=M)
|
||||
m1 = GPy.models.sparse_GP(X, kernel, M=M,likelihood= likelihood)
|
||||
#m1 = GPy.models.sparse_GP(X, Y, kernel, M=M)
|
||||
m1 = GPy.models.sparse_GP(X,Y=None, kernel=kernel, M=M,likelihood= likelihood)
|
||||
|
||||
print m1.checkgrad()
|
||||
# contrain all parameters to be positive
|
||||
m1.constrain_positive('(variance|lengthscale|precision)')
|
||||
#m1.constrain_positive('(variance|lengthscale)')
|
||||
#m1.constrain_fixed('prec',10.)
|
||||
|
||||
|
||||
#check gradient FIXME unit test please
|
||||
m1.checkgrad()
|
||||
# optimize and plot
|
||||
m1.optimize('tnc', messages = 1)
|
||||
m1.plot()
|
||||
# print(m1)
|
||||
|
||||
######################################
|
||||
## 2 dimensional example
|
||||
|
||||
# # sample inputs and outputs
|
||||
# X = np.random.uniform(-3.,3.,(N,2))
|
||||
# Y = np.sin(X[:,0:1]) * np.sin(X[:,1:2])+np.random.randn(N,1)*0.05
|
||||
|
||||
# # construct kernel
|
||||
# rbf = GPy.kern.rbf(2)
|
||||
# noise = GPy.kern.white(2)
|
||||
# kernel = rbf + noise
|
||||
|
||||
# # create simple GP model
|
||||
# m2 = GPy.models.sparse_GP_regression(X,Y,kernel, M = 50)
|
||||
# create simple GP model
|
||||
|
||||
# # contrain all parameters to be positive (but not inducing inputs)
|
||||
# m2.constrain_positive('(variance|lengthscale|precision)')
|
||||
|
||||
# #check gradient FIXME unit test please
|
||||
# m2.checkgrad()
|
||||
|
||||
# # optimize and plot
|
||||
# pb.figure()
|
||||
# m2.optimize('tnc', messages = 1)
|
||||
# m2.plot()
|
||||
# print(m2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue