2
$\begingroup$

enter image description hereI want to add the information centrality metric to my analysis of complex network. Is there any in built function or library that I can use in mathematical. I did not come across any algorithm with clear idea how to implement this. enter image description here

Update: If I use the algorithm as mentioned in the literature above I get a situation that the inverse of the matrix cannot be calculated (mathematica displays as singular matrix ) as shown below

Data is:

adjCitationData = {
    {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} }


DCr = DegreeCentrality@IGWeightedAdjacencyGraph@adjCitationData;
n = 14;
diagD = DiagonalMatrix[DCr];
matJ = Table[1, {i, n}, {j, n}];
matB = diagD - adjCitationData + matJ;
Inverse[matB];
invB = Inverse[matB] // N;
infoC[i_, j_] := invB[[i, i]] + invB[[j, j]] - 2*invB[[i, j]];
Inverse[matB];(*Inverse cannot be calculated as determinant is zero*)
Dimensions[matB]

IGWeightedAdjacencyGraph is from IGraph http://szhorvat.net/pelican/igraphm-a-mathematica-interface-for-igraph.html

I am I doing this correctly.

$\endgroup$
3
  • 1
    $\begingroup$ Can you define what you mean by informational centrality? There are many centrality measures in Mathematica such as betweenness, degree, eigenvalue centralities so on. $\endgroup$ May 4, 2022 at 19:08
  • $\begingroup$ Can you provide the full reference of the paper developing the centrality measure? If possible, send the link to the paper. $\endgroup$ May 4, 2022 at 21:27
  • $\begingroup$ In your matrix adjCitationData , the last row and the last columns are all zero. You should drop the zero rows and columns from this matrix. Then, the algorithm works fine, otherwise, the matrix cannot be converted to a graph. $\endgroup$ May 5, 2022 at 8:59

2 Answers 2

3
$\begingroup$

@Tugrul Temel`s answer followed the paper instructions and works fine. Here is the fine-tuned version of that code which is around one order of magnitude faster:

ClearAll[informationCentrality];
informationCentrality[g_] := 
 Block[{b = 
    Inverse[1. + DiagonalMatrix[DegreeCentrality[g]] - 
      AdjacencyMatrix[g](*KirchhoffMatrix[g]+1.*)], bDiagonal},

  bDiagonal = Diagonal[b];
  Outer[Plus, bDiagonal, bDiagonal] - 2 * b
  ]

Comparison

(* Tugrul Temel`s answer *)
TugrulTemel[g_] := Block[{n = VertexCount[g], invB},
  invB = Inverse[
    1. + DiagonalMatrix[DegreeCentrality[g]] - AdjacencyMatrix[g]];
  Table[invB[[i, i]] + invB[[j, j]] - 2*invB[[i, j]], {i, n}, {j, n}]
  ]
g = RandomGraph[{70, 260}]

informationCentrality[g] == TugrulTemel[g]
(* Out: True *)

informationCentrality[g]; // RepeatedTiming
(* Out: {0.000533871, Null} *)

TugrulTemel[g]; // RepeatedTiming
(* Out: {0.0123265, Null} *)
$\endgroup$
5
  • $\begingroup$ Nice, compact and efficient code. Thanks. $\endgroup$ May 5, 2022 at 8:36
  • $\begingroup$ @Ben lzd I have problem with inversing the matrix. The sample data I have added in the Updated question. Is there any way to overcome this. $\endgroup$ May 5, 2022 at 10:15
  • $\begingroup$ @SyedIftekharuddin I think it's because your graph is not weakly connected and has separate components. $\endgroup$
    – Ben Izd
    May 5, 2022 at 11:07
  • $\begingroup$ @BenIzd I have added my graph for visualization. Could you please suggest how to overcome this. $\endgroup$ May 5, 2022 at 11:18
  • $\begingroup$ For your specific graph which has 1 main component, you can try (assuming graph is save in a variable called g): informationCentrality[First[TakeLargestBy[WeaklyConnectedGraphComponents[g],EdgeCount,1]]]. This will give you the main component's information centrality without the two isolated vertices. $\endgroup$
    – Ben Izd
    May 5, 2022 at 14:09
2
$\begingroup$

Here is an example with a 5 by 5 matrix.

ClearAll[adjA, adjG, degD, diagD, matJ, matB];
SeedRandom[11];
adjA = RandomInteger[{0, 1}, {5, 5}];  (*an example Adjaceny Matrix*)
adjG = AdjacencyGraph[adjA, VertexLabels -> "Name"]; (* Directed graph of adjA *)
degD = DegreeCentrality[adjG]; (* Degree vector of adjG *)
diagD = DiagonalMatrix[degD]; (* Diagonal Degree Matrix of degD *)
matJ = Table[1, {i, 5}, {j, 5}];  (* matrix with all elements 1 *)
matB = diagD - adjA + matJ; (* matrix B *)
Inverse[matB] // N; (* inverse of matB *)

infoC[i_, j_] := invB[[i, i]] + invB[[j, j]] - 2*invB[[i, j]]; (* definition of informational centrality *)

Example: i=2, j=4;

infoC[2,4]
(* 0.320202 *)

You can then calculate any centrality value using infoC[i,j].

UPDATE A generalization of the centrality measure for any directed graph with n vertices;

ClearAll[n, adjA, adjG, degD, diagD, matJ, matB, invB];
SeedRandom[11];
n = 10; (* number of vertices *)
adjA = RandomInteger[{0, 1}, {n, n}];
adjG = AdjacencyGraph[adjA, VertexLabels -> "Name"];
degD = DegreeCentrality[adjG];
diagD = DiagonalMatrix[degD];
matJ = Table[1, {i, n}, {j, n}];
matB = diagD - adjA + matJ;
invB = Inverse[matB] // N;

(* informational centrality measure for individual vertices i and j *)
infoC[i_, j_] := invB[[i, i]] + invB[[j, j]] - 2*invB[[i, j]]

(* full matrix of informational centrality measures *)
Table[infoC[i, j], {i, n}, {j, n}] // MatrixForm
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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