On 01.04.2016 15:51, Stephen Bonner wrote:
Is there a primitive function for counting triangles in graph-tool?
The closest one is global_clustering(), which returns:
3 x number of triangles / number of connected triples
the denominator is easy to compute from the degrees alone (the number of
triples a node with degree k participates is simply k(k-1)/2). Hence,
you can get the number of triangles with:
d = g.degree_property_map("out")
n_t = global_clustering(g)[0] * (d.a * (d.a - 1) / 2) .sum() / 3
Currently i am explicitly creating a triangle graph and then using the motif function to search for this graph. -
triangle = Graph()
v1 = triangle.add_vertex()
v2 = triangle.add_vertex()
v3 = triangle.add_vertex()
e = triangle.add_edge(v1, v2)
e = triangle.add_edge(v1, v3)
e = triangle.add_edge(v3, v2)
triangle.set_directed(False)
motifsgraph, num_triangles = motifs(tempG, 3, motif_list=[triangle])
Just wondering if there is a better way to do this as it is 1) slow and 2) turning up some strange results.
This should work too. What strange results are you seeing?
Best,
Tiago
--
Tiago de Paula Peixoto <
tiago@skewed.de>
_______________________________________________
graph-tool mailing list
graph-tool@skewed.dehttps://lists.skewed.de/mailman/listinfo/graph-tool