I am trying to replicate Mathematica's LocalClusteringCoefficient
function (as well as compute $C_i^{out}$) for a directed graph. Which was presumed that Mathematica calculates as the cyclic clustering coefficient, $C_i^{cyc}$ in this post: What exactly does LocalClusteringCoefficient compute for directed graphs?
The equation comes from page 13 of this paper, also linked in Szabolcs's post:
$$C_i^{cyl}=$$ $$(A)_{ii}^3\over d_i^{in}d_i^{out}-d_i^{\leftarrow\rightarrow}$$
Where:
$$d_i^{in} = (A^T)_i 1$$
$$d_i^{out} = (A)_i 1$$
$$d_i^{\leftarrow\rightarrow}=(A)_{ii}^2$$
A = Adjacency Matrix, $(A)_i$ = $i$-th row of A, 1 = N-dimensional column vector $(1,1,....1,)^T$
For a graph g
:
g = Graph[{1, 2, 3, 4}, {1 -> 2, 2 -> 3, 3 -> 1, 1 -> 4}, VertexLabels ->"Name"]
Here is what I've tried:
s = Range[VertexCount[g]];
one = Table[1, Max[VertexCount[g]]];
din = Transpose[AdjacencyMatrix[g]][[#]] & /@ s;
dout = AdjacencyMatrix[g][[#]] & /@ s;
dlink = b2.b2.b2
numer = dout.dout.dout
denom = (din.one).(dout.one) - dlink;
numer/denom
%.one
With these results:
(* {1/3, 2/3, 1/3, 0} *)
However, LocalClusteringCoefficient[g]
yields:
(*{1/2, 1, 1, 0}*)