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.m 3.1KB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. function [attAffinity] = CalcAttributesAffinity(data, attData, last_known_node, addMissingAtt, normalize, returnSparse)
  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. count = sum(attData,2);
  8. nnz_n = nnz(count);
  9. % fprintf('calculating attribtes affinity matrix - common start\n');
  10. common = attData*attData';
  11. [r,c,v] = find(common);
  12. clear('common');
  13. x=size(r,1);
  14. LogMsg(sprintf('attAffinity common (%d) - nnz=%6.5d, %7.5d%%, max %d, min %d, mean %7.5d',numAtt,x,100*x/(n*n),max(v),min(v),mean(v)));
  15. LogMsg(sprintf('attAffinity count (%d) - nnz=%6.5d, %7.5d%%, max %d, min %d, mean %7.5d',numAtt,nnz_n, 100*nnz_n/n, max(count),min(count),mean(count)));
  16. fprintf('calculating attribtes affinity matrix \n');
  17. % fprintf('calculating attribtes affinity matrix - loop start\n');
  18. attAffinity = zeros(n,n); %% Sigal 13.3.13 - TODO use sparse if x < 50%???
  19. for i=1:x
  20. total = count(r(i))+count(c(i))-v(i);
  21. if total > 0
  22. attAffinity(r(i),c(i)) = v(i)/total;
  23. end
  24. end
  25. % [r,c,v] = find(attAffinity);
  26. % x=size(r,1);
  27. % LogMsg(sprintf('attAffinity final -> nnz=%d, %d%%, max %d, min %d, mean %d',x,100*x/(n*n),max(v),min(v),mean(v)));
  28. % [r,c,v] = find(attAffinity>=0.02);
  29. % x=size(r,1);
  30. % LogMsg(sprintf('attAffinity 0.02 - nnz=%d, %d%%, max %d, min %d, mean %d',x,100*x/(n*n),max(v),min(v),mean(v)));
  31. % [r,c,v] = find(attAffinity>=0.05);
  32. % x=size(r,1);
  33. % LogMsg(sprintf('attAffinity 0.05 - nnz=%d, %d%%, max %d, min %d, mean %d',x,100*x/(n*n),max(v),min(v),mean(v)));
  34. % LogMsg(sprintf('==> attAffinity - max %d, min %d, mean %d',max(max(attAffinity)),min(min(attAffinity)),mean(mean(attAffinity))));
  35. % for i=1:n %% sigal 25.2.13 last_known_node
  36. % for j=1:i-1
  37. % if common(i,j)>0
  38. % total = count(i)+count(j)-common(i,j);
  39. % if total > 0
  40. % attAffinity(i,j) = common(i,j)/total;
  41. % attAffinity(j,i) = attAffinity(i,j);
  42. % end
  43. % end
  44. % end
  45. % % for k=last_known_node+1:n
  46. % % attAffinity(i,k) = 1;
  47. % % attAffinity(k,i) = 1;
  48. % % end
  49. % end
  50. % fprintf('calculating attribtes affinity matrix - loop end\n');
  51. % fprintf('calculating attribtes affinity matrix - normalize start\n');
  52. % if normalize == 1
  53. % maxValue = max(max(attAffinity));
  54. % if maxValue>0 && maxValue ~= 1
  55. % attAffinity = attAffinity ./ maxValue;
  56. % end
  57. % end
  58. % fprintf('calculating attribtes affinity matrix - normalize end max=%d\n',maxValue);
  59. %
  60. % for i = 1 : size(attAffinity,1)
  61. % attAffinity(i,i) = 1;
  62. % end
  63. % if returnSparse == 1
  64. % attAffinity = sparse(attAffinity);
  65. % end
  66. fprintf('calculating attribtes affinity matrix - end function\n');
  67. end %function