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.

CalcAffinityByCommonNeighbors.m 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. function [ affinity ] = CalcAffinityByCommonNeighbors( data, actual_graph_size, num_missing_nodes )
  2. %UNTITLED Summary of this function goes here
  3. % Detailed explanation goes here
  4. %since missing nodes are only connected to one node we will artificially
  5. %connect them to their only neighbor's neighbors, and keep the connection to
  6. %the neighbor itself.
  7. if nargin > 1
  8. data = ConnectMissingNodesToNeighborsNeighbors(data, actual_graph_size, num_missing_nodes);
  9. end
  10. affinity = zeros(size(data,1), size(data,2));
  11. for i = 1 : size(data,1)
  12. num_neighbors_i = sum(data(i,:));
  13. for j = i : size(data,1)
  14. num_neighbors_j = sum(data(j,:));
  15. num_common_neighbors = sum((data(i,:)) > 0 & (data(j,:) > 0));
  16. if data(i,j) > 0
  17. num_common_neighbors = num_common_neighbors + 2; %add one for each direction of the link
  18. end
  19. % num_common_neighbors = 0;
  20. % if data(i,j) == 1
  21. % num_common_neighbors = 1;
  22. % end
  23. % for k = 1 : size(data,1)
  24. % if data(i,k) == 1 && data(j,k) == 1
  25. % num_common_neighbors = num_common_neighbors + 1;
  26. % end
  27. % end
  28. %set the lowest affinity to epsilon
  29. %affinity(i,j) = max(max(num_common_neighbors / num_neighbors_i, num_common_neighbors / num_neighbors_j), eps);
  30. affinity(j,i) = affinity(i,j);
  31. end
  32. end
  33. end