#NEWLINE# @ not_implemented_for ( 'directed' ) #NEWLINE# @ not_implemented_for ( 'multigraph' ) #NEWLINE# def communicability( G ) : #NEWLINE# #INDENT# 'Return communicability between all pairs of nodes in G.\n\n    The communicability between pairs of nodes in G is the sum of\n    closed walks of different lengths starting at node u and ending at node v.\n\n    Parameters\n    ----------\n    G: graph\n\n    Returns\n    -------\n    comm: dictionary of dictionaries\n        Dictionary of dictionaries keyed by nodes with communicability\n        as the value.\n\n    Raises\n    ------\n    NetworkXError\n       If the graph is not undirected and simple.\n\n    See Also\n    --------\n    communicability_exp:\n       Communicability between all pairs of nodes in G  using spectral\n       decomposition.\n    communicability_betweenness_centrality:\n       Communicability betweeness centrality for each node in G.\n\n    Notes\n    -----\n    This algorithm uses a spectral decomposition of the adjacency matrix.\n    Let G=(V,E) be a simple undirected graph.  Using the connection between\n    the powers  of the adjacency matrix and the number of walks in the graph,\n    the communicability  between nodes `u` and `v` based on the graph spectrum\n    is [1]_\n\n    .. math::\n        C(u,v)=\\sum_{j=1}^{n}\\phi_{j}(u)\\phi_{j}(v)e^{\\lambda_{j}},\n\n    where `\\phi_{j}(u)` is the `u\\rm{th}` element of the `j\\rm{th}` orthonormal\n    eigenvector of the adjacency matrix associated with the eigenvalue\n    `\\lambda_{j}`.\n\n    References\n    ----------\n    .. [1] Ernesto Estrada, Naomichi Hatano,\n       "Communicability in complex networks",\n       Phys. Rev. E 77, 036111 (2008).\n       http://arxiv.org/abs/0707.0756\n\n    Examples\n    --------\n    >>> G = nx.Graph([(0,1),(1,2),(1,5),(5,4),(2,4),(2,3),(4,3),(3,6)])\n    >>> c = nx.communicability(G)\n    ' #NEWLINE# import numpy #NEWLINE# import scipy.linalg #NEWLINE# nodelist = list ( G ) #NEWLINE# A = nx . to_numpy_matrix ( G , nodelist ) #NEWLINE# A [ ( A != 0.0 ) ] = 1 #NEWLINE# ( w , vec ) = numpy . linalg . eigh ( A ) #NEWLINE# expw = numpy . exp ( w ) #NEWLINE# mapping = dict ( zip ( nodelist , range ( len ( nodelist ) ) ) ) #NEWLINE# c = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for u in G : #NEWLINE# #INDENT# c [ u ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for v in G : #NEWLINE# #INDENT# s = 0 #NEWLINE# p = mapping [ u ] #NEWLINE# q = mapping [ v ] #NEWLINE# for j in range ( len ( nodelist ) ) : #NEWLINE# #INDENT# s += ( ( vec [ : , q ] [ ( p , 0 ) ] * vec [ : , j ] [ ( q , 0 ) ] ) * expw [ j ] ) #NEWLINE# #UNINDENT# c [ u ] [ v ] = float ( s ) #NEWLINE# #UNINDENT# #UNINDENT# return c