From 0909ec30bc884cf70d591a6eb5930d71ea22dc61 Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Wed, 17 Jul 2013 17:43:45 +0100 Subject: [PATCH 1/4] BGPLVM example correction --- GPy/examples/dimensionality_reduction.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/GPy/examples/dimensionality_reduction.py b/GPy/examples/dimensionality_reduction.py index 5e0c77cb..08fdfa8d 100644 --- a/GPy/examples/dimensionality_reduction.py +++ b/GPy/examples/dimensionality_reduction.py @@ -24,7 +24,7 @@ def BGPLVM(seed=default_seed): Y = np.random.multivariate_normal(np.zeros(N), K, Q).T lik = Gaussian(Y, normalize=True) - k = GPy.kern.rbf_inv(Q, ARD=True) + GPy.kern.bias(Q) + GPy.kern.white(Q) + k = GPy.kern.rbf(Q, ARD=True) + GPy.kern.bias(Q) + GPy.kern.white(Q) # k = GPy.kern.rbf(Q) + GPy.kern.bias(Q) + GPy.kern.white(Q, 0.00001) # k = GPy.kern.rbf(Q, ARD = False) + GPy.kern.white(Q, 0.00001) @@ -145,7 +145,6 @@ def BGPLVM_oil(optimize=True, N=200, Q=10, num_inducing=15, max_iters=150, plot= # create simple GP model kernel = GPy.kern.rbf_inv(Q, ARD=True) + GPy.kern.bias(Q, np.exp(-2)) + GPy.kern.white(Q, np.exp(-2)) - kernel += GPy.kern.rbf_inv(Q, ARD=True) + GPy.kern.bias(Q, np.exp(-2)) + GPy.kern.white(Q, np.exp(-2)) Y = data['X'][:N] Yn = Y - Y.mean(0) Yn /= Yn.std(0) From a4170abceb1138ce26318d11f855996dbbff62c4 Mon Sep 17 00:00:00 2001 From: Nicolo Fusi Date: Wed, 17 Jul 2013 17:44:04 +0100 Subject: [PATCH 2/4] fast_array_equals now handles 3d matrices --- GPy/util/misc.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/GPy/util/misc.py b/GPy/util/misc.py index f931ae6a..0914adb8 100644 --- a/GPy/util/misc.py +++ b/GPy/util/misc.py @@ -59,7 +59,7 @@ def kmm_init(X, m = 10): return X[inducing] def fast_array_equal(A, B): - code=""" + code2=""" int i, j; return_val = 1; @@ -74,6 +74,23 @@ def fast_array_equal(A, B): } """ + code3=""" + int i, j, z; + return_val = 1; + + #pragma omp parallel for private(i, j, z) + for(i=0;i #include @@ -93,9 +110,14 @@ def fast_array_equal(A, B): elif A.shape == B.shape: if len(A.shape) == 2: N, D = A.shape - value = weave.inline(code, support_code=support_code, libraries=['gomp'], + value = weave.inline(code2, support_code=support_code, libraries=['gomp'], arg_names=['A', 'B', 'N', 'D'], type_converters=weave.converters.blitz,**weave_options) + elif len(A.shape) == 3: + N, D, Q = A.shape + value = weave.inline(code3, support_code=support_code, libraries=['gomp'], + arg_names=['A', 'B', 'N', 'D', 'Q'], + type_converters=weave.converters.blitz,**weave_options) else: value = np.array_equal(A,B) From 06d540f056c6b1489c904a80683d96055ebc8629 Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Wed, 17 Jul 2013 17:49:50 +0100 Subject: [PATCH 3/4] plot_ARD greatly improved, crossterm plotting enabled --- GPy/kern/kern.py | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/GPy/kern/kern.py b/GPy/kern/kern.py index 5cd90749..491f9ed7 100644 --- a/GPy/kern/kern.py +++ b/GPy/kern/kern.py @@ -66,12 +66,26 @@ class kern(Parameterized): Parameterized.setstate(self, state) - def plot_ARD(self, fignum=None, ax=None, title=None): - """If an ARD kernel is present, it bar-plots the ARD parameters""" + def plot_ARD(self, fignum=None, ax=None, title='', legend=False): + """If an ARD kernel is present, it bar-plots the ARD parameters, + :param fignum: figure number of the plot + :param ax: matplotlib axis to plot on + :param title: + title of the plot, + pass '' to not print a title + pass None for a generic title + """ if ax is None: fig = pb.figure(fignum) ax = fig.add_subplot(111) + from GPy.util import Tango + from matplotlib.textpath import TextPath + Tango.reset() + xticklabels = [] + bars = [] + x0 = 0 for p in self.parts: + c = Tango.nextMedium() if hasattr(p, 'ARD') and p.ARD: if title is None: ax.set_title('ARD parameters, %s kernel' % p.name) @@ -82,10 +96,32 @@ class kern(Parameterized): else: ard_params = 1. / p.lengthscale - x = np.arange(len(ard_params)) - ax.bar(x - 0.4, ard_params) - ax.set_xticks(x) - ax.set_xticklabels([r"${}$".format(i) for i in x]) + x = np.arange(x0, x0 + len(ard_params)) + bars.append(ax.bar(x, ard_params, align='center', color=c, edgecolor='k', linewidth=1.2, label=p.name)) + xticklabels.extend([r"$\mathrm{{{name}}}\ {x}$".format(name=p.name, x=i) for i in np.arange(len(ard_params))]) + x0 += len(ard_params) + x = np.arange(x0) + for bar in bars: + for patch, num in zip(bar.patches, np.arange(len(bar.patches))): + height = patch.get_height() + xi = patch.get_x() + patch.get_width() / 2. + va = 'top' + c = 'w' + t = TextPath((0, 0), "${xi}$".format(xi=xi), rotation=0, usetex=True, ha='center') + if patch.get_extents().height <= t.get_extents().height + 2: + va = 'bottom' + c = 'k' + ax.text(xi, height, "${xi}$".format(xi=int(num)), color=c, rotation=0, ha='center', va=va) + # for xi, t in zip(x, xticklabels): + # ax.text(xi, maxi / 2, t, rotation=90, ha='center', va='center') + # ax.set_xticklabels(xticklabels, rotation=17) + ax.set_xticks([]) + ax.set_xlim(-.5, x0 - .5) + if title is '': + ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, + ncol=len(bars), mode="expand", borderaxespad=0.) + else: + ax.legend() return ax def _transform_gradients(self, g): From a65c5a94193ade67be99393e79d6a71556a73767 Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Wed, 17 Jul 2013 17:50:11 +0100 Subject: [PATCH 4/4] plot_ARD greatly improved, crossterm plotting enabled --- GPy/kern/kern.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPy/kern/kern.py b/GPy/kern/kern.py index 491f9ed7..a09a94f3 100644 --- a/GPy/kern/kern.py +++ b/GPy/kern/kern.py @@ -119,7 +119,7 @@ class kern(Parameterized): ax.set_xlim(-.5, x0 - .5) if title is '': ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, - ncol=len(bars), mode="expand", borderaxespad=0.) + ncol=max(2, len(bars)), mode="expand", borderaxespad=0.) else: ax.legend() return ax