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_Sparse.m 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. function [ affinity ] = CalcAffinityByCommonNeighbors_Sparse( data, actual_graph_size, num_missing_nodes, num_attr_nodes, attWeight, addMissingAtt )
  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, num_attr_nodes, addMissingAtt);
  9. end
  10. % affinity = sparse(size(data,1), size(data,2));
  11. %
  12. % num_neighbors = full(sum(data));
  13. %
  14. % for i = 1 : size(data,1)
  15. % %i
  16. % num_neighbors_i = num_neighbors(i);
  17. % for j = i : size(data,1)
  18. % num_neighbors_j = num_neighbors(j);
  19. % num_common_neighbors = nnz((data(i,:)) & (data(j,:)));
  20. % if data(i,j) > 0
  21. % num_common_neighbors = num_common_neighbors + 2; %add one for each direction of the link
  22. % end
  23. % % num_common_neighbors = 0;
  24. % % if data(i,j) == 1
  25. % % num_common_neighbors = 1;
  26. % % end
  27. % % for k = 1 : size(data,1)
  28. % % if data(i,k) == 1 && data(j,k) == 1
  29. % % num_common_neighbors = num_common_neighbors + 1;
  30. % % end
  31. % % end
  32. %
  33. %
  34. % affinity(i,j) = max(max(num_common_neighbors / num_neighbors_i, num_common_neighbors / num_neighbors_j),eps);
  35. %
  36. % affinity(j,i) = affinity(i,j);
  37. % end
  38. % end
  39. %%%%%%%%%%%%%%%% Problematic??
  40. % Sigal 5.3.13: normalizeWeight
  41. % make sure that ratio att/link is same w/1-w
  42. if attWeight < 1 && attWeight >= 0
  43. normalizeWeight = attWeight/(1-attWeight);
  44. else
  45. normalizeWeight = 1;
  46. end
  47. data1 = data;
  48. if num_attr_nodes > 0
  49. data1(:, 1:num_attr_nodes) = normalizeWeight * data1(:, 1:num_attr_nodes);
  50. data1(1:num_attr_nodes, :) = normalizeWeight * data1(1:num_attr_nodes, :);
  51. end
  52. % sigal - oct 12 - bug fix by ron - include the node itself as its friend
  53. affinity = data1 * data + data1*2; % give the #common neighbors per node pair (nxn)
  54. s_rows = sum(data1) + 1; % give the #neighbors per node (nx1)?
  55. %%s_cols = sum(data,2);
  56. affinity = NormalizeCommonNeighbors(affinity, s_rows); %new mex function
  57. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  58. % for i = 1 : size(data)
  59. % affinity(i,:) = affinity(i,:) ./ s_rows(i);
  60. % affinity(:,i) = affinity(:,i) ./ s_cols(i);
  61. % end
  62. % %sigal 29.10.13 - normolize by diagonal min
  63. % v = diag(affinity);
  64. % max_val = min(v);
  65. % %max_val = max(max(affinity));
  66. %
  67. % affinity = affinity ./ max_val;
  68. %
  69. % for i = 1 : size(affinity,1)
  70. % affinity(i,i) = 1;
  71. % end
  72. % %sigal 29.10.13 - end
  73. end