def test_optimization(): # load the data. cdir = os.path.abspath(os.path.dirname(demo.__file__)) data = np.load(os.path.join(cdir, 'xy.npz')) X = data['X'] y = data['y'] # create the model and add data. gp = pygp.BasicGP(sn=.1, sf=1, ell=.1, mu=0) gp.add_data(X, y) # optimize the model pygp.optimize(gp, {'sn': None}) # make sure our constraint is satisfied nt.assert_equal(gp.get_hyper()[0], np.log(0.1))
import pygp.plotting as pp if __name__ == '__main__': # load the data. cdir = os.path.abspath(os.path.dirname(__file__)) data = np.load(os.path.join(cdir, 'xy.npz')) X = data['X'] y = data['y'] # create the model and add data to it. model = pygp.BasicGP(sn=.1, sf=1, ell=.1) model.add_data(X, y) # find the ML hyperparameters and plot the predictions. pygp.optimize(model) # create a prior structure. priors = { 'sn': pygp.priors.Uniform(0.01, 1.0), 'sf': pygp.priors.Uniform(0.01, 5.0), 'ell': pygp.priors.Uniform(0.01, 1.0), 'mu': pygp.priors.Uniform(-2, 2)} # create sample-based models. mcmc = pygp.meta.MCMC(model, priors, n=200, burn=100) smc = pygp.meta.SMC(model, priors, n=200) pl.figure(1) pl.clf()
optimize its hyperparameters. """ import os import numpy as np import matplotlib.pyplot as pl import pygp import pygp.plotting as pp if __name__ == '__main__': # load the data. cdir = os.path.abspath(os.path.dirname(__file__)) data = np.load(os.path.join(cdir, 'xy.npz')) X = data['X'] y = data['y'] # create the model, add data, and optimize it. gp = pygp.BasicGP(sn=.1, sf=1, ell=.1, mu=0) gp.add_data(X, y) pygp.optimize(gp) # plot the posterior. pl.figure(1) pl.clf() pp.plot_posterior(gp) pl.legend(loc=2) pl.draw() pl.show()
cdir = os.path.abspath(os.path.dirname(__file__)) data = np.load(os.path.join(cdir, "xy.npz")) X = data["X"] y = data["y"] # create a basic GP. gp1 = pygp.BasicGP(sn=0.1, sf=1, ell=0.1) gp1.add_data(X, y) # create a sparse GPs. U = np.linspace(-1.3, 2, 10)[:, None] gp2 = pygp.inference.FITC.from_gp(gp1, U) gp3 = pygp.inference.DTC.from_gp(gp1, U) # find the ML parameters pygp.optimize(gp1) pygp.optimize(gp2) pygp.optimize(gp3) # plot the dense gp. pl.figure(1) pl.clf() pl.subplot(131) pp.plot_posterior(gp1) pl.title("Full GP") # grab the axis limits. axis = pl.axis() # plot the FITC sparse gp. pl.subplot(132)
import numpy as np import matplotlib.pyplot as pl import pygp import pygp.plotting as pp if __name__ == '__main__': # load the data. cdir = os.path.abspath(os.path.dirname(__file__)) data = np.load(os.path.join(cdir, 'xy.npz')) X = data['X'] y = data['y'] # create the model, add data, and optimize it. gp = pygp.BasicGP(sn=.1, sf=1, ell=.1, mu=0) gp.add_data(X, y) priors = {"sf": pygp.priors.LogNormal(1e-15, 1, 0.1, 1), "ell": pygp.priors.Uniform(1e-15, 1e2), "sn": pygp.priors.Horseshoe(1e-9, 1, 0.1)} pygp.optimize(gp, priors) print(gp) # plot the posterior. pl.figure(1) pl.clf() pp.plot_posterior(gp) pl.legend(loc=2) pl.draw() pl.show()
import pygp.priors import pygp.plotting as pp if __name__ == '__main__': # load the data. cdir = os.path.abspath(os.path.dirname(__file__)) data = np.load(os.path.join(cdir, 'xy.npz')) X = data['X'] y = data['y'] # create the model and add data to it. model = pygp.BasicGP(sn=.1, sf=1, ell=.1) model.add_data(X, y) # find the ML hyperparameters and plot the predictions. pygp.optimize(model) # create a prior structure. priors = { 'sn': pygp.priors.Uniform(0.01, 1.0), 'sf': pygp.priors.Uniform(0.01, 5.0), 'ell': pygp.priors.Uniform(0.01, 1.0), 'mu': pygp.priors.Uniform(-2, 2) } # create sample-based models. mcmc = pygp.meta.MCMC(model, priors, n=200, burn=100) smc = pygp.meta.SMC(model, priors, n=200) pl.figure(1) pl.clf()
Basic demo showing how to instantiate a simple GP model, add data to it, and optimize its hyperparameters. """ import os import numpy as np import matplotlib.pyplot as pl import pygp import pygp.plotting as pp if __name__ == '__main__': # load the data. cdir = os.path.abspath(os.path.dirname(__file__)) data = np.load(os.path.join(cdir, 'xy.npz')) X = data['X'] y = data['y'] # create the model, add data, and optimize it. gp = pygp.BasicGP(sn=.1, sf=1, ell=.1, mu=0) gp.add_data(X, y) pygp.optimize(gp) # plot the posterior. pl.figure(1) pl.clf() pp.plot_posterior(gp) pl.legend(loc=2) pl.draw() pl.show()