% % % % % % C1 = [ 0.8147 0.1576; 0.9058 0.9706; 0.1270 0.9572; 0.9134 0.4854; 0.6324 0.8003; 0.0975 0.1419; 0.2785 0.4218; 0.5469 0.9157; 0.9575 0.7922; 0.9649 0.9595 ]; Q1 = [ 0.6557 0.7577; 0.0357 0.7431; 0.8491 0.3922; 0.9340 0.6555; 0.6787 0.1712 ]; C2 = [ 0.7060 0.4456 0.5060 0.6160; 0.0318 0.6463 0.6991 0.4733; 0.2769 0.7094 0.8909 0.3517; 0.0462 0.7547 0.9593 0.8308; 0.0971 0.2760 0.5472 0.5853; 0.8235 0.6797 0.1386 0.5497; 0.6948 0.6551 0.1493 0.9172; 0.3171 0.1626 0.2575 0.2858; 0.9502 0.1190 0.8407 0.7572; 0.0344 0.4984 0.2543 0.7537; 0.4387 0.9597 0.8143 0.3804; 0.3816 0.3404 0.2435 0.5678; 0.7655 0.5853 0.9293 0.0759; 0.7952 0.2238 0.3500 0.0540; 0.1869 0.7513 0.1966 0.5308; 0.4898 0.2551 0.2511 0.7792 ]; Q2 = [ 0.9340 0.3112 0.4505 0.0782; 0.1299 0.5285 0.0838 0.4427; 0.5688 0.1656 0.2290 0.1067; 0.4694 0.6020 0.9133 0.9619; 0.0119 0.2630 0.1524 0.0046; 0.3371 0.6541 0.8258 0.7749; 0.1622 0.6892 0.5383 0.8173; 0.7943 0.7482 0.9961 0.8687 ]; D1_exp = [ 0.6208 0.9745 0.2371 0.5120 0.1367; 0.3284 0.8993 0.5811 0.3164 0.8310; 0.5651 0.2327 0.9169 0.8616 0.9603; 0.3749 0.9147 0.1132 0.1713 0.3921; 0.0485 0.5994 0.4621 0.3346 0.6308; 0.8312 0.6044 0.7922 0.9815 0.5819; 0.5052 0.4028 0.5714 0.6959 0.4722; 0.1919 0.5395 0.6045 0.4665 0.7561; 0.3037 0.9231 0.4144 0.1387 0.6807; 0.3692 0.9540 0.5790 0.3056 0.8386 ]; D2_exp = [ 0.6020 0.7396 0.6583 0.6050 1.0070 0.5542 0.6298 0.6352; 1.0696 0.6348 0.9353 0.6914 0.8160 0.4475 0.4037 0.9145; 0.9268 0.8450 0.9376 0.6492 0.9671 0.4360 0.5956 0.7400; 1.3455 0.9876 1.2953 0.4709 1.2557 0.3402 0.4417 0.7500; 0.9839 0.5476 0.7517 0.7216 0.7074 0.5605 0.4784 0.9954; 0.6839 0.7200 0.7305 0.9495 1.0628 0.8718 0.8178 0.9179; 0.9850 0.7514 0.9585 0.7996 1.2054 0.7784 0.6680 0.8591; 0.6950 0.4730 0.3103 1.0504 0.4397 0.8967 0.8140 1.2066; 0.8065 1.2298 0.9722 0.7153 1.3933 0.8141 1.0204 0.6758; 1.1572 0.3686 0.9031 0.8232 0.7921 0.6656 0.3708 1.0970; 0.9432 0.9049 1.0320 0.6905 1.1167 0.5094 0.6455 0.6653; 0.7672 0.3740 0.5277 0.8247 0.6842 0.6945 0.5648 0.9968; 0.5768 1.1210 0.8403 0.9345 1.1316 0.8292 1.0380 0.8127; 0.1939 0.8703 0.2684 1.1794 0.8103 1.0683 1.1115 1.1646; 1.0106 0.2708 0.8184 0.8954 0.7402 0.6982 0.4509 1.0594; 0.8554 0.5878 0.6834 0.7699 0.9155 0.7161 0.6162 0.9481 ]; % tests D1 = dist2(C1, Q1); if norm (D1-pdist2(C1, Q1), 'fro') > 0.01 disp('Error in dist2(C1, Q1)'); end D2 = dist2(C2, Q2); if norm (D2-pdist2(C2, Q2), 'fro') > 0.01 disp('Error in dist2(C2, Q2)'); end D2 = dist2(C2, C2); if norm (D2-pdist2(C2, C2), 'fro') > 0.01 disp('Error in dist2(C2, C2)'); end %C = rand(10000, 2); % Corpus %Q = rand(10000, 2); % Queries C = rand(20000, 2); % Δύο clusters Q = C; %Q = rand(10000, 2); % Queries κοντά στο μέσο k = 100; % Number of neighbors m = 100; % Max candidates per query global count; count =0; tic; [pi, pd] = recursiveKNN(C, Q, k, m); toc count tic; [si, sd] = knnsearch(C, Q, 'k', k); toc [a,b] = size(si); all_neighbors = a*b accuracy = 1 - nnz(si-pi)/all_neighbors false_neighbors = nnz(sd-pd)