def eigenvector_centrality(graph, normalized=True, reversed=True, rating={},<EOL>start=None, iterations=<NUM_LIT:100>, tolerance=<NUM_LIT>):
G = graph.keys()     <EOL>W = adjacency (graph, directed=True, reversed=reversed)<EOL>def _normalize(x):<EOL><INDENT>s = sum(x.values())<EOL>if s != <NUM_LIT:0>: s = <NUM_LIT:1.0> / s<EOL>for k in x: <EOL><INDENT>x[k] *= s<EOL><DEDENT><DEDENT>x = start<EOL>if x is None:<EOL><INDENT>x = dict([(n, random()) for n in G])<EOL><DEDENT>_normalize(x)<EOL>for i in range(iterations):<EOL><INDENT>x0 = x<EOL>x = dict.fromkeys(x0.keys(), <NUM_LIT:0>)<EOL>for n in x:<EOL><INDENT>for nbr in W[n]:<EOL><INDENT>r = <NUM_LIT:1><EOL>if rating.has_key(n): r = rating[n]<EOL>x[n] += <NUM_LIT> + x0[nbr] * W[n][nbr] * r<EOL><DEDENT><DEDENT>_normalize(x)          <EOL>e = sum([abs(x[n]-x0[n]) for n in x])<EOL>if e < len(graph.nodes) * tolerance:<EOL><INDENT>if normalized:<EOL><INDENT>m = max(x.values())<EOL>if m == <NUM_LIT:0>: m = <NUM_LIT:1><EOL>x = dict([(id, w/m) for id, w in x.iteritems()])<EOL><DEDENT>return x<EOL><DEDENT><DEDENT>warn("<STR_LIT>", Warning)<EOL>return dict([(n, <NUM_LIT:0>) for n in G])<EOL>
Eigenvector centrality for nodes in the graph (like Google's PageRank).

    Eigenvector centrality is a measure of the importance of a node in a directed network. 
    It rewards nodes with a high potential of (indirectly) connecting to high-scoring nodes.
    Nodes with no incoming connections have a score of zero.
    If you want to measure outgoing connections, reversed should be False.

    The eigenvector calculation is done by the power iteration method.
    It has no guarantee of convergence.
    A starting vector for the power iteration can be given in the start dict.

    You can adjust the importance of a node with the rating dictionary,
    which links node id's to a score.

    The algorithm is adapted from NetworkX, Aric Hagberg (hagberg@lanl.gov):
    https://networkx.lanl.gov/attachment/ticket/119/eigenvector_centrality.py