# graph_tool.clustering.global_clustering#

graph_tool.clustering.global_clustering(g, weight=None, ret_counts=False, sampled=False, m=1000)[source]#

Return the global clustering coefficient.

Parameters:
gGraph

Graph to be used.

weightEdgePropertyMap, optional (default: None)

Edge weights. If omitted, a constant value of 1 will be used.

ret_countsboolean (optional, default: False)

If True the number of triangles and connected triples are also returned.

sampledbool (default: False)

If True a much faster, assymptotically exact, sampling estimate is performed. In this case the, weight option is ignored.

mint (default: 1000)

If sampled is True, this will be the number of samples used for the estimation.

Returns:
ctuple of floats or float

Global clustering coefficient and standard deviation (jackknife method). If sampled is True only the clustering coefficient is returned.

trianglesint (if ret_counts is True)

Number of triangles. Not returned if sampled is True.

triplesint (if ret_counts is True)

Number of connected triples. Not returned if sampled is True.

local_clustering

local clustering coefficient

extended_clustering

extended (generalized) clustering coefficient

motifs

motif counting

Notes

The global clustering coefficient [newman-structure-2003] $$c$$ is defined as

$c = 3 \times \frac{\text{number of triangles}} {\text{number of connected triples}}$

If weights are given, the following definition is used:

$c = \frac{\mathrm{Tr}{{\boldsymbol A}^3}}{\sum_{i\ne j}[{\boldsymbol A}^2]_{ij}},$

where $$\boldsymbol A$$ is the weighted adjacency matrix, and it is assumed that the weights are normalized, i.e. $$A_{ij} \le 1$$.

The implemented algorithm runs in time $$O(|V|\left<k^2\right>)$$, where $$\left< k^2\right>$$ is the second moment of the degree distribution.

If enabled during compilation, this algorithm runs in parallel.

References

M. E. J. Newman, “The structure and function of complex networks”, SIAM Review, vol. 45, pp. 167-256, 2003, DOI: 10.1137/S003614450342480 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> print(gt.global_clustering(g))
(0.2556818181..., 0.06314746595...)
{"ft_lang_label":"__label__en","ft_lang_prob":0.6769587,"math_prob":0.98996085,"size":2189,"snap":"2023-40-2023-50","text_gpt3_token_len":581,"char_repetition_ratio":0.12860411,"word_repetition_ratio":0.028880866,"special_character_ratio":0.27546826,"punctuation_ratio":0.18717949,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9992372,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-03T13:11:04Z\",\"WARC-Record-ID\":\"<urn:uuid:b8d2a8e7-ace0-470e-a719-10cd56e5ce6a>\",\"Content-Length\":\"73396\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a23b7d11-e7b3-449d-a54f-0cba3345d95b>\",\"WARC-Concurrent-To\":\"<urn:uuid:f41db583-d98b-43fd-9b67-d50b03d459b1>\",\"WARC-IP-Address\":\"49.12.93.194\",\"WARC-Target-URI\":\"https://graph-tool.skewed.de/static/doc/autosummary/graph_tool.clustering.global_clustering.html\",\"WARC-Payload-Digest\":\"sha1:FS4VRCLM2TMEV4KSXLEUGOJJOL7NM2TP\",\"WARC-Block-Digest\":\"sha1:VWSM34UTHGPKNHI6NA67WGPDGA2J3XF5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100508.23_warc_CC-MAIN-20231203125921-20231203155921-00802.warc.gz\"}"}