AUTH's THMMY "Parallel and distributed systems" course assignments.
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.

run_test.m 4.0 KiB

3 dagen geleden
3 dagen geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. %
  2. %
  3. %
  4. %
  5. %
  6. %
  7. C1 = [
  8. 0.8147 0.1576;
  9. 0.9058 0.9706;
  10. 0.1270 0.9572;
  11. 0.9134 0.4854;
  12. 0.6324 0.8003;
  13. 0.0975 0.1419;
  14. 0.2785 0.4218;
  15. 0.5469 0.9157;
  16. 0.9575 0.7922;
  17. 0.9649 0.9595 ];
  18. Q1 = [
  19. 0.6557 0.7577;
  20. 0.0357 0.7431;
  21. 0.8491 0.3922;
  22. 0.9340 0.6555;
  23. 0.6787 0.1712 ];
  24. C2 = [
  25. 0.7060 0.4456 0.5060 0.6160;
  26. 0.0318 0.6463 0.6991 0.4733;
  27. 0.2769 0.7094 0.8909 0.3517;
  28. 0.0462 0.7547 0.9593 0.8308;
  29. 0.0971 0.2760 0.5472 0.5853;
  30. 0.8235 0.6797 0.1386 0.5497;
  31. 0.6948 0.6551 0.1493 0.9172;
  32. 0.3171 0.1626 0.2575 0.2858;
  33. 0.9502 0.1190 0.8407 0.7572;
  34. 0.0344 0.4984 0.2543 0.7537;
  35. 0.4387 0.9597 0.8143 0.3804;
  36. 0.3816 0.3404 0.2435 0.5678;
  37. 0.7655 0.5853 0.9293 0.0759;
  38. 0.7952 0.2238 0.3500 0.0540;
  39. 0.1869 0.7513 0.1966 0.5308;
  40. 0.4898 0.2551 0.2511 0.7792 ];
  41. Q2 = [
  42. 0.9340 0.3112 0.4505 0.0782;
  43. 0.1299 0.5285 0.0838 0.4427;
  44. 0.5688 0.1656 0.2290 0.1067;
  45. 0.4694 0.6020 0.9133 0.9619;
  46. 0.0119 0.2630 0.1524 0.0046;
  47. 0.3371 0.6541 0.8258 0.7749;
  48. 0.1622 0.6892 0.5383 0.8173;
  49. 0.7943 0.7482 0.9961 0.8687 ];
  50. D1_exp = [
  51. 0.6208 0.9745 0.2371 0.5120 0.1367;
  52. 0.3284 0.8993 0.5811 0.3164 0.8310;
  53. 0.5651 0.2327 0.9169 0.8616 0.9603;
  54. 0.3749 0.9147 0.1132 0.1713 0.3921;
  55. 0.0485 0.5994 0.4621 0.3346 0.6308;
  56. 0.8312 0.6044 0.7922 0.9815 0.5819;
  57. 0.5052 0.4028 0.5714 0.6959 0.4722;
  58. 0.1919 0.5395 0.6045 0.4665 0.7561;
  59. 0.3037 0.9231 0.4144 0.1387 0.6807;
  60. 0.3692 0.9540 0.5790 0.3056 0.8386 ];
  61. D2_exp = [
  62. 0.6020 0.7396 0.6583 0.6050 1.0070 0.5542 0.6298 0.6352;
  63. 1.0696 0.6348 0.9353 0.6914 0.8160 0.4475 0.4037 0.9145;
  64. 0.9268 0.8450 0.9376 0.6492 0.9671 0.4360 0.5956 0.7400;
  65. 1.3455 0.9876 1.2953 0.4709 1.2557 0.3402 0.4417 0.7500;
  66. 0.9839 0.5476 0.7517 0.7216 0.7074 0.5605 0.4784 0.9954;
  67. 0.6839 0.7200 0.7305 0.9495 1.0628 0.8718 0.8178 0.9179;
  68. 0.9850 0.7514 0.9585 0.7996 1.2054 0.7784 0.6680 0.8591;
  69. 0.6950 0.4730 0.3103 1.0504 0.4397 0.8967 0.8140 1.2066;
  70. 0.8065 1.2298 0.9722 0.7153 1.3933 0.8141 1.0204 0.6758;
  71. 1.1572 0.3686 0.9031 0.8232 0.7921 0.6656 0.3708 1.0970;
  72. 0.9432 0.9049 1.0320 0.6905 1.1167 0.5094 0.6455 0.6653;
  73. 0.7672 0.3740 0.5277 0.8247 0.6842 0.6945 0.5648 0.9968;
  74. 0.5768 1.1210 0.8403 0.9345 1.1316 0.8292 1.0380 0.8127;
  75. 0.1939 0.8703 0.2684 1.1794 0.8103 1.0683 1.1115 1.1646;
  76. 1.0106 0.2708 0.8184 0.8954 0.7402 0.6982 0.4509 1.0594;
  77. 0.8554 0.5878 0.6834 0.7699 0.9155 0.7161 0.6162 0.9481 ];
  78. % tests
  79. D1 = dist2(C1, Q1);
  80. if norm (D1-pdist2(C1, Q1), 'fro') > 0.01
  81. disp('Error in dist2(C1, Q1)');
  82. end
  83. D2 = dist2(C2, Q2);
  84. if norm (D2-pdist2(C2, Q2), 'fro') > 0.01
  85. disp('Error in dist2(C2, Q2)');
  86. end
  87. D2 = dist2(C2, C2);
  88. if norm (D2-pdist2(C2, C2), 'fro') > 0.01
  89. disp('Error in dist2(C2, C2)');
  90. end
  91. %C = rand(10000, 2); % Corpus
  92. %Q = rand(10000, 2); % Queries
  93. C = rand(20000, 2); % Δύο clusters
  94. Q = C;
  95. %Q = rand(10000, 2); % Queries κοντά στο μέσο
  96. k = 100; % Number of neighbors
  97. m = 100; % Max candidates per query
  98. global count;
  99. count =0;
  100. tic; [pi, pd] = recursiveKNN(C, Q, k, m); toc
  101. count
  102. tic; [si, sd] = knnsearch(C, Q, 'k', k); toc
  103. [a,b] = size(si);
  104. all_neighbors = a*b
  105. accuracy = 1 - nnz(si-pi)/all_neighbors
  106. false_neighbors = nnz(sd-pd)