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.

CalcPHsAffinityByAttributes.asv 1.6KB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function [affinity] = CalcPHsAffinityByAttributes(data, attData, last_known_node, addMissingAtt, threshold, add2levels)
  2. % sigal 29.10.13
  3. % based on CalcAttributesAffinity_S5
  4. % sigal 19.2.14 - choose between attribute and
  5. if nargin < 6
  6. add2levels = 0;
  7. end
  8. n = size(data,1);
  9. numAtt = size(attData,2);
  10. firstPH = last_known_node+1;
  11. numPHs = size(data,1) - firstPH +1;
  12. if firstPH > n
  13. LogMsg(sprintf('*** ERROR: CalcPHsAffinityByAttributes firstPH %d >size %d.',firstPH, n));
  14. return
  15. end
  16. if addMissingAtt > 0 && last_known_node < n
  17. attData = AddMissingNodesAttrFromNeighborsNeighbors(data, attData, last_known_node, addMissingAtt);
  18. end
  19. attData = attData(firstPH:end,:);
  20. count = sum(attData,2);
  21. nnz_n = nnz(count);
  22. nnz_p = 100*nnz_n/numPHs;
  23. LogMsg(sprintf('PHsAttAffinity count (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n, nnz_p));
  24. % full calculation
  25. common = attData*attData';
  26. affinity = zeros(numPHs,numPHs);
  27. for i=1:numPHs
  28. for j=1:numPHs
  29. val = common(i,j);
  30. total = count(i)+count(j)-val;
  31. if total > 0 && val/total > threshold
  32. affinity(i,j) = val/total;
  33. end
  34. end
  35. end
  36. nnz_n = nnz(affinity);
  37. nnz_p = 100*nnz_n/(numPHs*numPHs);
  38. LogMsg(sprintf('PHsAttAffinity totalC (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,nnz_p));
  39. clear('common');
  40. clear('count');
  41. end %function