Parallel and distributed systems exercise 2: ditributed all-kNN algorithm.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

19 lines
720 B

  1. function D = distXY(X, Y)
  2. %distXY Calculate an m x n Euclidean distance matrix 𝐷 of X and Y
  3. %
  4. % Calculate an m x n Euclidean distance matrix 𝐷 between two sets points 𝑋 and 𝑌 of 𝑚 and 𝑛 points respectively
  5. % X : [m x d] Corpus data points (d dimensions)
  6. % Y : [n x d] Query data poinsts (d dimensions)
  7. % D : [m x n] Distance matrix where D(i,j) the distance of X(i) and Y(j)
  8. [m d1] = size(X);
  9. [n d2] = size(Y);
  10. if d1 == d2
  11. d = d1;
  12. else
  13. error('Corpus(X) and Query(Y) data points have to have the same dimensions');
  14. end
  15. %D = (X.*X) * ones(d,1)*ones(1,n) -2 * X*Y.' + ones(m,1)*ones(1,d) * (Y.*Y).';
  16. D = sum(X.^2, 2) - 2 * X*Y.' + sum(Y.^2, 2).'
  17. end