pdist2(X,Y, dist_func)
unfortunately computes dist_func(X, Y(i,:))
, instead of dist_func(X(i,:), Y(i,:))
. So the actual function I need is,
function K=compute_kernel( k_func, X, Y )
% Woohoo! Efficient way to compute kernel
size(X)
size(Y)
m = size(X,1);
n = size(Y,1);
for i = 1:n
K(:,i) = pdist2( Y(i,:), X, k_func);
end
It's not as nice as just using pdist2
, but is still much more efficient than the previous case.