0
$\begingroup$

I'm trying to calculate the transitivity of a graph, also known as it's global clustering coefficient. The formula for this is: # of triangles / # of connected triples as seen here. While I can easily calculate the number of triangles in a graph by taking $tr(A^3)/6$ where $A$ is the adjacency matrix, I have had less success calculating the denominator. Since $A^3$ has entry $a_{i,j}$ giving the number of paths from $i$ to $j$, I had thought that I could get the total number of paths of length $3$ by simply summing any row of $A^3$ and dividing by $3$, but this doesn't give the right answer according to the code I have written.

This is for a program, so if there isn't a formula then pseudocode for the calculation would work too.

  • 0
    ``Since $A^3$ has entry $a_{i, j}$ giving the number of paths from $i$ to $j$'' You don't say anything about length of such path. It is not good.2017-02-07
  • 0
    Connected triples are a path of length 22017-02-07
  • 0
    You should sum the rows of $A^2$ then...2017-02-07
  • 0
    I mean you should fix any $A^3$ to $A^2$ except the one inside the trace.2017-02-07
  • 0
    @StellaBiderman What about the elements of the diagonal? you shouldn't include them.2017-02-07

1 Answers 1

2

$\sum_{i\neq j}(A^2)_{i,j}\over2$ should work.