mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-24 14:15:14 +02:00
adjusted plotting behaviour in X1d
This commit is contained in:
parent
9acc6e9723
commit
350497c726
2 changed files with 128 additions and 46 deletions
|
|
@ -118,13 +118,13 @@ def mrd_simulation(plot_sim=False):
|
|||
# Y2 -= Y2.mean(0)
|
||||
# make_params = lambda ard: np.hstack([[1], ard, [1, .3]])
|
||||
|
||||
D1, D2, D3, N, M, Q = 6, 7, 8, 150, 18, 5
|
||||
x = np.linspace(0, 2 * np.pi, N)[:, None]
|
||||
D1, D2, D3, N, M, Q = 50, 100, 8, 200, 2, 5
|
||||
x = np.linspace(0, 8 * np.pi, N)[:, None]
|
||||
|
||||
s1 = np.vectorize(lambda x: np.sin(x))
|
||||
s2 = np.vectorize(lambda x: np.cos(x))
|
||||
s3 = np.vectorize(lambda x:-np.exp(-np.cos(2 * x)))
|
||||
sS = np.vectorize(lambda x: np.sin(2 * x))
|
||||
sS = np.vectorize(lambda x: x * np.sin(2 * x))
|
||||
|
||||
s1 = s1(x)
|
||||
s2 = s2(x)
|
||||
|
|
@ -144,20 +144,30 @@ def mrd_simulation(plot_sim=False):
|
|||
S2 = np.hstack([s2, sS])
|
||||
S3 = np.hstack([s3, sS])
|
||||
|
||||
from GPy.models import mrd
|
||||
from GPy import kern
|
||||
reload(mrd); reload(kern)
|
||||
|
||||
# k = kern.rbf(2, ARD=True) + kern.bias(2) + kern.white(2)
|
||||
# Y1 = np.random.multivariate_normal(np.zeros(N), k.K(S1), D1).T
|
||||
# Y2 = np.random.multivariate_normal(np.zeros(N), k.K(S2), D2).T
|
||||
# Y3 = np.random.multivariate_normal(np.zeros(N), k.K(S3), D3).T
|
||||
|
||||
Y1 = S1.dot(np.random.randn(S1.shape[1], D1))
|
||||
Y2 = S2.dot(np.random.randn(S2.shape[1], D2))
|
||||
Y3 = S3.dot(np.random.randn(S3.shape[1], D3))
|
||||
|
||||
Y1 += .1 * np.random.randn(*Y1.shape)
|
||||
Y2 += .1 * np.random.randn(*Y2.shape)
|
||||
Y3 += .1 * np.random.randn(*Y3.shape)
|
||||
Y1 += .5 * np.random.randn(*Y1.shape)
|
||||
Y2 += .5 * np.random.randn(*Y2.shape)
|
||||
Y3 += .5 * np.random.randn(*Y3.shape)
|
||||
|
||||
Y1 -= Y1.mean(0)
|
||||
Y2 -= Y2.mean(0)
|
||||
Y3 -= Y3.mean(0)
|
||||
Y1 /= Y1.std(0)
|
||||
Y2 /= Y2.std(0)
|
||||
Y3 /= Y3.std(0)
|
||||
# Y1 -= Y1.mean(0)
|
||||
# Y2 -= Y2.mean(0)
|
||||
# Y3 -= Y3.mean(0)
|
||||
|
||||
# Y1 /= Y1.std(0)
|
||||
# Y2 /= Y2.std(0)
|
||||
# Y3 /= Y3.std(0)
|
||||
|
||||
Slist = [s1, s2, sS]
|
||||
Ylist = [Y1, Y2]
|
||||
|
|
@ -173,21 +183,33 @@ def mrd_simulation(plot_sim=False):
|
|||
ax.plot(x, S, label=lab)
|
||||
ax.legend()
|
||||
for i, Y in enumerate(Ylist):
|
||||
ax = fig.add_subplot(2, len(Ylist), len(Slist) + i)
|
||||
ax = fig.add_subplot(2, len(Ylist), len(Ylist) + 1 + i)
|
||||
ax.imshow(Y)
|
||||
ax.set_title("Y{}".format(i + 1))
|
||||
pylab.draw()
|
||||
pylab.tight_layout()
|
||||
|
||||
from GPy.models import mrd
|
||||
from GPy import kern
|
||||
reload(mrd); reload(kern)
|
||||
k = kern.rbf(Q, ARD=True) + kern.bias(Q) + kern.white(Q)
|
||||
m = mrd.MRD(*Ylist, Q=Q, M=M, kernel=k, init="single", _debug=False)
|
||||
# k = kern.rbf(Q, ARD=True) + kern.bias(Q) + kern.white(Q)
|
||||
k = kern.linear(Q, ARD=True) + kern.bias(Q) + kern.white(Q)
|
||||
m = mrd.MRD(*Ylist, Q=Q, M=M, kernel=k, initx="concat", _debug=False)
|
||||
m.ensure_default_constraints()
|
||||
|
||||
# cstr = "noise|white|variance"
|
||||
# m.unconstrain(cstr); m.constrain_bounded(cstr, 1e-10, 1.)
|
||||
for i, Y in enumerate(Ylist):
|
||||
m.set('{}_noise'.format(i + 1), Y.var() / 100.)
|
||||
|
||||
# import ipdb;ipdb.set_trace()
|
||||
cstr = "variance"
|
||||
m.unconstrain(cstr); m.constrain_bounded(cstr, 1e-15, 1.)
|
||||
|
||||
# print "initializing beta"
|
||||
# cstr = "noise"
|
||||
# m.unconstrain(cstr); m.constrain_fixed(cstr)
|
||||
# m.optimize('scg', messages=1, max_f_eval=200)
|
||||
#
|
||||
# print "releasing beta"
|
||||
# cstr = "noise"
|
||||
# m.unconstrain(cstr); m.constrain_positive(cstr)
|
||||
|
||||
|
||||
m.auto_scale_factor = True
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue