|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- function [ affinity ] = CalcPHsAffinityByAA( data, actual_graph_size, num_missing_nodes, connectPlaceholdersToNeighbors)
- % sigal 29.10.13
- % based on CalculateAffinityByAdamicAdar_Sparse
-
- % adamic/adar(i,j) = sum( 1 / log(num_neighbors(k) | k is a
- % neighbor of both i and j
-
- fprintf('CalcPHsAffinityByAA: NNZ(data) = %d\n', nnz(data));
-
- firstPH = actual_graph_size-num_missing_nodes+1;
- numPHs = size(data,1) - firstPH +1;
-
- %n = size(data,1);
- %diag_indices = 1:n+1:n*n;
- %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
- if connectPlaceholdersToNeighbors > 0
- data = ConnectMissingNodesToNeighborsNeighbors( data, actual_graph_size, num_missing_nodes);
- end
- affinity = zeros(numPHs,numPHs);
-
- s_cols = sum(data(:,firstPH:end),2); % give the #PH neighbors per node (nx1)?
- fprintf('CalcPHsAffinityByAA: NNZ(s_cols) = %d\n', nnz(s_cols));
- for k = 1 : size(data,1)
- if s_cols(k) > 0
- %find all the neighbors of k
- neighbors_k_vec = data(k,:);
- 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
- neighbors_k = find(neighbors_k_vec);
- num_neighbors_k = size(neighbors_k, 2);
- %sigal - only need to calcluate for PHs (thus indexes are updated accordingly)
- phs_neighbors_k_idc = neighbors_k>=firstPH;
- phs_neighbors_k = neighbors_k(1,phs_neighbors_k_idc)-firstPH+1;
-
- if num_neighbors_k > 1 && size(phs_neighbors_k,2) > 0
- w = 1;
- inv_log_num_neighbors_k = w / log(num_neighbors_k);
- for i = phs_neighbors_k
- for j = phs_neighbors_k
- affinity(i,j) = affinity(i,j) + inv_log_num_neighbors_k;
- affinity(j,i) = affinity(i,j);
- end
- end
- end
- end
- end
-
- %sigal 29.10.13 - normolize by diagonal min
- v = diag(affinity);
- max_val = min(v);
- %max_val = max(max(affinity));
-
- affinity = affinity ./ max_val;
-
- for i = 1 : size(affinity,1)
- affinity(i,i) = 1;
- end
- %sigal 29.10.13 - end
-
-
- affinity = sparse(affinity);
-
- end
-
|