AUTH's THMMY "Parallel and distributed systems" course assignments.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728
  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. % idx: Is the Nxk matrix with the k indexes of the C points, that are
  6. % neighbors of the nth point of Q
  7. % dst: Is the Nxk matrix with the k distances to the C points of the nth
  8. % point of Q
  9. %
  10. % Calculate the distance matrix between C and Q
  11. % D is an m x n matrix where each element D(i, j) is the distance
  12. % between the i-th point in C and the j-th point in Q.
  13. % k is the number of nearest neighbors to find.
  14. D = dist2(C, Q);
  15. % Find the k-nearest neighbors for each query point in Q
  16. % [~,n] = size(D);
  17. % for j = 1:n
  18. % [dst(:, j), idx(:, j)] = mink(D(:, j), k);
  19. % end
  20. [dst, idx] = mink(D, k, 1); % mink along dimension 1 for each query point
  21. % Transpose the output to match the knnsearch format
  22. idx = idx'; % Make idx an n x k matrix
  23. dst = dst'; % Make dst an n x k matrix
  24. end