k2d
provides various methods for converting kernel matrix to distance matrix and vice versa.
k2d(Mat, direction = "k2d", method = "norm", scale = 1, pos = TRUE)
TRUE
when direction="d2k"
, negative eigenvalues are round to zero to obtain positive semidefinite kernel matrix. Default TRUE
.method="norm"
) means a conversion
d_ND(x,y) = sqrt k(x,x) - 2k(x,y) + k(y,y).Cauchy-Schwarz-type conversion (method="CS"
) is more principled way:
d_CS(x,y) = arccos k^2(x,y)/k(x,x)k(y,y).
Other two simple ways are
d_exp(x,y) = exp(- k(x,y)/scale),
which is an exponential-type distance (method="exp"
), and
d_n(x,y) = 1 - k(x,y)/sqrt k(x,x)k(y,y),
which we call naive (method="naive"
).
For converting distance to kernel (direction="d2k"
), it should be noted that we usually have distance between pairs of points only, and distances from "origin" are unknown.
Double-centering (method="DC"
) is the most popular and simple way to convert distance to kernel. However, it does not make positive definite kernel in general,
and it sometimes require post-processing, e.g., cutting off negative eigenvalues (pos=TRUE
).
Another simple way is exponential map (method="exp"
), i.e., k(x,y) = exp( - d(x,y)/scale).