AUTH's THMMY "Parallel and distributed systems" course assignments.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

25 lignes
810 B

  1. function [idx, dst] = knnsearch2(C, Q, k)
  2. % C: Is a mxd matrix (Corpus)
  3. % Q: Is a nxd matrix (Query)
  4. % k: The number of nearest neighbors needded
  5. % Calculate the distance matrix between C and Q
  6. % D is an m x n matrix where each element D(i, j) is the distance
  7. % between the i-th point in C and the j-th point in Q.
  8. % k is the number of nearest neighbors to find.
  9. D = dist2(C, Q);
  10. % Find the k-nearest neighbors for each query point in Q
  11. % [~,n] = size(D);
  12. % for j = 1:n
  13. % [dst(:, j), idx(:, j)] = mink(D(:, j), k);
  14. % end
  15. [dst, idx] = mink(D, k, 1); % mink along dimension 1 for each query point
  16. % Transpose the output to match the knnsearch format
  17. idx = idx'; % Make idx an n x k matrix
  18. dst = dst'; % Make dst an n x k matrix
  19. end