3
$\begingroup$

I am new to mathematica. I have an adjacency matrix as shown below. I need to calculate various centralities for this matrix. But there is some strange error that I cannot understand.

mainList = {
{18, 5, 2,  4 ,   9,  0,  0,  5, 0, 3,   1,   5,    0,   0},
{  3, 6, 0,  2 ,   2,  0,  0,  0, 0, 0,   0,   1,   0,    0},
{  1, 3, 3,  4 ,   3,  0,  0,  0, 0, 0,   0,   1,   0,    0},
{  9, 0, 0, 68,  25,  0,  0,  0, 0, 6,  12,   0,   6,    0},
{19, 4, 1, 57, 139,  0,  0, 0, 0, 7,  62,  0,  44,  0},
{  1, 0, 0,  0 ,   0,  5,  4,  0, 0,  0,   0,    0,   0,   0},
{  1, 0, 0,  0 ,   0,  3,  2,  0, 0,  0,   0,    0,   0,   0},
{  6, 0, 0,  0 ,   1,  0,  0,  2, 0,  0,   0,    3,   0,   0},
{  0, 0, 0,  0 ,   0,  0,  0,  0, 0,  0,   0,    0,   0,   0},
{  0, 0, 0,  0 ,   0,  0,  0,  0, 0,  0,   0,    0,   0,   0},
{  8, 2, 0, 44 , 85, 0,  0,  0, 0,  4,  53,   0,  35,  0},
{  8, 1, 0,  0 ,   1,  1,  0,  2, 0,  0,   0,    6,   0,   0},
{  1, 0, 0, 25 , 59,  0,  0, 0, 0,  1,  47,   0,  37,  0},
{  0, 0, 0,  0 ,   0,   0,  0,  0, 0,  0,    0,    0,   0,   0} };

I removed the zero from the matrix and replace with infinity using the Replace as

mainList = ReplaceAll[0 -> \[Infinity]][mainList];



 {{1, 1, 2, 1, 3, 2, 1, 1, 1, 1, 1, 1, 1, 
  1}, {1, \[Infinity], \[Infinity], \[Infinity], 2, 
  1, \[Infinity], \[Infinity], \[Infinity], \[Infinity], \[Infinity], \
\[Infinity], \[Infinity], \[Infinity]}, {2, \[Infinity], \[Infinity], \
\[Infinity], 4, 
  2, \[Infinity], \[Infinity], \[Infinity], \[Infinity], \[Infinity], \
\[Infinity], \[Infinity], \[Infinity]}, {1, \[Infinity], \[Infinity], \
\[Infinity], 2, 
  1, \[Infinity], \[Infinity], \[Infinity], \[Infinity], \[Infinity], \
\[Infinity], \[Infinity], \[Infinity]}, {3, 2, 4, 2, 2, 3, 2, 2, 2, 2,
   2, 2, 2, 2}, {2, 1, 2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 
  1}, {1, \[Infinity], \[Infinity], \[Infinity], 2, 
  1, \[Infinity], \[Infinity], \[Infinity], \[Infinity], \[Infinity], \
\[Infinity], \[Infinity], \[Infinity]}, {1, \[Infinity], \[Infinity], \
\[Infinity], 2, 
  1, \[Infinity], \[Infinity], \[Infinity], \[Infinity], \[Infinity], \
\[Infinity], \[Infinity], \[Infinity]}, {1, \[Infinity], \[Infinity], \
\[Infinity], 2, 
  1, \[Infinity], \[Infinity], \[Infinity], \[Infinity], \[Infinity], \
\[Infinity], \[Infinity], \[Infinity]}, {1, \[Infinity], \[Infinity], \
\[Infinity], 2, 
  1, \[Infinity], \[Infinity], \[Infinity], \[Infinity], \[Infinity], \
\[Infinity], \[Infinity], \[Infinity]}, {1, \[Infinity], \[Infinity], \
\[Infinity], 2, 
  1, \[Infinity], \[Infinity], \[Infinity], \[Infinity], \[Infinity], \
\[Infinity], \[Infinity], \[Infinity]}, {1, \[Infinity], \[Infinity], \
\[Infinity], 2, 
  1, \[Infinity], \[Infinity], \[Infinity], \[Infinity], \[Infinity], \
\[Infinity], \[Infinity], \[Infinity]}, {1, \[Infinity], \[Infinity], \
\[Infinity], 2, 
  1, \[Infinity], \[Infinity], \[Infinity], \[Infinity], \[Infinity], \
\[Infinity], \[Infinity], \[Infinity]}, {1, \[Infinity], \[Infinity], \
\[Infinity], 2, 
  1, \[Infinity], \[Infinity], \[Infinity], \[Infinity], \[Infinity], \
\[Infinity], \[Infinity], \[Infinity]}}

I need to calculate the closeness, betweeness and EigenVector centralities as follows: CCm = Mean[IGCloseness@IGWeightedAdjacencyGraph@mainList];

BCm = Mean[IGBetweenness@IGWeightedAdjacencyGraph@mainList];

EVCm = Mean[EigenvectorCentrality@WeightedAdjacencyGraph@mainList];

I get the following error (for example for closeness centrality calculation):

enter image description here

I am not sure how to solve this issue.

$\endgroup$

1 Answer 1

6
$\begingroup$
  1. You must load IGraph/M using Needs["IGraphM`"] before using any functions from the package. The red syntax colouring of IGWeightedAdjacencyMatrix in your screenshot shows that you have not done so. Restart the kernel, and load the package before doing anything else.
  2. It is not necessary to replace zeros with infinities when using IGWeightedAdjacencyMatrix.

You can create a weighted graph from the adjacency matrix like this:

Needs["IGraphM`"]

g = IGWeightedAdjacencyGraph[mainList]

I noticed that you have non-zero entries on the diagonal. This is unusual. Is it intentional, or a mistake on your part? Do you really want self-loops in your graph?

Notice that the graph is not connected. There are two isolated vertices. There is an additional vertex with no outgoing connections, showing that the rest of the graph is not strongly connected either. It makes no sense to compute closeness in disconnected graphs. More details: http://szhorvat.net/mathematica/IGDocumentation/#closeness

It also makes no sense to compute eigenvector centrality for a disconnected graph. The largest eigenvalue will be degenerate. Furthermore, while eigenvector centrality can be defined for directed graphs in principle, it was not really designed for these. Note that IGEigenvectorCentrality computes the left eigenvector of the adjacency matrix. More details: http://szhorvat.net/mathematica/IGDocumentation/#eigenvector-centrality

Finally, note that the interpretation of weights is different when computing betweenness/closeness vs eigenvector centrality. With shortest path based measures such as betweenness and closeness, weights are interpreted as edge lengths, i.e. larger weights represent longer/weaker connections. With the eigenvector centrality, larger weights represent stronger connections. You should transform your weights to make them suitable for the specific measure you are computing.

I notice that you are trying to compute the mean of centrality values. Be careful here: centrality measures characterize individual vertices, not graphs. They are useful to compare two vertices within the same graph. Comparing vertices across different graphs is already problematic, especially if the graphs have a different number of vertices. Taking the mean of all values will not in generally be meaningful for characterizing an entire graph. Think e.g. of eigenvector centrality: the values are the entries of the leading eigenvector of the adjacency matrix. If you multiply them by a constant, they are equally valid. Eigenvector centrality values are meaningless in isolation, they are only useful for comparing two vertices within the same graph.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.