function USP = unionofshortestpaths(G);
% Computes the graph of the union of shortest paths for a weighted adjacency matrix of connectivity, first transforming the weights to a normalised distance.
% Cite: Meier J, Tewarie P, Van Mieghem P. The Union of Shortest Path Trees of Functional Brain Networks. Brain Connectivity. 2015;5(9):575-581.
%
% INPUT- G, a weighted adjacency matrix.
% OUTPUT- USP, the binary matrix for the union of shortest paths of
% G.
% alpha = 5;
% G = (exp(-G) - exp(-1))/(exp(0)-exp(-1));
% G = exp(G)/exp(1);
A = squareform(G);
alpha = [1:100] + log(max(A));
alpha = find(alpha<1 & alpha>0);
alpha = alpha(1);
G = -log(G)/alpha;
G(G==Inf) = 0;
G(G==1) = 0;
%G = 1-G;
%G(G==1) = 0;
G = sparse(G);
USP = zeros(size(G));
for i = 1:length(G)
for j = 1:length(G)
[dist, path, pred] = graphshortestpath(G,i,j);
for k = 1:sum(path>0)-1
USP(path(k),path(k+1)) = 1;
end
end
end