Skip to content

Commit

Permalink
fizxed a numerical bug in stationary.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshensman committed Aug 8, 2014
1 parent ece85f0 commit df8bad0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions GPy/kern/_src/rbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def K_of_r(self, r):
def dK_dr(self, r):
return -r*self.K_of_r(r)

def spectrum(self, omega):
assert self.input_dim == 1 #TODO: higher dim spectra?
return self.variance*np.sqrt(2*np.pi)*self.lengthscale*np.exp(-self.lengthscale*2*omega**2/2)

#---------------------------------------#
# PSI statistics #
#---------------------------------------#
Expand Down
3 changes: 2 additions & 1 deletion GPy/kern/_src/stationary.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ def _unscaled_dist(self, X, X2=None):
Xsq = np.sum(np.square(X),1)
r2 = -2.*tdot(X) + (Xsq[:,None] + Xsq[None,:])
util.diag.view(r2)[:,]= 0. # force diagnoal to be zero: sometime numerically a little negative
r2 = np.clip(r2, 0, np.inf)
return np.sqrt(r2)
else:
#X2, = self._slice_X(X2)
X1sq = np.sum(np.square(X),1)
X2sq = np.sum(np.square(X2),1)
r2 = -2.*np.dot(X, X2.T) + X1sq[:,None] + X2sq[None,:]
r2[r2<0] = 0. # A bit hacky
r2 = np.clip(r2, 0, np.inf)
return np.sqrt(r2)

@Cache_this(limit=5, ignore_args=())
Expand Down

0 comments on commit df8bad0

Please sign in to comment.