Provides algorithms for calculation of clustering coefficients, aka. transitivity.
| local_clustering (g[, prop, undirected]) | Return the local clustering coefficients for all vertices. |
| global_clustering (g) | Return the global clustering coefficient. |
| extended_clustering (g[, props, max_depth, ...]) | Return the extended clustering coefficients for all vertices. |
| motifs (g, k[, p, motif_list, undirected]) | Count the occurrence of k-size subgraphs (motifs). A tuple with two lists is returned: the list of motifs found, and the list with their respective counts. |
| motif_significance (g, k[, n_shuffles, p, motif_list, ...]) | Obtain the motif significance profile, for subgraphs with k vertices. A tuple with two lists is returned: the list of motifs found, and their respective z-scores. |
Return the local clustering coefficients for all vertices.
| Parameters: | g : Graph
prop : PropertyMap or string, optional
undirected : bool, optional
|
|---|---|
| Returns: | prop : PropertyMap
|
See also
Notes
The local clustering coefficient [watts-collective-1998] c_i is defined as
where k_i is the out-degree of vertex i, and
is the set of out-neighbours of vertex i. For undirected graphs the value of c_i is normalized as
The implemented algorithm runs in O(|V|\left< k\right>^3) time, where \left< k\right> is the average out-degree.
If enabled during compilation, this algorithm runs in parallel.
References
| [watts-collective-1998] | D. J. Watts and Steven Strogatz, “Collective dynamics of ‘small-world’ networks”, Nature, vol. 393, pp 440-442, 1998. doi:10.1038/30918 |
Examples
>>> from numpy.random import seed
>>> seed(42)
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> clust = gt.local_clustering(g)
>>> print gt.vertex_average(g, clust)
(0.0052816666666666671, 0.00046415526317530143)
Return the global clustering coefficient.
| Parameters: | g : Graph
|
|---|---|
| Returns: | c : tuple of floats
|
See also
Notes
The global clustering coefficient [newman-structure-2003] c is defined as
The implemented algorithm runs in O(|V|\left< k\right>^3) time, where \left< k\right> is the average (total) degree.
If enabled during compilation, this algorithm runs in parallel.
References
| [newman-structure-2003] | M. E. J. Newman, “The structure and function of complex networks”, SIAM Review, vol. 45, pp. 167-256, 2003 |
Examples
>>> from numpy.random import seed
>>> seed(42)
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> print gt.global_clustering(g)
(0.0075696677384780283, 0.00039465997422993533)
Return the extended clustering coefficients for all vertices.
| Parameters: | g : Graph
props : list of PropertyMap objects, optional
max_depth : int, optional
undirected : bool, optional
|
|---|---|
| Returns: | prop : list of PropertyMap objects
|
See also
Notes
The extended clustering coefficient c^d_i of order d is defined as
where d_G(u,v) is the shortest distance from vertex u to v in graph G, and
is the set of out-neighbours of i. According to the above definition, we have that the traditional local clustering coefficient is recovered for d=1, i.e., c^1_i = c_i.
The implemented algorithm runs in O(|V|\left<k\right>^{2+\text{max-depth}}) worst time, where \left< k\right> is the average out-degree.
If enabled during compilation, this algorithm runs in parallel.
References
| [abdo-clustering] | A. H. Abdo, A. P. S. de Moura, “Clustering as a measure of the local topology of networks”, arXiv:physics/0605235v4 |
Examples
>>> from numpy.random import seed
>>> seed(42)
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> clusts = gt.extended_clustering(g, max_depth=5)
>>> for i in xrange(0, 5):
... print gt.vertex_average(g, clusts[i])
...
(0.0052816666666666671, 0.00046415526317530143)
(0.026543333333333332, 0.0010405374199048405)
(0.11648, 0.0019761350156302583)
(0.40672499999999995, 0.0031128844140121867)
(0.42646999999999996, 0.0030644539462829075)
Count the occurrence of k-size subgraphs (motifs). A tuple with two lists is returned: the list of motifs found, and the list with their respective counts.
| Parameters: | g : Graph
k : int
p : float or float list (optional, default: 1.0)
motif_list : list of Graph objects, optional
undirected : bool, optional
|
|---|---|
| Returns: | motifs : list of Graph objects
counts : list of ints
|
See also
Notes
This functions implements the ESU and RAND-ESU algorithms described in [wernicke-efficient-2006].
If enabled during compilation, this algorithm runs in parallel.
References
| [wernicke-efficient-2006] | (1, 2, 3) S. Wernicke, “Efficient detection of network motifs”, IEEE/ACM Transactions on Computational Biology and Bioinformatics (TCBB), Volume 3, Issue 4, Pages 347-359, 2006. |
Examples
>>> from numpy.random import seed
>>> seed(42)
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> motifs, counts = gt.motifs(g, 4, undirected=True)
>>> print len(motifs)
11
>>> print counts
[115780, 390603, 667, 764, 2666, 1694, 821, 5, 9, 4, 4]
Obtain the motif significance profile, for subgraphs with k vertices. A tuple with two lists is returned: the list of motifs found, and their respective z-scores.
| Parameters: | g : Graph
k : int
n_shuffles : int (optional, default: 100)
p : float or float list (optional, default: 1.0)
motif_list : list of Graph objects (optional, default: None)
threshold : int (optional, default: 0)
undirected : bool (optional, default: None)
self_loops : bool (optional, default: False)
parallel_edges : bool (optional, default: False)
full_output : bool (optional, default: False)
shuffle_strategy : string (optional, default: “uncorrelated”)
|
|---|---|
| Returns: | motifs : list of Graph objects
z-scores : list of floats
|
See also
Notes
The z-score z_i of motif i is defined as
where N_i is the number of times motif i found, and N^s_i is the count of the same motif but on a shuffled network. It measures how many standard deviations is each motif count, in respect to a ensemble of randomly shuffled graphs with the same degree sequence.
The z-scores values are not normalized.
If enabled during compilation, this algorithm runs in parallel.
Examples
>>> from numpy import random
>>> random.seed(10)
>>> g = gt.random_graph(100, lambda: (3,3))
>>> motifs, zscores = gt.motif_significance(g, 3)
>>> print len(motifs)
12
>>> print zscores
[0.84493166311546375, 0.83875258032645894, 1.2117425659306142, -0.20405718722884647, -0.69886762637118316, -0.68343227667794837, -0.92481997609648403, -0.11, -0.14999999999999999, -0.26000000000000001, -0.14000000000000001, -0.01]