Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions spearmint/kernels/kernel_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,33 +210,7 @@ def dist2(ls, x1, x2=None):
def grad_dist2(ls, x1, x2=None):
if x2 is None:
x2 = x1

# Rescale.
x1 = x1 / ls
x2 = x2 / ls

N = x1.shape[0]
M = x2.shape[0]
D = x1.shape[1]
gX = np.zeros((x1.shape[0],x2.shape[0],x1.shape[1]))

code = \
"""
for (int i=0; i<N; i++)
for (int j=0; j<M; j++)
for (int d=0; d<D; d++)
gX(i,j,d) = (2/ls(d))*(x1(i,d) - x2(j,d));
"""
try:
scipy.weave.inline(code, ['x1','x2','gX','ls','M','N','D'], \
type_converters=scipy.weave.converters.blitz, \
compiler='gcc')
except:
# The C code weave above is 10x faster than this:
for i in xrange(0,x1.shape[0]):
gX[i,:,:] = 2*(x1[i,:] - x2[:,:])*(1/ls)

return gX
return (x1 * 2/ls**2)[:, np.newaxis, :] - (x2 * 2/ls**2)[np.newaxis, :, :]

def dist_Mahalanobis(U, x1, x2=None):
W = np.dot(U,U.T)
Expand Down