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

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