def density(cmatrix, edgetype): """ Density is the proportion of the number of present connections in the network, to the maximum possible number of connections. Connection weights are ignored. Parameters ---------- cmatrix : connection/adjacency matrix Returns ------- edgetype == 'undirected': kden : connection density, number of connections present out of all possible (N^2-N) Note: Assumes that cmatrix is undirected and that there are no self-connections. Note: Function always returns average binary density, regardless of weights. Olaf Sporns, Indiana University, 2002/2007/2008 Modification history: 2009-10: K fixed to sum over one half of cmatrix [Tony Herdman, SFU] edgetype == 'directed' kden : connection density, number of connections present out of all possible (N^2-N) Note: Assumes that cmatrix is directed and that there are no self-connections. Note: Function always returns average binary density, regardless of weights. Olaf Sporns, Indiana University, 2002/2007/2008 """ if edgetype == 'undirected': m = bct.to_gslm(cmatrix.tolist()) val = bct.density_und(m) bct.gsl_free(m) return val elif edgetype == 'directed': m = bct.to_gslm(cmatrix.tolist()) val = bct.density_dir(m) bct.gsl_free(m) return val
def density_dir(*args): return _bct.density_dir(*args)
def density_dir(*args): """density_dir(gsl_matrix CIJ) -> double""" return _bct.density_dir(*args)