From aaf51f0e19603e07849c4c743b2425e9d47ef55b Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Tue, 16 Apr 2013 12:37:31 +0100 Subject: [PATCH] simulation data changes --- GPy/examples/dimensionality_reduction.py | 34 +++++++++++++----------- GPy/models/mrd.py | 33 ++++++++--------------- 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/GPy/examples/dimensionality_reduction.py b/GPy/examples/dimensionality_reduction.py index 2c7d6bea..f3e40181 100644 --- a/GPy/examples/dimensionality_reduction.py +++ b/GPy/examples/dimensionality_reduction.py @@ -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 = 50, 100, 8, 200, 2, 5 - x = np.linspace(0, 8 * np.pi, N)[:, None] + D1, D2, D3, N, M, Q = 50, 100, 8, 300, 2, 6 + x = np.linspace(0, 4 * 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: x * np.sin(2 * x)) + s2 = np.vectorize(lambda x: x * np.cos(x)) + sS = np.vectorize(lambda x:-np.exp(-np.cos(2 * x))) + s3 = np.vectorize(lambda x: np.sin(2 * x)) s1 = s1(x) s2 = s2(x) @@ -161,16 +161,16 @@ def mrd_simulation(plot_sim=False): 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.mean(0) + Y2 -= Y2.mean(0) + Y3 -= Y3.mean(0) - # Y1 /= Y1.std(0) - # Y2 /= Y2.std(0) - # Y3 /= Y3.std(0) + Y1 /= Y1.std(0) + Y2 /= Y2.std(0) + Y3 /= Y3.std(0) Slist = [s1, s2, sS] - Ylist = [Y1, Y2] + Ylist = [Y1] if plot_sim: import pylab @@ -190,20 +190,22 @@ def mrd_simulation(plot_sim=False): pylab.tight_layout() # 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() + ardvar = 5. / (m.X.max(axis=0) - m.X.min(axis=0)) 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.) + m.unconstrain(cstr); m.constrain_bounded(cstr, 1e-12, 1.) # print "initializing beta" # cstr = "noise" # m.unconstrain(cstr); m.constrain_fixed(cstr) +# import ipdb;ipdb.set_trace() # m.optimize('scg', messages=1, max_f_eval=200) # # print "releasing beta" diff --git a/GPy/models/mrd.py b/GPy/models/mrd.py index 943db420..f5e56d08 100644 --- a/GPy/models/mrd.py +++ b/GPy/models/mrd.py @@ -273,39 +273,28 @@ class MRD(model): 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.clf() - ax1 = fig.add_subplot(self.X.shape[1], 1, 1) if colors is None: - colors = ax1._get_lines.color_cycle - ax1.plot(self.X, c='k', alpha=.3) - plots = ax1.plot(self.X.T[0], c=colors.next()) - ax1.fill_between(numpy.arange(self.X.shape[0]), - self.X.T[0] - 2 * numpy.sqrt(self.gref.X_variance.T[0]), - 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) + colors = pylab.gca()._get_lines.color_cycle + pylab.clf() + plots = [] + for i in range(self.X.shape[1]): + ax = fig.add_subplot(self.X.shape[1], 1, i + 1) 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]), - self.X.T[i + 1] - 2 * numpy.sqrt(self.gref.X_variance.T[i + 1]), - 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] + 2 * numpy.sqrt(self.gref.X_variance.T[i]), facecolor=plots[-1].get_color(), alpha=.3) - if i < self.X.shape[1] - 2: + ax.legend(borderaxespad=0.) + if i < self.X.shape[1] - 1: ax.set_xticklabels('') - ax1.set_xticklabels('') # 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], # 1., 1. + .01 * self.X.shape[1]), loc=3, # ncol=self.X.shape[1], mode="expand", borderaxespad=0.) 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 def plot_X(self):