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_S3.m 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. function [attAffinity] = CalcAttributesAffinity_S3(data, attData, last_known_node, addMissingAtt, threshold)
  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. LogMsg(sprintf('attAffinity count (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n, 100*nnz_n/n));
  10. % fprintf('calculating attribtes affinity matrix - common start\n');
  11. common = sparse(attData*attData');
  12. [r,c] = find(common);
  13. nnz_n=size(r,1);%x=nnz(attAffinity);
  14. perc_nnz = nnz_n/(n*n);
  15. LogMsg(sprintf('attAffinity common (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,100*perc_nnz));
  16. % Sigal 22.3.13 - TODO use sparse if x < 40%
  17. if perc_nnz>0.4
  18. LogMsg(sprintf('*** WARNING: attAffinity - use sparse for more than 40%% full matrix (n=%d,p=%.3f)',n,perc_nnz));
  19. end
  20. % attAffinity = sparse(n,n);
  21. % for i=1:nnz_n
  22. % val = common(r(i),c(i));
  23. % total = count(r(i))+count(c(i))-val;
  24. % % if (c(i)<31 && r(i)<31)
  25. % % fprintf('(i,j)=(%d,%d): common=%f, total=%f\n',full(r(i))-1,full(c(i))-1,full(val),full(total));
  26. % % end
  27. % if total > 0 && val/total > threshold
  28. % attAffinity(r(i),c(i)) = val/total;
  29. % end
  30. % end
  31. %
  32. % nnz_n = nnz(attAffinity);
  33. % LogMsg(sprintf('attAffinity totalM (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,100*nnz_n/(n*n)));
  34. attAffinity = AttributesSimilarity(common,count,threshold);
  35. nnz_n = nnz(attAffinity);
  36. LogMsg(sprintf('attAffinity totalC (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,100*nnz_n/(n*n)));
  37. % diff = attAffinityC-attAffinity;
  38. % nnz_n = nnz(diff);
  39. % LogMsg(sprintf('attAffinity diff (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,100*nnz_n/(n*n)));
  40. end %function