Does anyone know how Matlab’s Z=dist(W,P)
works? The Matlab documentation does not specify an algorithm that uses the weight matrix, W.
I am using Octave and trying to mimic the behavior. So far, this stack overflow post helped me to prove that Octave’s Z=squareform(pdist(P'))
is equivalent to Matlab’s Z=dist(P)
. I can also designate the elements of Z using a couple of for loops:
function z=dist(w,p)
for i=1:size(p,2)
for j=1:size(p,2)
u=p(:,i);
v=p(:,j);
z(i,j)=sum((u-v).^2).^0.5;
end
end
end
However, I am unable to find any online documentation on the weight matrix, W. I cannot simply multiply the output of squareform(pdist(P'))
by W because the dimensions do not match. I have attempted to premultiply W, e.g. sqrt(W*(P(:,1)-P(:,2)).^2)
, like this stack overflow post but the output magnitudes are wrong.
Here is an example using Matlab:
P=
9 7 10
10 1 10
2 3 2
10 6 10
W=
10 9 5 8
5 2 10 10
>> D = dist(P)
0 10.0995 1.0000
10.0995 0 10.3441
1.0000 10.3441 0
>> D = dist(W,P)
3.8730 9.0000 3.7417
12.0000 8.3666 12.3693
Thanks in advance for any help you can provide!