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.