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.

AddMissingNodesAttrFromNeighborsNeighbors.m 1.9KB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. function [ attDataOut ] = AddMissingNodesAttrFromNeighborsNeighbors( data, attData, last_known_node, addMissingAttPerc, add2level)
  2. if nargin<4
  3. addMissingAttPerc = 1;
  4. end
  5. first_missing_node = last_known_node + 1;
  6. attDataOut = attData;
  7. m = size(data,1); % num rows
  8. ma = size(attDataOut,1);
  9. na = size(attDataOut,2);
  10. if (ma < m)
  11. attDataOut = [attDataOut; zeros(m-ma,na)];
  12. end
  13. for i = first_missing_node : size(data,1)
  14. neighbor = find(data(i,:), 1 ); %the missing node could have more than one neighbor if in a previous iteration we added a neighbor to it. The min should be the original neighbor
  15. %fprintf('i = %d, neighbor = %d\n', i, neighbor);
  16. %sum(data(i,:))
  17. if size(neighbor,2) > 0
  18. if add2level == 1
  19. neighborNeighbors = find(data(neighbor,:));
  20. else
  21. neighborNeighbors = neighbor;
  22. end
  23. if addMissingAttPerc == 1
  24. attDataOut(i,:) = attDataOut(i,:) | attDataOut(neighbor,:);
  25. for j = neighborNeighbors
  26. attDataOut(i,:) = attDataOut(i,:) | attDataOut(j,:);
  27. end
  28. else
  29. attDataOut(i,:) = attDataOut(i,:) | chooseAttData(attDataOut(neighbor,:),addMissingAttPerc) ;
  30. for j = neighborNeighbors
  31. attDataOut(i,:) = attDataOut(i,:) | chooseAttData(attDataOut(j,:),addMissingAttPerc);
  32. end
  33. end
  34. else
  35. fprintf('Warning: node %d doesnt have any neighbors\n', i);
  36. end
  37. end
  38. end % function AddMissingNodesAttrFromNeighborsNeighbors
  39. function [choosenAtt] = chooseAttData(inAttData, chooseAttPerc)
  40. choosenAtt = inAttData;
  41. attIndices = find(inAttData==1);
  42. for i= attIndices
  43. if rand(1)>chooseAttPerc
  44. choosenAtt(i) = 0;
  45. end
  46. end
  47. end % function chooseAtt