Example is working

This commit is contained in:
Ricardo Andrade 2013-02-07 11:35:29 +00:00
parent 8fd79f6eee
commit 02dc5c7b48

View file

@ -3,46 +3,45 @@
""" """
Simple Gaussian Processes classification Gaussian Processes + Expectation Propagation - Poisson Likelihood
""" """
import pylab as pb import pylab as pb
import numpy as np import numpy as np
import GPy import GPy
pb.ion()
pb.close('all')
default_seed=10000 default_seed=10000
model_type='Full' def toy_1d(seed=default_seed):
inducing=4 """
seed=default_seed Simple 1D classification example
"""Simple 1D classification example. :param seed : seed value for data generation (default is 4).
:param model_type: type of model to fit ['Full', 'FITC', 'DTC']. :type seed: int
:param seed : seed value for data generation (default is 4). """
:type seed: int
:param inducing : number of inducing variables (only used for 'FITC' or 'DTC').
:type inducing: int
"""
X = np.arange(0,100,5)[:,None] X = np.arange(0,100,5)[:,None]
F = np.round(np.sin(X/18.) + .1*X) + np.arange(5,25)[:,None] F = np.round(np.sin(X/18.) + .1*X) + np.arange(5,25)[:,None]
E = np.random.randint(-5,5,20)[:,None] E = np.random.randint(-5,5,20)[:,None]
Y = F + E Y = F + E
pb.figure()
likelihood = GPy.inference.likelihoods.poisson(Y,scale=1.)
m = GPy.models.GP(X,likelihood=likelihood) kernel = GPy.kern.rbf(1)
#m = GPy.models.GP(X,Y=likelihood.Y) distribution = GPy.likelihoods.likelihood_functions.Poisson()
likelihood = GPy.likelihoods.EP(Y,distribution)
m.constrain_positive('var') m = GPy.models.GP(X,likelihood,kernel)
m.constrain_positive('len') m.ensure_default_constraints()
m.tie_param('lengthscale')
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(samples=4)
print(m) # Approximate likelihood
m.update_likelihood_approximation()
# Optimize and plot
m.optimize()
#m.EPEM FIXME
print m
# Plot
pb.subplot(211)
m.plot_f() #GP plot
pb.subplot(212)
m.plot() #Output plot
return m