Matlab code contributed by Scott D. White

From InterSciWiki
Jump to: navigation, search


Scott's zip file for matlab code Scott D. White including network algorithms.


Intro to Matlab (by Scott White)

Comments

Peter J. Mucha to Doug WikiSysopWikiSysop 05:55, 9 June 2008 (PDT) show details 5:31 AM (21 minutes ago)

Reply

Doug -- Thanks for the update. It's great to see more things available out on the web like this to try to use. I've already sent one of my students off to try some of Scott White's codes.

Peter

See also

Estrada's Subgraph centrality, network communicability, and community detection.

Matlab code by James McNerney for Estrada Indices and Community detection

6 September 2009: I've added matlab code below for several of the quantities used in Ernesto Estrada's papers on communicability and subgraph centrality. --James McNerney

Subgraph centrality C_s

function Cs = sg_centrality(A)
% SG_CENTRALITY(A) computes the subgraph centralities of the network 
% represented by the adjacency matrix A. It returns a vector of subgraph
% centralities for each node of the network (as they are ordered in the
% adjacency matrix.)

[V,lambda] = eig(A);                   % Compute the eigenvectors and
lambda     = diag(lambda);             % eigenvalues.
V2         = V.^2;                     % Matrix of squares of the eigenvectors elements.
Cs         = real(V2 * exp(lambda));   % Compute eigenvector centrality. Lop off imaginary part remaining due to precision error.

Communicability G

function G = communicability(A)
% COMMUNICABILITY(A) computes the communicability of pairs of nodes in the
% network represented by the adjacency matrix A. It returns a matrix whose
% elements G(i,j) = G(j,i) give the the communicability between nodes i and
% j.

G = expm(A);    % Compute the matrix exponential of A.

\Delta G (Community detection)

function DG = Delta_G( A ) 
% DELTA_G(A) computes the matrix "delta G" (a matrix related to the
% communicability matrix) for the network with adjacency matrix A. Finding
% cliques in the signed version of this matrix is equivalent to finding
% communities in the original adjacency matrix.

[phi,lambda] = eig(A);
n            = length(A);
phi1         = phi(:,n);      % 'eig' orders eigenvalue in increasing order,
lambda1      = lambda(n,n);   % so the nth eigenvalue is the largest
first_term   = phi1 * phi1' * exp(lambda1);  % Matrix of first terms in the decomposition of G.
G            = expm(A);                      % The communicability.
DG           = G - first_term;

Homogeneity \xi

function xi = homogeneity(A)
% HOMOGENEITY(A) computes Estrada's measure of homogeneity for a network
% with adjacency matrix A.

% Compute Cs_odd values for all nodes.
[phi,lambda] = eig(A);                    % Compute the eigenvectors and
lambda       = diag(lambda);              % eigenvalues.
phi2         = phi.^2;                    % Matrix of squares of the eigenvectors elements.
Cs_odd       = real(phi2 * sinh(lambda)); % Compute eigenvector centrality. Lop off imaginary part remaining due to precision error.

% Compute xi.
n            = length(A);
phi_1        = abs(phi(:,n));    % The eigenvector of the largest eigenvalue.
lambda_1     = lambda(n);        % The largest eigenvalue.
residuals    = log10(phi_1) - 0.5*log10(Cs_odd) + 0.5*log10(sinh(lambda_1));
xi           = sqrt( sum(residuals.^2)/n );

Plot

%%% Plot %%%
% Compute vectors for plotting line of perfectly homogeneous network.
Cs_low  = min(Cs_odd);
Cs_hi   = max(Cs_odd);
Cs_plot = [Cs_low Cs_hi];
b       = sinh(lambda_1)^(-.5);

% Plot.
loglog(Cs_odd, phi_1, 'o')
hold on
plot( Cs_plot, b*Cs_plot.^(.5), 'k--')
hold off
set(gca, 'FontSize',16)
xlabel('C_s^{(odd)}(i)')
ylabel('phi_1(i)')
title( ['\xi(G) = ',num2str(xi)] )