@not_implemented_for('directed')
@not_implemented_for('multigraph')
def communicability_betweenness_centrality(G, normalized=True):
 import scipy
 import scipy.linalg
 nodelist = list(G)
 n = len(nodelist)
 A = nx.to_numpy_matrix(G, nodelist)
 A[(A != 0.0)] = 1
 expA = scipy.linalg.expm(A.A)
 mapping = dict(zip(nodelist, range(n)))
 cbc = {}
 for v in G:
  i = mapping[v]
  row = A[i, :].copy()
  col = A[:, i].copy()
  A[i, :] = 0
  A[:, i] = 0
  B = ((expA - scipy.linalg.expm(A)) / expA)
  B[i, :] = 0
  B[:, i] = 0
  B -= scipy.diag(scipy.diag(B))
  cbc[v] = float(B.sum())
  A[i, :] = row
  A[:, i] = col
 cbc = _rescale(cbc, normalized=normalized)
 return cbc

@ not_implemented_for ( 'directed' ) @ not_implemented_for ( 'multigraph' ) def communicability_betweenness_centrality ( G , normalized = True ) : import scipy import scipy . linalg nodelist = list ( G ) n = len ( nodelist ) A = nx . to_numpy_matrix ( G , nodelist ) A [ ( A != 0.0 ) ] = 1 expA = scipy . linalg . expm ( A . A ) mapping = dict ( zip ( nodelist , range ( n ) ) ) cbc = { } for v in G : i = mapping [ v ] row = A [ i , : ] . copy ( ) col = A [ : , i ] . copy ( ) A [ i , : ] = 0 A [ : , i ] = 0 B = ( ( expA - scipy . linalg . expm ( A ) ) / expA ) B [ i , : ] = 0 B [ : , i ] = 0 B -= scipy . diag ( scipy . diag ( B ) ) cbc [ v ] = float ( B . sum ( ) ) A [ i , : ] = row A [ : , i ] = col cbc = _rescale ( cbc , normalized = normalized ) return cbc
return subgraph communicability for all pairs of nodes in g .