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.

CalcMissPHsAffinityByAttributes.m 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function [candidatesAffinity] = CalcMissPHsAffinityByAttributes(candidates, averageTop, data, attData, last_known_node, addMissingAtt, threshold)
  2. % sigal 29.10.13
  3. % based on CalcAttributesAffinity_S5
  4. n = size(data,1);
  5. numAtt = size(attData,2);
  6. firstPH = last_known_node+1;
  7. numPHs = size(data,1) - firstPH +1;
  8. if firstPH > n
  9. LogMsg(sprintf('*** ERROR: CalcPHsAffinityByAttributes firstPH %d >size %d.',firstPH, n));
  10. return
  11. end
  12. if addMissingAtt > 0 && last_known_node < n
  13. attData = AddMissingNodesAttrFromNeighborsNeighbors(data, attData, last_known_node, addMissingAtt);
  14. end
  15. candidatesInd = find(candidates>0);
  16. totalInd = [candidatesInd,firstPH:size(data,1)];
  17. attData = attData(totalInd,:);
  18. totalNum = size(attData,1);
  19. count = sum(attData,2);
  20. nnz_n = nnz(count);
  21. nnz_p = 100*nnz_n/totalNum;
  22. LogMsg(sprintf('PHsAttAffinity count (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n, nnz_p));
  23. % full calculation
  24. common = attData*attData';
  25. affinity = zeros(totalNum,totalNum);
  26. for i=1:totalNum
  27. for j=1:totalNum
  28. val = common(i,j);
  29. total = count(i)+count(j)-val;
  30. if total > 0 && val/total > threshold
  31. affinity(i,j) = val/total;
  32. end
  33. end
  34. end
  35. nnz_n = nnz(affinity);
  36. nnz_p = 100*nnz_n/(totalNum*totalNum);
  37. LogMsg(sprintf('PHsAttAffinity totalC (%d, %.3f) - nnz=%d, %7.5f%%',numAtt,threshold,nnz_n,nnz_p));
  38. clear('common');
  39. clear('count');
  40. candidatesNum = nnz(candidatesInd);
  41. candidatesAffinity = zeros(1, size(candidates,2));
  42. for i=1:candidatesNum
  43. sortedA = sort(affinity(i,:),'descend');
  44. val = sum(sortedA(1:averageTop),2)/averageTop;
  45. candidatesAffinity(1,candidatesInd(1,i)) = val;
  46. end
  47. clear('affinity');
  48. end %function