diff --git a/GPy/inference/latent_function_inference/var_dtc_gpu.py b/GPy/inference/latent_function_inference/var_dtc_gpu.py index a3fe0782..1089fc6c 100644 --- a/GPy/inference/latent_function_inference/var_dtc_gpu.py +++ b/GPy/inference/latent_function_inference/var_dtc_gpu.py @@ -10,9 +10,9 @@ from ...util.misc import param_to_array log_2_pi = np.log(2*np.pi) from ...util import gpu_init -assert gpu_init.initSuccess try: + import scikits.cuda.linalg as culinalg import pycuda.gpuarray as gpuarray from scikits.cuda import cublas from ...util.linalg_gpu import logDiagSum, strideSum, mul_bcast, sum_axis, outer_prod, mul_bcast_first, join_prod diff --git a/GPy/kern/_src/kern.py b/GPy/kern/_src/kern.py index dbe4c1f8..f871e676 100644 --- a/GPy/kern/_src/kern.py +++ b/GPy/kern/_src/kern.py @@ -13,7 +13,7 @@ class Kern(Parameterized): #=========================================================================== # This adds input slice support. The rather ugly code for slicing can be # found in kernel_slice_operations - __metaclass__ = KernCallsViaSlicerMeta + #__metaclass__ = KernCallsViaSlicerMeta #=========================================================================== _support_GPU=False def __init__(self, input_dim, active_dims, name, useGPU=False, *a, **kw): diff --git a/GPy/kern/_src/psi_comp/ssrbf_psi_gpucomp.py b/GPy/kern/_src/psi_comp/ssrbf_psi_gpucomp.py index 8d2f24bc..f49dc52a 100644 --- a/GPy/kern/_src/psi_comp/ssrbf_psi_gpucomp.py +++ b/GPy/kern/_src/psi_comp/ssrbf_psi_gpucomp.py @@ -9,7 +9,6 @@ import numpy as np from GPy.util.caching import Cache_this from ....util import gpu_init -assert gpu_init.initSuccess try: import pycuda.gpuarray as gpuarray @@ -257,6 +256,7 @@ except: class PSICOMP_SSRBF(object): def __init__(self): + assert gpu_init.initSuccess, "GPU initialization failed!" self.cublas_handle = gpu_init.cublas_handle self.gpuCache = None self.gpuCacheAll = None diff --git a/GPy/kern/_src/rbf.py b/GPy/kern/_src/rbf.py index e08d94f9..e0071fb9 100644 --- a/GPy/kern/_src/rbf.py +++ b/GPy/kern/_src/rbf.py @@ -11,9 +11,6 @@ from ...core.parameterization import variational from psi_comp import ssrbf_psi_comp from psi_comp.ssrbf_psi_gpucomp import PSICOMP_SSRBF -import pycuda.gpuarray as gpuarray -import pycuda.autoinit - class RBF(Stationary): """ Radial Basis Function kernel, aka squared-exponential, exponentiated quadratic or Gaussian kernel: diff --git a/GPy/models/ss_gplvm.py b/GPy/models/ss_gplvm.py index 55ee573c..57be302a 100644 --- a/GPy/models/ss_gplvm.py +++ b/GPy/models/ss_gplvm.py @@ -30,9 +30,12 @@ class SSGPLVM(SparseGP): def __init__(self, Y, input_dim, X=None, X_variance=None, init='PCA', num_inducing=10, Z=None, kernel=None, inference_method=None, likelihood=None, name='Spike-and-Slab GPLVM', group_spike=False, **kwargs): - if X == None: # The mean of variational approximation (mu) + if X == None: from ..util.initialization import initialize_latent - X = initialize_latent(init, input_dim, Y) + X, fracs = initialize_latent(init, input_dim, Y) + else: + fracs = np.ones(input_dim) + self.init = init if X_variance is None: # The variance of the variational approximation (S) @@ -52,7 +55,7 @@ class SSGPLVM(SparseGP): likelihood = Gaussian() if kernel is None: - kernel = kern.SSRBF(input_dim) + kernel = kern.RBF(input_dim, lengthscale=fracs, ARD=True) # + kern.white(input_dim) pi = np.empty((input_dim)) pi[:] = 0.5 diff --git a/GPy/plotting/matplot_dep/__init__.py b/GPy/plotting/matplot_dep/__init__.py index e2706903..f493513a 100644 --- a/GPy/plotting/matplot_dep/__init__.py +++ b/GPy/plotting/matplot_dep/__init__.py @@ -15,3 +15,5 @@ import latent_space_visualizations import netpbmfile import inference_plots import maps +import img_plots +from ssgplvm import SSGPLVM_plot diff --git a/GPy/plotting/matplot_dep/img_plots.py b/GPy/plotting/matplot_dep/img_plots.py new file mode 100644 index 00000000..fbaaa237 --- /dev/null +++ b/GPy/plotting/matplot_dep/img_plots.py @@ -0,0 +1,56 @@ +""" +The module contains the tools for ploting 2D image visualizations +""" + +import numpy as np +from matplotlib.cm import jet + +width_max = 15 +height_max = 12 + +def _calculateFigureSize(x_size, y_size, fig_ncols, fig_nrows, pad): + width = (x_size*fig_ncols+pad*(fig_ncols-1)) + height = (y_size*fig_nrows+pad*(fig_nrows-1)) + if width > float(height)/height_max*width_max: + return (width_max, float(width_max)/width*height) + else: + return (float(height_max)/height*width, height_max) + +def plot_2D_images(figure, arr, symmetric=False, pad=None, zoom=None, mode=None, interpolation='nearest'): + ax = figure.add_subplot(111) + if len(arr.shape)==2: + arr = arr.reshape(*((1,)+arr.shape)) + fig_num = arr.shape[0] + y_size = arr.shape[1] + x_size = arr.shape[2] + fig_ncols = int(np.ceil(np.sqrt(fig_num))) + fig_nrows = int(np.ceil((float)(fig_num)/fig_ncols)) + if pad==None: + pad = max(int(min(y_size,x_size)/10),1) + + figsize = _calculateFigureSize(x_size, y_size, fig_ncols, fig_nrows, pad) + figure.set_size_inches(figsize,forward=True) + #figure.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95) + + if symmetric: + # symmetric around zero: fix zero as the middle color + mval = max(abs(arr.max()),abs(arr.min())) + arr = arr/(2.*mval)+0.5 + else: + minval,maxval = arr.max(),arr.min() + arr = (arr-minval)/(maxval-minval) + + if mode=='L': + arr_color = np.empty(arr.shape+(3,)) + arr_color[:] = arr.reshape(*(arr.shape+(1,))) + elif mode==None or mode=='jet': + arr_color = jet(arr) + + buf = np.ones((y_size*fig_nrows+pad*(fig_nrows-1), x_size*fig_ncols+pad*(fig_ncols-1), 3),dtype=arr.dtype) + + for y in xrange(fig_nrows): + for x in xrange(fig_ncols): + if y*fig_ncols+x