mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-21 14:05:14 +02:00
merged
This commit is contained in:
commit
ba1d6697e5
14 changed files with 356 additions and 122 deletions
|
|
@ -20,7 +20,7 @@ class RBF(Stationary):
|
|||
|
||||
"""
|
||||
|
||||
def __init__(self, input_dim, variance=1., lengthscale=None, ARD=False, name='RBF'):
|
||||
def __init__(self, input_dim, variance=1., lengthscale=None, ARD=False, name='rbf'):
|
||||
super(RBF, self).__init__(input_dim, variance, lengthscale, ARD, name)
|
||||
self.weave_options = {}
|
||||
|
||||
|
|
@ -159,7 +159,7 @@ class RBF(Stationary):
|
|||
grad_mu = np.sum(dL_dpsi1[:, :, None] * tmp * dist, 1)
|
||||
grad_S = np.sum(dL_dpsi1[:, :, None] * 0.5 * tmp * (dist_sq - 1), 1)
|
||||
#psi2
|
||||
denom, Zdist, Zdist_sq, mudist, mudist_sq, psi2 = self._psi2computations(Z, variational_posterior)
|
||||
denom, _, _, mudist, mudist_sq, psi2 = self._psi2computations(Z, variational_posterior)
|
||||
tmp = psi2[:, :, :, None] / l2 / denom
|
||||
grad_mu += -2.*(dL_dpsi2[:, :, :, None] * tmp * mudist).sum(1).sum(1)
|
||||
grad_S += (dL_dpsi2[:, :, :, None] * tmp * (2.*mudist_sq - 1)).sum(1).sum(1)
|
||||
|
|
@ -237,7 +237,7 @@ class RBF(Stationary):
|
|||
return denom, dist, dist_sq, psi1
|
||||
|
||||
|
||||
#@cache_this(ignore_args=(1,))
|
||||
@Cache_this(limit=1, ignore_args=(0,))
|
||||
def _Z_distances(self, Z):
|
||||
Zhat = 0.5 * (Z[:, None, :] + Z[None, :, :]) # M,M,Q
|
||||
Zdist = 0.5 * (Z[:, None, :] - Z[None, :, :]) # M,M,Q
|
||||
|
|
@ -257,7 +257,6 @@ class RBF(Stationary):
|
|||
#allocate memory for the things we want to compute
|
||||
mudist = np.empty((N, M, M, Q))
|
||||
mudist_sq = np.empty((N, M, M, Q))
|
||||
exponent = np.zeros((N,M,M))
|
||||
psi2 = np.empty((N, M, M))
|
||||
|
||||
l2 = self.lengthscale **2
|
||||
|
|
|
|||
|
|
@ -69,12 +69,12 @@ class Stationary(Kern):
|
|||
def dK_dr(self, r):
|
||||
raise NotImplementedError, "implement derivative of the covariance function wrt r to use this class"
|
||||
|
||||
#@Cache_this(limit=5, ignore_args=())
|
||||
@Cache_this(limit=5, ignore_args=())
|
||||
def K(self, X, X2=None):
|
||||
r = self._scaled_dist(X, X2)
|
||||
return self.K_of_r(r)
|
||||
|
||||
#@Cache_this(limit=5, ignore_args=(0,))
|
||||
@Cache_this(limit=5, ignore_args=(0,))
|
||||
def _unscaled_dist(self, X, X2=None):
|
||||
"""
|
||||
Compute the Euclidean distance between each row of X and X2, or between
|
||||
|
|
@ -88,7 +88,7 @@ class Stationary(Kern):
|
|||
X2sq = np.sum(np.square(X2),1)
|
||||
return np.sqrt(-2.*np.dot(X, X2.T) + (X1sq[:,None] + X2sq[None,:]))
|
||||
|
||||
#@Cache_this(limit=5, ignore_args=())
|
||||
@Cache_this(limit=5, ignore_args=())
|
||||
def _scaled_dist(self, X, X2=None):
|
||||
"""
|
||||
Efficiently compute the scaled distance, r.
|
||||
|
|
@ -141,7 +141,7 @@ class Stationary(Kern):
|
|||
diagonal, where we return zero (the distance on the diagonal is zero).
|
||||
This term appears in derviatives.
|
||||
"""
|
||||
dist = self._scaled_dist(X, X2)
|
||||
dist = self._scaled_dist(X, X2).copy()
|
||||
if X2 is None:
|
||||
nondiag = util.diag.offdiag_view(dist)
|
||||
nondiag[:] = 1./nondiag
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue