mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-03 08:42:39 +02:00
simulation data changes
This commit is contained in:
parent
350497c726
commit
aaf51f0e19
2 changed files with 29 additions and 38 deletions
|
|
@ -118,13 +118,13 @@ def mrd_simulation(plot_sim=False):
|
||||||
# Y2 -= Y2.mean(0)
|
# Y2 -= Y2.mean(0)
|
||||||
# make_params = lambda ard: np.hstack([[1], ard, [1, .3]])
|
# make_params = lambda ard: np.hstack([[1], ard, [1, .3]])
|
||||||
|
|
||||||
D1, D2, D3, N, M, Q = 50, 100, 8, 200, 2, 5
|
D1, D2, D3, N, M, Q = 50, 100, 8, 300, 2, 6
|
||||||
x = np.linspace(0, 8 * np.pi, N)[:, None]
|
x = np.linspace(0, 4 * np.pi, N)[:, None]
|
||||||
|
|
||||||
s1 = np.vectorize(lambda x: np.sin(x))
|
s1 = np.vectorize(lambda x: np.sin(x))
|
||||||
s2 = np.vectorize(lambda x: np.cos(x))
|
s2 = np.vectorize(lambda x: x * np.cos(x))
|
||||||
s3 = np.vectorize(lambda x:-np.exp(-np.cos(2 * x)))
|
sS = np.vectorize(lambda x:-np.exp(-np.cos(2 * x)))
|
||||||
sS = np.vectorize(lambda x: x * np.sin(2 * x))
|
s3 = np.vectorize(lambda x: np.sin(2 * x))
|
||||||
|
|
||||||
s1 = s1(x)
|
s1 = s1(x)
|
||||||
s2 = s2(x)
|
s2 = s2(x)
|
||||||
|
|
@ -161,16 +161,16 @@ def mrd_simulation(plot_sim=False):
|
||||||
Y2 += .5 * np.random.randn(*Y2.shape)
|
Y2 += .5 * np.random.randn(*Y2.shape)
|
||||||
Y3 += .5 * np.random.randn(*Y3.shape)
|
Y3 += .5 * np.random.randn(*Y3.shape)
|
||||||
|
|
||||||
# Y1 -= Y1.mean(0)
|
Y1 -= Y1.mean(0)
|
||||||
# Y2 -= Y2.mean(0)
|
Y2 -= Y2.mean(0)
|
||||||
# Y3 -= Y3.mean(0)
|
Y3 -= Y3.mean(0)
|
||||||
|
|
||||||
# Y1 /= Y1.std(0)
|
Y1 /= Y1.std(0)
|
||||||
# Y2 /= Y2.std(0)
|
Y2 /= Y2.std(0)
|
||||||
# Y3 /= Y3.std(0)
|
Y3 /= Y3.std(0)
|
||||||
|
|
||||||
Slist = [s1, s2, sS]
|
Slist = [s1, s2, sS]
|
||||||
Ylist = [Y1, Y2]
|
Ylist = [Y1]
|
||||||
|
|
||||||
if plot_sim:
|
if plot_sim:
|
||||||
import pylab
|
import pylab
|
||||||
|
|
@ -190,20 +190,22 @@ def mrd_simulation(plot_sim=False):
|
||||||
pylab.tight_layout()
|
pylab.tight_layout()
|
||||||
|
|
||||||
# k = kern.rbf(Q, ARD=True) + kern.bias(Q) + kern.white(Q)
|
# 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)
|
k = kern.linear(Q, ARD=True) + kern.bias(Q, .01) + kern.white(Q, .1)
|
||||||
|
m = mrd.MRD(*Ylist, Q=Q, M=M, kernel=k, initx="concat", initz='permute', _debug=False)
|
||||||
m.ensure_default_constraints()
|
m.ensure_default_constraints()
|
||||||
|
ardvar = 5. / (m.X.max(axis=0) - m.X.min(axis=0))
|
||||||
|
|
||||||
for i, Y in enumerate(Ylist):
|
for i, Y in enumerate(Ylist):
|
||||||
m.set('{}_noise'.format(i + 1), Y.var() / 100.)
|
m.set('{}_noise'.format(i + 1), Y.var() / 100.)
|
||||||
|
|
||||||
# import ipdb;ipdb.set_trace()
|
|
||||||
cstr = "variance"
|
cstr = "variance"
|
||||||
m.unconstrain(cstr); m.constrain_bounded(cstr, 1e-15, 1.)
|
m.unconstrain(cstr); m.constrain_bounded(cstr, 1e-12, 1.)
|
||||||
|
|
||||||
# print "initializing beta"
|
# print "initializing beta"
|
||||||
# cstr = "noise"
|
# cstr = "noise"
|
||||||
# m.unconstrain(cstr); m.constrain_fixed(cstr)
|
# m.unconstrain(cstr); m.constrain_fixed(cstr)
|
||||||
|
# import ipdb;ipdb.set_trace()
|
||||||
# m.optimize('scg', messages=1, max_f_eval=200)
|
# m.optimize('scg', messages=1, max_f_eval=200)
|
||||||
#
|
#
|
||||||
# print "releasing beta"
|
# print "releasing beta"
|
||||||
|
|
|
||||||
|
|
@ -273,39 +273,28 @@ class MRD(model):
|
||||||
|
|
||||||
def plot_X_1d(self, colors=None):
|
def plot_X_1d(self, colors=None):
|
||||||
fig = pylab.figure(num="MRD X 1d", figsize=(min(8, (3 * len(self.bgplvms))), min(12, (2 * self.X.shape[1]))))
|
fig = pylab.figure(num="MRD X 1d", figsize=(min(8, (3 * len(self.bgplvms))), min(12, (2 * self.X.shape[1]))))
|
||||||
fig.clf()
|
|
||||||
ax1 = fig.add_subplot(self.X.shape[1], 1, 1)
|
|
||||||
if colors is None:
|
if colors is None:
|
||||||
colors = ax1._get_lines.color_cycle
|
colors = pylab.gca()._get_lines.color_cycle
|
||||||
ax1.plot(self.X, c='k', alpha=.3)
|
pylab.clf()
|
||||||
plots = ax1.plot(self.X.T[0], c=colors.next())
|
plots = []
|
||||||
ax1.fill_between(numpy.arange(self.X.shape[0]),
|
for i in range(self.X.shape[1]):
|
||||||
self.X.T[0] - 2 * numpy.sqrt(self.gref.X_variance.T[0]),
|
ax = fig.add_subplot(self.X.shape[1], 1, i + 1)
|
||||||
self.X.T[0] + 2 * numpy.sqrt(self.gref.X_variance.T[0]),
|
|
||||||
facecolor=plots[-1].get_color(),
|
|
||||||
alpha=.3)
|
|
||||||
ax1.text(1, 1, r"$\mathbf{{X_{}}}".format(1),
|
|
||||||
horizontalalignment='right',
|
|
||||||
verticalalignment='top',
|
|
||||||
transform=ax1.transAxes)
|
|
||||||
for i in range(self.X.shape[1] - 1):
|
|
||||||
ax = fig.add_subplot(self.X.shape[1], 1, i + 2)
|
|
||||||
ax.plot(self.X, c='k', alpha=.3)
|
ax.plot(self.X, c='k', alpha=.3)
|
||||||
plots.extend(ax.plot(self.X.T[i + 1], c=colors.next()))
|
plots.extend(ax.plot(self.X.T[i], c=colors.next(), label=r"$\mathbf{{X_{}}}$".format(i)))
|
||||||
ax.fill_between(numpy.arange(self.X.shape[0]),
|
ax.fill_between(numpy.arange(self.X.shape[0]),
|
||||||
self.X.T[i + 1] - 2 * numpy.sqrt(self.gref.X_variance.T[i + 1]),
|
self.X.T[i] - 2 * numpy.sqrt(self.gref.X_variance.T[i]),
|
||||||
self.X.T[i + 1] + 2 * numpy.sqrt(self.gref.X_variance.T[i + 1]),
|
self.X.T[i] + 2 * numpy.sqrt(self.gref.X_variance.T[i]),
|
||||||
facecolor=plots[-1].get_color(),
|
facecolor=plots[-1].get_color(),
|
||||||
alpha=.3)
|
alpha=.3)
|
||||||
if i < self.X.shape[1] - 2:
|
ax.legend(borderaxespad=0.)
|
||||||
|
if i < self.X.shape[1] - 1:
|
||||||
ax.set_xticklabels('')
|
ax.set_xticklabels('')
|
||||||
ax1.set_xticklabels('')
|
|
||||||
# ax1.legend(plots, [r"$\mathbf{{X_{}}}$".format(i + 1) for i in range(self.X.shape[1])],
|
# ax1.legend(plots, [r"$\mathbf{{X_{}}}$".format(i + 1) for i in range(self.X.shape[1])],
|
||||||
# bbox_to_anchor=(0., 1 + .01 * self.X.shape[1],
|
# bbox_to_anchor=(0., 1 + .01 * self.X.shape[1],
|
||||||
# 1., 1. + .01 * self.X.shape[1]), loc=3,
|
# 1., 1. + .01 * self.X.shape[1]), loc=3,
|
||||||
# ncol=self.X.shape[1], mode="expand", borderaxespad=0.)
|
# ncol=self.X.shape[1], mode="expand", borderaxespad=0.)
|
||||||
pylab.draw()
|
pylab.draw()
|
||||||
fig.tight_layout(h_pad=.01, rect=(0, 0, 1, .95))
|
fig.tight_layout(h_pad=.01) # , rect=(0, 0, 1, .95))
|
||||||
return fig
|
return fig
|
||||||
|
|
||||||
def plot_X(self):
|
def plot_X(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue