# Subgraph Centrality - Optimization

I'm implementing some calculations on networks, and one of the properties I'm using is the Subgraph Centrality (developed on this paper). The equation I'm using is the equation (4) on the paper.

I wrote the following code for the equation:

eigenvalues = Chop[Eigenvalues[N[Normal[AdjacencyMatrix[graph]]]]];
subCentrality=Table[N[Sum[(Power[eigenvectors[[i,j]],2])*Exp[eigenvalues[[i]]], {i,VertexCount[graph]}]],{j,Length[eigenvectors]}];


Where 'graph' is any graph. The data I'm using is on this link, which corresponds to the 'AdjacencyMatrix' of my network. Using this formula, it took me about 9h to complete the calculation. That could be a suitable time if I had to calculate it only once, but I'm trying to implement it in some algorithms, where I'll have to calculate this about 2000-3000 times. Is there a way of optimizing this code?

• You might use EigenSystem to get both the values and vectors at once -- with luck this might cut the time in half. – bill s Nov 23 '17 at 15:59

{λ, U} = Eigensystem[N[Normal[AdjacencyMatrix[graph]]]];