def clustering_coef_wu(*args): return _bct.clustering_coef_wu(*args)
def clustering_coef_wu(*args): """clustering_coef_wu(gsl_matrix W) -> gsl_vector""" return _bct.clustering_coef_wu(*args)
def clustering_coef(cmatrix, edgetype, weighted): """ Clustering coefficient C For an individual node, the clustering coefficient is defined as the fraction of the existing number, to the total possible number of neighbor-neighbor links. Parameters ---------- cmatrix : connection/adjacency matrix edgetype : {'directed','undirected'} weighted : {False, True} Returns ------- edgetype == 'undirected': weighted == True: C : clustering coefficient C for weighted undirected graph W. Reference: Onnela et al. 2005, Phys Rev E 71:065103 Mika Rubinov, UNSW, 2007 (last modified July 2008) weighted == False: C : clustering coefficient C, for binary undirected graph G Reference: Watts and Strogatz, 1998, Nature 393:440-442 Mika Rubinov, UNSW, 2007 (last modified September 2008) edgetype == 'directed': weighted == True: C : clustering coefficient C for weighted directed graph W. Reference: Fagiolo, 2007, Phys Rev E 76:026107 (also see Onnela et al. 2005, Phys Rev E 71:065103); Mika Rubinov, UNSW, 2007 (last modified July 2008) See comments for clustering_coef_bd The weighted modification is as follows: - The numerator: adjacency matrix is replaced with weights matrix^1/3 - The denominator: no changes from the binary version The above reduces to symmetric and/or binary versions of the clustering coefficient for respective graphs. weighted == False: C : clustering coefficient C, for binary directed graph A Reference: Fagiolo, 2007, Phys Rev E 76:026107. Mika Rubinov, UNSW, 2007 (last modified July 2008) In directed graphs, 3 nodes generate up to 8 triangles (2*2*2 edges) The number of existing triangles is the main diagonal of S^3/2 The number of all (in or out) neighbour pairs is K(K-1)/2 Each neighbour pair may generate two triangles "False pairs" are i<->j edge pairs (these do not generate triangles) The number of false pairs is the main diagonal of A^2 Thus the maximum possible number of triangles = = (2 edges)*([ALL PAIRS] - [FALSE PAIRS]) = = 2 * (K(K-1)/2 - diag(A^2)) = K(K-1) - 2(diag(A^2)) """ if edgetype == 'directed': if weighted: m = bct.to_gslm(cmatrix.tolist()) str = bct.clustering_coef_wd(m) strnp = bct.from_gsl(str) bct.gsl_free(m) bct.gsl_free(str) return np.asarray(strnp) else: m = bct.to_gslm(cmatrix.tolist()) str = bct.clustering_coef_bd(m) strnp = bct.from_gsl(str) bct.gsl_free(m) bct.gsl_free(str) return np.asarray(strnp) else: if weighted: m = bct.to_gslm(cmatrix.tolist()) str = bct.clustering_coef_wu(m) strnp = bct.from_gsl(str) bct.gsl_free(m) bct.gsl_free(str) return np.asarray(strnp) else: m = bct.to_gslm(cmatrix.tolist()) str = bct.clustering_coef_bu(m) strnp = bct.from_gsl(str) bct.gsl_free(m) bct.gsl_free(str) return np.asarray(strnp)