1
$\begingroup$

The adjacency matrix with weights on each edges are as shown below.

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} }

adjPSODynamicsData = {
   {0, 1, 1, 1, 2, 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, 0, 0, 0, 0, 0, 0, 0},
   {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   {4, 4, 10, 2, 2, 4, 10, 3, 8, 2, 2, 5, 7, 9},
   {0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   {3, 5, 0, 4, 1, 6, 0, 5, 0, 1, 2, 2, 3, 3},
   {0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
   {0, 1, 1, 2, 1, 3, 1, 3, 0, 2, 1, 2, 1, 2},
   {0, 0, 0, 3 , 2, 0, 0, 1, 0, 0, 1, 1, 1, 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, 1, 0, 0 , 4, 0, 0, 0, 0, 1, 0, 0, 0, 1},
   {0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
   };

WeightedAdjacencyGraph@adjPSODynamicsData

pts[m_, r_] := Module[{pts, CCr, CCm, BCr, BCm, EVCr, EVCm},
  pts = 0;
  
  BCm = Mean[BetweennessCentrality@WeightedAdjacencyGraph@m];
  BCr = Mean[BetweennessCentrality@WeightedAdjacencyGraph@r];
  
  (*EVCr=Mean[EigenvectorCentrality@WeightedAdjacencyGraph@m];
  EVCm=Mean[EigenvectorCentrality@WeightedAdjacencyGraph@r];*)
  pts = ((BCr - BCm)/BCr)^2 ;
  
  pts *= 1000;
  Return@pts
  ]

pts[adjCitationData, adjPSODynamicsData]

I have to calculate the value points for real and modelled network. But when I use the in-built BetweennessCentrality of Mathematica, I get all zeros:

BetweennessCentrality@WeightedAdjacencyGraph@adjCitationData
{0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}

I am I using the BetweennessCentrality function correctly? Same is the case for closeness and eigenvector centralities.

$\endgroup$
4
  • 1
    $\begingroup$ The definition you provide is for betweenness, not closeness. The network does not have a closeness centrality, it is the individual vertices that do. Both these measures are already implemented in Mathematica. Can you explain why you want to implement them from scratch? $\endgroup$
    – Szabolcs
    May 3, 2022 at 8:54
  • $\begingroup$ To better understand the calculation and later modify as per the need $\endgroup$ May 3, 2022 at 9:12
  • 1
    $\begingroup$ What have you tried so far? I assume you found FindShortestPath? You can use FindPath to find all paths of the same length. $\endgroup$
    – Szabolcs
    May 3, 2022 at 9:43
  • $\begingroup$ The title of your post was not consistent with the question asked in the body. I edited it to focus on one specific question. If you have other questions, please ask them in a separate post instead of changing this one. $\endgroup$
    – Szabolcs
    May 4, 2022 at 6:37

1 Answer 1

4
$\begingroup$

There are two reasons why centrality functions return all zeros:

  • WeightedAdjacencyGraph does not work as one would normally expect. This function creates an edge also for matrix entries which are zeros. To indicate the absence of an entry, use Infinity. Use ReplaceAll to change zeros to infinities in your matrix.
  • BetweennessCentrality does not support edge weights. There is no workaround to this using built-in functions.

The simplest way to get around these limitation is to use my package, IGraph/M, which provides a more reasonable IGWeightedAdjacencyGraph which treats 0 as a missing edge, and also allows configuring the value that should be interpreted as "unconnected". It also provides IGBetweenness, which does support weights.

$\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.