4

Referring to https://stats.stackexchange.com/questions/15798/how-to-calculate-a-gaussian-kernel-effectively-in-numpy , a solution is provided for calculating the precomputed kernel matrix.

from scipy.spatial.distance import pdist, squareform
X = loaddata() # this is an NxD matrix, where N is number of items and D its dimensions
pairwise_dists = squareform(pdist(X, 'euclidean'))
K = scip.exp(pairwise_dists / s**2)

How one can implement the above Guassin kernel, if the input is a weighted adjacency matrix for a directed graph?

1 Answer 1

2

If you already have your distance matrix, you could simply apply

K = scip.exp(YOUR_DISTANCE_HERE / s**2)

However, it may no longer be a kernel. Not all "similarity scores" are valid kernels. If your distances is a valid Mahalanobis distance then you have a guarantee, that everything will be ok. In case of "any" distance - anything can happen.

Usinig invalid kernel may lead to:

  1. Optimization process crash
  2. Finding suboptimal solutions (bad solutions)
  3. Doing anything, there are completely no guarantees.

Maybe you should consider graph kernels which are somewhat strongly related to the gaussian kernel and the heat diffusion

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.