mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-12 05:22:38 +02:00
[examples] stick man example corrected
This commit is contained in:
parent
42fe64cec9
commit
0acb196b26
1 changed files with 17 additions and 10 deletions
|
|
@ -408,13 +408,13 @@ def stick(kernel=None, optimize=True, verbose=True, plot=True):
|
||||||
data = GPy.util.datasets.osu_run1()
|
data = GPy.util.datasets.osu_run1()
|
||||||
# optimize
|
# optimize
|
||||||
m = GPy.models.GPLVM(data['Y'], 2, kernel=kernel)
|
m = GPy.models.GPLVM(data['Y'], 2, kernel=kernel)
|
||||||
if optimize: m.optimize(messages=verbose, max_f_eval=10000)
|
if optimize: m.optimize('bfgs', messages=verbose, max_f_eval=10000)
|
||||||
if plot:
|
if plot:
|
||||||
plt.clf
|
plt.clf
|
||||||
ax = m.plot_latent()
|
ax = m.plot_latent()
|
||||||
y = m.Y[0, :]
|
y = m.Y[0, :]
|
||||||
data_show = GPy.plotting.matplot_dep.visualize.stick_show(y[None, :], connect=data['connect'])
|
data_show = GPy.plotting.matplot_dep.visualize.stick_show(y[None, :], connect=data['connect'])
|
||||||
vis = GPy.plotting.matplot_dep.visualize.lvm(m.X[0, :].copy(), m, data_show, latent_axes=ax)
|
vis = GPy.plotting.matplot_dep.visualize.lvm(m.X[:1, :].copy(), m, data_show, latent_axes=ax)
|
||||||
raw_input('Press enter to finish')
|
raw_input('Press enter to finish')
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
@ -475,23 +475,30 @@ def robot_wireless(optimize=True, verbose=True, plot=True):
|
||||||
def stick_bgplvm(model=None, optimize=True, verbose=True, plot=True):
|
def stick_bgplvm(model=None, optimize=True, verbose=True, plot=True):
|
||||||
from GPy.models import BayesianGPLVM
|
from GPy.models import BayesianGPLVM
|
||||||
from matplotlib import pyplot as plt
|
from matplotlib import pyplot as plt
|
||||||
|
import numpy as np
|
||||||
import GPy
|
import GPy
|
||||||
|
|
||||||
data = GPy.util.datasets.osu_run1()
|
data = GPy.util.datasets.osu_run1()
|
||||||
Q = 6
|
Q = 6
|
||||||
kernel = GPy.kern.RBF(Q, ARD=True) + GPy.kern.Bias(Q, _np.exp(-2)) + GPy.kern.White(Q, _np.exp(-2))
|
kernel = GPy.kern.RBF(Q, lengthscale=np.repeat(.5, Q), ARD=True) + GPy.kern.Bias(Q, _np.exp(-2))
|
||||||
m = BayesianGPLVM(data['Y'], Q, init="PCA", num_inducing=20, kernel=kernel)
|
m = BayesianGPLVM(data['Y'], Q, init="PCA", num_inducing=20, kernel=kernel)
|
||||||
|
|
||||||
|
m.data = data
|
||||||
|
|
||||||
|
m.X.mean -= m.X.mean.mean(0); m.X.mean /= m.X.mean.var(0)
|
||||||
|
m.X.variance /= 100
|
||||||
|
m.likelihood.variance = 0.001
|
||||||
|
m.Z.randomize()
|
||||||
|
|
||||||
# optimize
|
# optimize
|
||||||
m.ensure_default_constraints()
|
if optimize: m.optimize('bfgs', messages=verbose, max_iters=1500, xtol=1e-300, ftol=1e-300)
|
||||||
if optimize: m.optimize('scg', messages=verbose, max_iters=200, xtol=1e-300, ftol=1e-300)
|
|
||||||
m._set_params(m._get_params())
|
|
||||||
if plot:
|
if plot:
|
||||||
plt.clf, (latent_axes, sense_axes) = plt.subplots(1, 2)
|
plt.clf, (latent_axes, sense_axes) = plt.subplots(1, 2)
|
||||||
plt.sca(latent_axes)
|
plt.sca(latent_axes)
|
||||||
m.plot_latent()
|
m.plot_latent(ax=latent_axes)
|
||||||
y = m.likelihood.Y[0, :].copy()
|
y = m.Y[:1, :].copy()
|
||||||
data_show = GPy.plotting.matplot_dep.visualize.stick_show(y[None, :], connect=data['connect'])
|
data_show = GPy.plotting.matplot_dep.visualize.stick_show(y, connect=data['connect'])
|
||||||
GPy.plotting.matplot_dep.visualize.lvm_dimselect(m.X[0, :].copy(), m, data_show, latent_axes=latent_axes, sense_axes=sense_axes)
|
GPy.plotting.matplot_dep.visualize.lvm_dimselect(m.X.mean[:1, :].copy(), m, data_show, latent_axes=latent_axes, sense_axes=sense_axes)
|
||||||
raw_input('Press enter to finish')
|
raw_input('Press enter to finish')
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue