I am trying to vectorize the code for this Weighted Minkowski Distance.
I am aware that in Matlab both pdist and pdist2 suffice the purpose when Theta is equal to either 1 or scalar:
Mat = theta*(squareform(pdist(X,'minkowski',p)))
However in my implementation, which follows, Theta is a vector with the same dimension as the number of columns of X.
X = [1:5; 2:6; 3:7]';
n = length(X);
theta = [0.1 .7 .2];
Mat = zeros(n,n);
Mat = Mat+Mat'+eye(n);
In order to vectorize this, I made the following attempt, but I believe there is something wrong, as the results do not match
col = size(X,2);
M1 = bsxfun(@minus,X(:), X(:).');
M2 = theta.*abs(reshape(M1.',[3 col*n*n]).');
M3 = sum((M2(1:10,:)).^p,2)^(1/p);
Any help will be highly appreciated.