# Consistent tools for graph analysis#

NNGT provides several functions for topological analysis that return consistent results for all backends (the results will always be the same regardless of which library is used under the hood). This section describes these functions and gives an overview of the currently supported methods.

Note

It is of course possible to use any function from the library on the graph attribute; however, not using one of the supported NNGT functions below will usually return results that are not consistent between libraries (and the code will obviously no longer be portable).

## Supported functions#

The following table details which functions are supported for directed and undirected networks, and whether they also work with weighted edges.

The test file where these functions are checked can be found here: testing/library_compatibility.py.

For each type of graph, the table tells which libraries are supported for the given function (graph-tool is gt, networkx is nx and igraph is ig). Custom implementation of a function is denoted by nngt, meaning that the function can be used even if no graph library is installed. A library marked between parentheses denotes partial support and additional explanation is usually given in the footnotes. A cross means that no consistent implementation is currently provided and the function will raise an error if one tries to use it on such graphs. Methods that are not defined for weighted or directed graphs are marked by NA.

Method

Unweighted undirected

Unweighted directed

Weighted undirected

Weighted directed

all_shortest_paths()

gt, nx, ig

gt, nx, ig

gt, nx, ig

gt, nx, ig

average_path_length()

gt, nx, ig

gt, nx, ig

gt, nx, ig

gt, nx, ig

gt, nx, ig

gt, nx, ig

gt, ig

gt, ig

betweenness()

gt, nx, ig

gt, nx, ig

gt, nx, ig

gt, nx, ig

betweenness_distrib()

gt, nx, ig

gt, nx, ig

gt, nx, ig

gt, nx, ig

closeness()

gt, nx, ig

gt, nx, ig

gt, nx, ig

gt, nx, ig

connected_components()

gt, nx, ig

gt, nx, ig

gt, nx, ig

gt, nx, ig

degree_distrib()

gt, nx, ig, nngt

gt, nx, ig, nngt

gt, nx, ig, nngt

gt, nx, ig, nngt

gt, nx, ig

gt, nx, ig

gt, nx, ig

gt, nx, ig

global_clustering()

gt, nx, ig, nngt

nngt

nngt

nngt

gt, nx, ig, nngt

nngt

nngt

nngt

reciprocity()

gt, nx, ig, nngt

gt, nx, ig, nngt

NA

NA

shortest_distance()

gt, nx, ig

gt, nx, ig

gt, nx, ig

gt, nx, ig

shortest_path()

gt, nx, ig

gt, nx, ig

gt, nx, ig

gt, nx, ig

spectral_radius()

nngt

nngt

nngt

nngt

subgraph_centrality()

nngt

nngt

nngt

nngt

gt, nx, ig, nngt

nngt

nngt

nngt

1

networkx could be used via a workaround but an issue has been raised to find out how to best deal with this.

2

the implementation of the diameter for graph-tool is approximmate so results may occasionaly be inexact with this backend.

3

for directed and weighted networks, definitions and implementations differ between graph libraries, so generic implementations are provided in NNGT. See “Clustering in weighted and directed networks” for details.

4

identical to global_clustering.

### Clustering in weighted and directed networks#

For directed clustering, NNGT provides the total clustering proposed in [Fagiolo2007]

with is the reciprocal degree.

For undirected weighted clustering, NNGT provides the definition proposed in [Barrat2004], [Onnela2005], [Zhang2005] as well as a new continuous definition [Fardet2021].

with the generalized strength associated to the matrix .

For directed weighted clustering, the generalization of Barrat from [Clemente2018] is provided, as well as a generalization of Onnela, Zhang–Horvath, and of the continuous clustering [Fardet2020], for all four directed modes (middleman, cycle, fan-in, and fan-out), as well as their sum, the total clustering:

with the total strength and the arithmetic reciprocal strength,

with the total generalized strength and the geometric reciprocal strength.

Global clusterings are defined as the sum of all numerators divided by the sum of all denominators for all definitions.

### References#

Barrat2004

Barrat, Barthelemy, Pastor-Satorras, Vespignani. The Architecture of Complex Weighted Networks. PNAS 2004, 101 (11). DOI: 10.1073/pnas.0400087101.

Clemente2018

Clemente, Grassi. Directed Clustering in Weighted Networks: A New Perspective. Chaos, Solitons & Fractals 2018, 107, 26–38. DOI: 10.1016/j.chaos.2017.12.007, arXiv: 1706.07322.

Fagiolo2007

Fagiolo. Clustering in Complex Directed Networks. Phys. Rev. E 2007, 76, (2), 026107. DOI: 10.1103/PhysRevE.76.026107, arXiv: physics/0612169.

Onnela2005

Onnela, Saramäki, Kertész, Kaski. Intensity and Coherence of Motifs in Weighted Complex Networks. Phys. Rev. E 2005, 71 (6), 065103. DOI: 10.1103/physreve.71.065103, arXiv: cond-mat/0408629.

Saramaki2007

Saramäki, Kivelä, Onnela, Kaski, Kertész. Generalizations of the Clustering Coefficient to Weighted Complex Networks. Phys. Rev. E 2007, 75 (2), 027105. DOI: 10.1103/PhysRevE.75.027105, arXiv: cond-mat/0608670.

Zhang2005

Zhang, Horvath. A General Framework for Weighted Gene Co-Expression Network Analysis. Statistical Applications in Genetics and Molecular Biology 2005, 4 (1). DOI: 10.2202/1544-6115.1128, PDF.

Fardet2021

Fardet, Levina. Weighted directed clustering: interpretations and requirements for heterogeneous, inferred, and measured networks. 2021. arXiv: 2105.06318.

Go to other tutorials: