%% A quick example of the centrality measures

%% Create the graph
G = sparse(9,9);
G(1,[2,3,4]) = 1;
G(2,[3,4,5]) = 1;
G(3,[4,6,7]) = 1;
G(4,8) = 1;
G(8,9) = 1;
G = G+G';
xy = [0 0; 
      1/sqrt(2) 1/sqrt(2); 
      1/sqrt(2) -1/sqrt(2); 
      -1 0;
      2/sqrt(2) 2/sqrt(2);
      1/sqrt(2)+1 -1/sqrt(2); 
      1/sqrt(2) -1/sqrt(2)-1; 
      -2 0;
      -3 0];
A = G;
%%
gplot(A,xy,'.-');
%%
addpath('~/dev/matlab-bgl');
%%
deg_cen = sum(A,2);
%%
D = floyd_warshall_all_sp(A);
ecc_cen = 1./max(D,2);
tc_cen = 1./sum(D,2);
%%
bet_cen = betweenness_centrality(A);
%%
alpha = 1/4;
n = size(A,1);
katz_cen = (eye(n) - alpha*A')\(alpha*A'*ones(n,1));
%%
katz_series = alpha*A'*ones(n,1);
for k=1:100
    katz_series = katz_series + ones(n,1);
    katz_series = alpha*(A'*katz_series);
end
%% Katz's graph
A = sparse(6,6);
A(1,6) = 1;
A(2,[3,6]) = 1;
A(3,[2,4,6]) = 1;
A(4,[1,5]) = 1;
A(5,[4,6]) = 1;
A(6,[1,4]) = 1;

%%
alpha = 1/2;
n = size(A,1);
katz_cen = (eye(n) - alpha*A')\(alpha*A'*ones(n,1));
