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.

CalcPHsAffinityByAA_samiA.m 2.5KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. function [ affinity ] = CalcPHsAffinityByAA( data, actual_graph_size, num_missing_nodes, connectPlaceholdersToNeighbors)
  2. % sigal 29.10.13
  3. % based on CalculateAffinityByAdamicAdar_Sparse
  4. % adamic/adar(i,j) = sum( 1 / log(num_neighbors(k) | k is a
  5. % neighbor of both i and j
  6. fprintf('CalcPHsAffinityByAA: NNZ(data) = %d\n', nnz(data));
  7. firstPH = actual_graph_size-num_missing_nodes+1;
  8. numPHs = size(data,1) - firstPH +1;
  9. %n = size(data,1);
  10. %diag_indices = 1:n+1:n*n;
  11. %data(diag_indices) = 1; %we consider each node as a neighbor of itself to obtain higher connectivity in the affinity matrix - i.e. each node will have a positive affinity to all its neighbors
  12. if connectPlaceholdersToNeighbors > 0
  13. data = ConnectMissingNodesToNeighborsNeighbors( data, actual_graph_size, num_missing_nodes);
  14. end
  15. affinity = zeros(numPHs,numPHs);
  16. s_cols = sum(data(:,firstPH:end),2); % give the #PH neighbors per node (nx1)?
  17. fprintf('CalcPHsAffinityByAA: NNZ(s_cols) = %d\n', nnz(s_cols));
  18. for k = 1 : size(data,1)
  19. if s_cols(k) > 0
  20. %find all the neighbors of k
  21. neighbors_k_vec = data(k,:);
  22. neighbors_k_vec(k) = 1;%we consider each node as a neighbor of itself to obtain higher connectivity in the affinity matrix - i.e. each node will have a positive affinity to all its neighbors
  23. neighbors_k = find(neighbors_k_vec);
  24. num_neighbors_k = size(neighbors_k, 2);
  25. %sigal - only need to calcluate for PHs (thus indexes are updated accordingly)
  26. phs_neighbors_k_idc = neighbors_k>=firstPH;
  27. phs_neighbors_k = neighbors_k(1,phs_neighbors_k_idc)-firstPH+1;
  28. if num_neighbors_k > 1 && size(phs_neighbors_k,2) > 0
  29. w = 1;
  30. inv_log_num_neighbors_k = w / log(num_neighbors_k);
  31. for i = phs_neighbors_k
  32. for j = phs_neighbors_k
  33. affinity(i,j) = affinity(i,j) + inv_log_num_neighbors_k;
  34. affinity(j,i) = affinity(i,j);
  35. end
  36. end
  37. end
  38. end
  39. end
  40. %sigal 29.10.13 - normolize by diagonal min
  41. v = diag(affinity);
  42. max_val = min(v);
  43. %max_val = max(max(affinity));
  44. affinity = affinity ./ max_val;
  45. for i = 1 : size(affinity,1)
  46. affinity(i,i) = 1;
  47. end
  48. %sigal 29.10.13 - end
  49. affinity = sparse(affinity);
  50. end