I would like to compute a kernel matrix in python in the fastest way as possible: the input is a matrix X= nsamples, nfeatues and the output should be a symmetric matrix D =nsamples, nsapmles
the method which I'm using right now, even though is based on iterators seems to be really slow do to the for loop... can anybody think to something better?
Thanks
my method so far is:
from itertools import combinations
def computeKernel(X,dlambda):
nsamples=X.shape[0]
D=numpy.zeros((nsamples,nsamples))
for el in combinations(range(nsamples),2):
i,j=el
D[el]=quadraticChiDist(X[i,:],X[j,:])
D=D+D.T
D=numpy.exp(-dlambda*D/255)
D=numpy.eye(D)+D
return D
where quadraticChiDist is the function that is evaluated for every possible pair of rows in X