From 0f6004034e0a9fb17c4f5311a36038cd6249eb37 Mon Sep 17 00:00:00 2001 From: Zhenwen Dai Date: Mon, 3 Mar 2014 17:56:47 +0000 Subject: [PATCH] [SSGPLVM] support non-ARD rbf --- GPy/kern/_src/rbf.py | 11 ++++++++--- GPy/kern/_src/rbf_psi_comp/ssrbf_psi_comp.py | 14 ++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/GPy/kern/_src/rbf.py b/GPy/kern/_src/rbf.py index 007bac77..498ab0ac 100644 --- a/GPy/kern/_src/rbf.py +++ b/GPy/kern/_src/rbf.py @@ -62,13 +62,18 @@ class RBF(Stationary): #from psi1 self.variance.gradient += np.sum(dL_dpsi1 * _dpsi1_dvariance) - self.lengthscale.gradient = (dL_dpsi1[:,:,None]*_dpsi1_dlengthscale).reshape(-1,self.input_dim).sum(axis=0) + if self.ARD: + self.lengthscale.gradient = (dL_dpsi1[:,:,None]*_dpsi1_dlengthscale).reshape(-1,self.input_dim).sum(axis=0) + else: + self.lengthscale.gradient = (dL_dpsi1[:,:,None]*_dpsi1_dlengthscale).sum() #from psi2 self.variance.gradient += (dL_dpsi2 * _dpsi2_dvariance).sum() - self.lengthscale.gradient += (dL_dpsi2[:,:,:,None] * _dpsi2_dlengthscale).reshape(-1,self.input_dim).sum(axis=0) - return + if self.ARD: + self.lengthscale.gradient += (dL_dpsi2[:,:,:,None] * _dpsi2_dlengthscale).reshape(-1,self.input_dim).sum(axis=0) + else: + self.lengthscale.gradient += (dL_dpsi2[:,:,:,None] * _dpsi2_dlengthscale).sum() elif isinstance(variational_posterior, variational.NormalPosterior): diff --git a/GPy/kern/_src/rbf_psi_comp/ssrbf_psi_comp.py b/GPy/kern/_src/rbf_psi_comp/ssrbf_psi_comp.py index f3d5ee6b..13b3f65f 100644 --- a/GPy/kern/_src/rbf_psi_comp/ssrbf_psi_comp.py +++ b/GPy/kern/_src/rbf_psi_comp/ssrbf_psi_comp.py @@ -6,22 +6,15 @@ The package for the psi statistics computation """ import numpy as np +from GPy.util.caching import Cache_this +@Cache_this(limit=1) def _Z_distances(Z): Zhat = 0.5 * (Z[:, None, :] + Z[None, :, :]) # M,M,Q Zdist = 0.5 * (Z[:, None, :] - Z[None, :, :]) # M,M,Q return Zhat, Zdist -# def _psi1computations(self, Z, vp): -# mu, S = vp.mean, vp.variance -# l2 = lengthscale **2 -# denom = S[:, None, :] / l2 + 1. # N,1,Q -# dist = Z[None, :, :] - mu[:, None, :] # N,M,Q -# dist_sq = np.square(dist) / l2 / denom # N,M,Q -# exponent = -0.5 * np.sum(dist_sq + np.log(denom), -1)#N,M -# psi1 = self.variance * np.exp(exponent) # N,M -# return denom, dist, dist_sq, psi1 - +@Cache_this(limit=1) def _psi1computations(variance, lengthscale, Z, mu, S, gamma): """ Z - MxQ @@ -64,6 +57,7 @@ def _psi1computations(variance, lengthscale, Z, mu, S, gamma): return _psi1, _dpsi1_dvariance, _dpsi1_dgamma, _dpsi1_dmu, _dpsi1_dS, _dpsi1_dZ, _dpsi1_dlengthscale +@Cache_this(limit=1) def _psi2computations(variance, lengthscale, Z, mu, S, gamma): """ Z - MxQ