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.

CalcAttributesAffinity_S5.m 3.5KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. function [attAffinity] = CalcAttributesAffinity_S5(data, attData, last_known_node, addMissingAtt, threshold, reqNodesToKeep)
  2. n = size(attData,1);
  3. numAtt = size(attData,2);
  4. if addMissingAtt > 0 && last_known_node < n
  5. attData = AddMissingNodesAttrFromNeighborsNeighbors(data, attData, last_known_node, addMissingAtt);
  6. end
  7. percentSparse = 0.25; %%0.33;
  8. count = sum(attData,2);
  9. nnz_n = nnz(count);
  10. nnz_p = 100*nnz_n/n;
  11. LogMsg(sprintf('attAffinity count (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n, nnz_p));
  12. % fprintf('calculating attribtes affinity matrix - common start\n');
  13. % sigal - 12.6.13
  14. % calculate attribute affinity only for the nodesToKeep
  15. nodesWithAtt = (count > 0)';
  16. if nargin < 6
  17. reqNodesToKeep = (count > -1)'; % i.e. all
  18. percentSparse = 0.75; %%nnz_n/n;
  19. end
  20. %sigal - 27.10.13
  21. if nnz_p > 0.75
  22. percentSparse = 0.75;
  23. end
  24. nodesToKeep = reqNodesToKeep & nodesWithAtt;
  25. numNodesToKeep = full(sum(nodesToKeep));
  26. [rows,idxNodesToKeep] = find(nodesToKeep);
  27. LogMsg(sprintf('nodesToKeep (req, nnz, final) %d %d %d',full(sum(reqNodesToKeep)), full(sum(nodesWithAtt)), numNodesToKeep));
  28. % full calculation %common = sparse(attData*attData');
  29. % %Sigal - 16.6.13 - use full C implementation
  30. % common = sparse(n,n);
  31. % common(nodesToKeep,nodesToKeep) = attData(nodesToKeep,:)*attData(nodesToKeep,:)';
  32. % [r,c] = find(common);
  33. % %nnz_n=numNodesToKeep*numNodesToKeep/2;
  34. % nnz_n=size(r,1);%x=nnz(attAffinity);
  35. % perc_nnz = nnz_n/(n*n);
  36. % LogMsg(sprintf('attAffinity count (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,100*perc_nnz));
  37. % % Sigal 22.3.13 - TODO use sparse if x < 40%
  38. % if perc_nnz>0.4
  39. % LogMsg(sprintf('*** WARNING: attAffinity - use sparse for more than 40%% full matrix (n=%d,p=%.3f)',n,perc_nnz));
  40. % end
  41. % attAffinity = sparse(n,n);
  42. % for i=1:nnz_n
  43. % val = common(r(i),c(i));
  44. % total = count(r(i))+count(c(i))-val;
  45. % % if (c(i)<31 && r(i)<31)
  46. % % fprintf('(i,j)=(%d,%d): common=%f, total=%f\n',full(r(i))-1,full(c(i))-1,full(val),full(total));
  47. % % end
  48. % if total > 0 && val/total > threshold
  49. % attAffinity(r(i),c(i)) = val/total;
  50. % end
  51. % end
  52. %
  53. % nnz_n = nnz(attAffinity);
  54. % LogMsg(sprintf('attAffinity totalM (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,100*nnz_n/(n*n)));
  55. %Sigal - 16.6.13 - use full C implementation
  56. % attAffinity = AttributesSimilarity(common,count,threshold);
  57. % clear('common');
  58. clear('count');
  59. attAffinity = AttributesSimilarity5(logical(attData'),idxNodesToKeep',threshold, percentSparse);
  60. nnz_n = nnz(attAffinity);
  61. LogMsg(sprintf('attAffinity totalC (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,100*nnz_n/(n*n)));
  62. % %debuging
  63. % debugMex = 1;
  64. % if debugMex
  65. % % attAffinity2 = AttributesSimilarity5a(attData,idxNodesToKeep',threshold);
  66. % attAffinity2 = AttributesSimilarity5(logical(attData'),idxNodesToKeep',threshold);
  67. % aff3 = attAffinity - attAffinity2;
  68. % nnz_a3 = nnz(aff3);
  69. % fprintf('diff affinity nnz_a3 %d \n',nnz_a3);
  70. %
  71. % clear('attAffinity2');
  72. % clear('aff3');
  73. % end
  74. % diff = attAffinityC-attAffinity;
  75. % nnz_n = nnz(diff);
  76. % LogMsg(sprintf('attAffinity diff (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,100*nnz_n/(n*n)));
  77. end %function