def stick_bgplvm(model=None, optimize=True, verbose=True, plot=True): from GPy.models import BayesianGPLVM from matplotlib import pyplot as plt import GPy data = GPy.util.datasets.osu_run1() Q = 6 kernel = GPy.kern.rbf(Q, ARD=True) + GPy.kern.bias( Q, _np.exp(-2)) + GPy.kern.white(Q, _np.exp(-2)) m = BayesianGPLVM(data['Y'], Q, init="PCA", num_inducing=20, kernel=kernel) # optimize m.ensure_default_constraints() if optimize: m.optimize('scg', messages=verbose, max_iters=200, xtol=1e-300, ftol=1e-300) m._set_params(m._get_params()) if plot: plt.clf, (latent_axes, sense_axes) = plt.subplots(1, 2) plt.sca(latent_axes) m.plot_latent() y = m.likelihood.Y[0, :].copy() data_show = GPy.util.visualize.stick_show(y[None, :], connect=data['connect']) GPy.util.visualize.lvm_dimselect(m.X[0, :].copy(), m, data_show, latent_axes=latent_axes, sense_axes=sense_axes) raw_input('Press enter to finish') return m
def stick_bgplvm(model=None, optimize=True, verbose=True, plot=True): """Interactive visualisation of the Stick Man data from Ohio State University with the Bayesian GPLVM.""" from GPy.models import BayesianGPLVM from matplotlib import pyplot as plt import numpy as np import GPy import pods data = pods.datasets.osu_run1() Q = 6 kernel = GPy.kern.RBF(Q, lengthscale=np.repeat(.5, Q), ARD=True) m = BayesianGPLVM(data['Y'], Q, init="PCA", num_inducing=20, kernel=kernel) m.data = data m.likelihood.variance = 0.001 # optimize try: if optimize: m.optimize('bfgs', messages=verbose, max_iters=5e3, bfgs_factor=10) except KeyboardInterrupt: print("Keyboard interrupt, continuing to plot and return") if plot: fig, (latent_axes, sense_axes) = plt.subplots(1, 2) plt.sca(latent_axes) m.plot_latent(ax=latent_axes) y = m.Y[:1, :].copy() data_show = GPy.plotting.matplot_dep.visualize.stick_show(y, connect=data['connect']) dim_select = GPy.plotting.matplot_dep.visualize.lvm_dimselect(m.X.mean[:1, :].copy(), m, data_show, latent_axes=latent_axes, sense_axes=sense_axes) fig.canvas.draw() # Canvas.show doesn't work on OSX. #fig.canvas.show() raw_input('Press enter to finish') return m
def stick_bgplvm(model=None, optimize=True, verbose=True, plot=True): """Interactive visualisation of the Stick Man data from Ohio State University with the Bayesian GPLVM.""" from GPy.models import BayesianGPLVM from matplotlib import pyplot as plt import numpy as np import GPy import pods data = pods.datasets.osu_run1() Q = 6 kernel = GPy.kern.RBF(Q, lengthscale=np.repeat(0.5, Q), ARD=True) m = BayesianGPLVM(data["Y"], Q, init="PCA", num_inducing=20, kernel=kernel) m.data = data m.likelihood.variance = 0.001 # optimize try: if optimize: m.optimize("bfgs", messages=verbose, max_iters=5e3, bfgs_factor=10) except KeyboardInterrupt: print("Keyboard interrupt, continuing to plot and return") if plot: fig, (latent_axes, sense_axes) = plt.subplots(1, 2) plt.sca(latent_axes) m.plot_latent(ax=latent_axes) y = m.Y[:1, :].copy() data_show = GPy.plotting.matplot_dep.visualize.stick_show( y, connect=data["connect"]) dim_select = GPy.plotting.matplot_dep.visualize.lvm_dimselect( m.X.mean[:1, :].copy(), m, data_show, latent_axes=latent_axes, sense_axes=sense_axes, ) fig.canvas.draw() # Canvas.show doesn't work on OSX. # fig.canvas.show() input("Press enter to finish") return m
def stick_bgplvm(model=None, optimize=True, verbose=True, plot=True): from GPy.models import BayesianGPLVM from matplotlib import pyplot as plt import numpy as np import GPy import pods data = pods.datasets.osu_run1() Q = 6 kernel = GPy.kern.RBF(Q, lengthscale=np.repeat(.5, Q), ARD=True) m = BayesianGPLVM(data['Y'], Q, init="PCA", num_inducing=20, kernel=kernel) m.data = data m.likelihood.variance = 0.001 # optimize try: if optimize: m.optimize('bfgs', messages=verbose, max_iters=5e3, bfgs_factor=10) except KeyboardInterrupt: print "Keyboard interrupt, continuing to plot and return" if plot: fig, (latent_axes, sense_axes) = plt.subplots(1, 2) plt.sca(latent_axes) m.plot_latent(ax=latent_axes) y = m.Y[:1, :].copy() data_show = GPy.plotting.matplot_dep.visualize.stick_show( y, connect=data['connect']) dim_select = GPy.plotting.matplot_dep.visualize.lvm_dimselect( m.X.mean[:1, :].copy(), m, data_show, latent_axes=latent_axes, sense_axes=sense_axes) fig.canvas.draw() fig.canvas.show() raw_input('Press enter to finish') return m
def stick_bgplvm(model=None, optimize=True, verbose=True, plot=True): from GPy.models import BayesianGPLVM from matplotlib import pyplot as plt import GPy data = GPy.util.datasets.osu_run1() Q = 6 kernel = GPy.kern.rbf(Q, ARD=True) + GPy.kern.bias(Q, _np.exp(-2)) + GPy.kern.white(Q, _np.exp(-2)) m = BayesianGPLVM(data['Y'], Q, init="PCA", num_inducing=20, kernel=kernel) # optimize m.ensure_default_constraints() if optimize: m.optimize('scg', messages=verbose, max_iters=200, xtol=1e-300, ftol=1e-300) m._set_params(m._get_params()) if plot: plt.clf, (latent_axes, sense_axes) = plt.subplots(1, 2) plt.sca(latent_axes) m.plot_latent() y = m.likelihood.Y[0, :].copy() data_show = GPy.util.visualize.stick_show(y[None, :], connect=data['connect']) GPy.util.visualize.lvm_dimselect(m.X[0, :].copy(), m, data_show, latent_axes=latent_axes, sense_axes=sense_axes) raw_input('Press enter to finish') return m