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.

ConnectMissingNodesToNeighborsNeighbors.m 3.2KB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. function [ data ] = ConnectMissingNodesToNeighborsNeighbors( data, actual_graph_size, num_missing_nodes, num_attr_nodes, addMissingAtt )
  2. %UNTITLED Summary of this function goes here
  3. % Detailed explanation goes here
  4. if nargin < 4
  5. num_attr_nodes = 0;
  6. addMissingAtt = 0;
  7. fprintf('run ConnectMissingNodesToNeighborsNeighbors without attributes params\n');
  8. end
  9. first_missing_node = actual_graph_size - num_missing_nodes + 1;
  10. % Sigal - TOCHECK remove connection to attributes nodes
  11. if addMissingAtt > 0 % sigal 10.2.14 % == 1 % sigal 24.10.13 TODO val > 0
  12. first_node = 1; %% sigal test 6.2.13 num_attr_nodes+1;
  13. first_social_node = num_attr_nodes+1;
  14. else
  15. first_node = num_attr_nodes+1;
  16. end
  17. %last_node = first_missing_node-1;
  18. for i = first_missing_node : size(data,1)
  19. 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
  20. %fprintf('i = %d, neighbor = %d\n', i, neighbor);
  21. %sum(data(i,:))
  22. if size(neighbor,2) > 0
  23. if addMissingAtt == 0 || num_attr_nodes == 0
  24. data(i,first_node:end) = data(i,first_node:end) | data(neighbor, first_node:end);
  25. data(first_node:end,i) = data(first_node:end,i) | data(first_node:end,neighbor);
  26. else
  27. % connect all friends
  28. data(i,first_social_node:end) = data(i,first_social_node:end) | data(neighbor, first_social_node:end);
  29. data(first_social_node:end,i) = data(first_social_node:end,i) | data(first_social_node:end,neighbor);
  30. % connect % of attributes
  31. % sigal - 19.2.14 - SAMI-A is better with only neighbor's attributes
  32. % neighborNeighbors = find(data(neighbor, first_social_node:end));
  33. neighborNeighbors = neighbor;
  34. for j = neighborNeighbors
  35. attData = data(j,1:num_attr_nodes);
  36. choosenAtt = chooseAttData(attData, addMissingAtt);
  37. attIndices = find(choosenAtt==1);
  38. data(i,attIndices) = data(i,attIndices) | data(j,attIndices);
  39. data(attIndices,i) = data(attIndices,i) | data(attIndices,j);
  40. end
  41. end
  42. else
  43. fprintf('Warning: node %d doesnt have any neighbors\n', i);
  44. end
  45. % data(i,:) = data(neighbor, :);
  46. % data(:,i) = data(:,neighbor);
  47. % data(i,neighbor) = 1;
  48. % data(neighbor,i) = 1;
  49. end
  50. end
  51. function [choosenAtt] = chooseAttData(inAttData, chooseAttPerc)
  52. choosenAtt = inAttData;
  53. if chooseAttPerc < 1
  54. attIndices = find(inAttData==1);
  55. for i= attIndices
  56. if rand(1)>chooseAttPerc
  57. choosenAtt(i) = 0;
  58. end
  59. end
  60. end
  61. end % function chooseAtt