Files
2026-07-13 13:30:25 +08:00

10 lines
271 B
Matlab
Executable File

function D = kn2sd(K)
% Transform a kernel matrix (or inner product matrix) to a squared distance matrix
% Input:
% K: n x n kernel matrix
% Ouput:
% D: n x n squared distance matrix
% Written by Mo Chen (sth4nth@gmail.com).
d = diag(K);
D = -2*K+bsxfun(@plus,d,d');