We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
eigenvector_centrality() docstring needs rewording
The docstring for eigenvector_centrality() refers to the cluster centrality of a node i and then proceeds to give an equation for the vector of cluster centrality for all nodes. Suggest rewording similar to the katz_similarity() method.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `networkx/algorithms/centrality/eigenvector.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #    Copyright (C) 2004-2018 by
3 #    Aric Hagberg <hagberg@lanl.gov>
4 #    Dan Schult <dschult@colgate.edu>
5 #    Pieter Swart <swart@lanl.gov>
6 #    All rights reserved.
7 #    BSD license.
8 #
9 # Authors:
10 #     Aric Hagberg <aric.hagberg@gmail.com>
11 #     Pieter Swart <swart@lanl.gov>
12 #     Sasha Gutfraind <ag362@cornell.edu>
13 """Functions for computing eigenvector centrality."""
14 from __future__ import division
15 
16 from math import sqrt
17 
18 import networkx as nx
19 from networkx.utils import not_implemented_for
20 
21 __all__ = ['eigenvector_centrality', 'eigenvector_centrality_numpy']
22 
23 
24 @not_implemented_for('multigraph')
25 def eigenvector_centrality(G, max_iter=100, tol=1.0e-6, nstart=None,
26                            weight=None):
27     r"""Compute the eigenvector centrality for the graph `G`.
28 
29     Eigenvector centrality computes the centrality for a node based on the
30     centrality of its neighbors. The eigenvector centrality for node $i$ is
31 
32     .. math::
33 
34         Ax = \lambda x
35 
36     where $A$ is the adjacency matrix of the graph `G` with eigenvalue
37     $\lambda$. By virtue of the Perron–Frobenius theorem, there is
38     a unique and positive solution if $\lambda$ is the largest
39     eigenvalue associated with the eigenvector of the adjacency matrix
40     $A$ ([2]_).
41 
42     Parameters
43     ----------
44     G : graph
45       A networkx graph
46 
47     max_iter : integer, optional (default=100)
48       Maximum number of iterations in power method.
49 
50     tol : float, optional (default=1.0e-6)
51       Error tolerance used to check convergence in power method iteration.
52 
53     nstart : dictionary, optional (default=None)
54       Starting value of eigenvector iteration for each node.
55 
56     weight : None or string, optional (default=None)
57       If None, all edge weights are considered equal.
58       Otherwise holds the name of the edge attribute used as weight.
59 
60     Returns
61     -------
62     nodes : dictionary
63        Dictionary of nodes with eigenvector centrality as the value.
64 
65     Examples
66     --------
67     >>> G = nx.path_graph(4)
68     >>> centrality = nx.eigenvector_centrality(G)
69     >>> sorted((v, '{:0.2f}'.format(c)) for v, c in centrality.items())
70     [(0, '0.37'), (1, '0.60'), (2, '0.60'), (3, '0.37')]
71 
72     Raises
73     ------
74     NetworkXPointlessConcept
75         If the graph `G` is the null graph.
76 
77     NetworkXError
78         If each value in `nstart` is zero.
79 
80     PowerIterationFailedConvergence
81         If the algorithm fails to converge to the specified tolerance
82         within the specified number of iterations of the power iteration
83         method.
84 
85     See Also
86     --------
87     eigenvector_centrality_numpy
88     pagerank
89     hits
90 
91     Notes
92     -----
93     The measure was introduced by [1]_ and is discussed in [2]_.
94 
95     The power iteration method is used to compute the eigenvector and
96     convergence is **not** guaranteed. Our method stops after ``max_iter``
97     iterations or when the change in the computed vector between two
98     iterations is smaller than an error tolerance of
99     ``G.number_of_nodes() * tol``. This implementation uses ($A + I$)
100     rather than the adjacency matrix $A$ because it shifts the spectrum
101     to enable discerning the correct eigenvector even for networks with
102     multiple dominant eigenvalues.
103 
104     For directed graphs this is "left" eigenvector centrality which corresponds
105     to the in-edges in the graph. For out-edges eigenvector centrality
106     first reverse the graph with ``G.reverse()``.
107 
108     References
109     ----------
110     .. [1] Phillip Bonacich.
111        "Power and Centrality: A Family of Measures."
112        *American Journal of Sociology* 92(5):1170–1182, 1986
113        <http://www.leonidzhukov.net/hse/2014/socialnetworks/papers/Bonacich-Centrality.pdf>
114     .. [2] Mark E. J. Newman.
115        *Networks: An Introduction.*
116        Oxford University Press, USA, 2010, pp. 169.
117 
118     """
119     if len(G) == 0:
120         raise nx.NetworkXPointlessConcept('cannot compute centrality for the'
121                                           ' null graph')
122     # If no initial vector is provided, start with the all-ones vector.
123     if nstart is None:
124         nstart = {v: 1 for v in G}
125     if all(v == 0 for v in nstart.values()):
126         raise nx.NetworkXError('initial vector cannot have all zero values')
127     # Normalize the initial vector so that each entry is in [0, 1]. This is
128     # guaranteed to never have a divide-by-zero error by the previous line.
129     x = {k: v / sum(nstart.values()) for k, v in nstart.items()}
130     nnodes = G.number_of_nodes()
131     # make up to max_iter iterations
132     for i in range(max_iter):
133         xlast = x
134         x = xlast.copy()  # Start with xlast times I to iterate with (A+I)
135         # do the multiplication y^T = x^T A (left eigenvector)
136         for n in x:
137             for nbr in G[n]:
138                 x[nbr] += xlast[n] * G[n][nbr].get(weight, 1)
139         # Normalize the vector. The normalization denominator `norm`
140         # should never be zero by the Perron--Frobenius
141         # theorem. However, in case it is due to numerical error, we
142         # assume the norm to be one instead.
143         norm = sqrt(sum(z ** 2 for z in x.values())) or 1
144         x = {k: v / norm for k, v in x.items()}
145         # Check for convergence (in the L_1 norm).
146         if sum(abs(x[n] - xlast[n]) for n in x) < nnodes * tol:
147             return x
148     raise nx.PowerIterationFailedConvergence(max_iter)
149 
150 
151 def eigenvector_centrality_numpy(G, weight=None, max_iter=50, tol=0):
152     r"""Compute the eigenvector centrality for the graph G.
153 
154     Eigenvector centrality computes the centrality for a node based on the
155     centrality of its neighbors. The eigenvector centrality for node $i$ is
156 
157     .. math::
158 
159         Ax = \lambda x
160 
161     where $A$ is the adjacency matrix of the graph G with eigenvalue $\lambda$.
162     By virtue of the Perron–Frobenius theorem, there is a unique and positive
163     solution if $\lambda$ is the largest eigenvalue associated with the
164     eigenvector of the adjacency matrix $A$ ([2]_).
165 
166     Parameters
167     ----------
168     G : graph
169       A networkx graph
170 
171     weight : None or string, optional (default=None)
172       The name of the edge attribute used as weight.
173       If None, all edge weights are considered equal.
174 
175     max_iter : integer, optional (default=100)
176       Maximum number of iterations in power method.
177 
178     tol : float, optional (default=1.0e-6)
179        Relative accuracy for eigenvalues (stopping criterion).
180        The default value of 0 implies machine precision.
181 
182     Returns
183     -------
184     nodes : dictionary
185        Dictionary of nodes with eigenvector centrality as the value.
186 
187     Examples
188     --------
189     >>> G = nx.path_graph(4)
190     >>> centrality = nx.eigenvector_centrality_numpy(G)
191     >>> print(['{} {:0.2f}'.format(node, centrality[node]) for node in centrality])
192     ['0 0.37', '1 0.60', '2 0.60', '3 0.37']
193 
194     See Also
195     --------
196     eigenvector_centrality
197     pagerank
198     hits
199 
200     Notes
201     -----
202     The measure was introduced by [1]_.
203 
204     This algorithm uses the SciPy sparse eigenvalue solver (ARPACK) to
205     find the largest eigenvalue/eigenvector pair.
206 
207     For directed graphs this is "left" eigenvector centrality which corresponds
208     to the in-edges in the graph. For out-edges eigenvector centrality
209     first reverse the graph with ``G.reverse()``.
210 
211     Raises
212     ------
213     NetworkXPointlessConcept
214         If the graph ``G`` is the null graph.
215 
216     References
217     ----------
218     .. [1] Phillip Bonacich:
219        Power and Centrality: A Family of Measures.
220        American Journal of Sociology 92(5):1170–1182, 1986
221        http://www.leonidzhukov.net/hse/2014/socialnetworks/papers/Bonacich-Centrality.pdf
222     .. [2] Mark E. J. Newman:
223        Networks: An Introduction.
224        Oxford University Press, USA, 2010, pp. 169.
225     """
226     import scipy as sp
227     from scipy.sparse import linalg
228     if len(G) == 0:
229         raise nx.NetworkXPointlessConcept('cannot compute centrality for the'
230                                           ' null graph')
231     M = nx.to_scipy_sparse_matrix(G, nodelist=list(G), weight=weight,
232                                   dtype=float)
233     eigenvalue, eigenvector = linalg.eigs(M.T, k=1, which='LR',
234                                           maxiter=max_iter, tol=tol)
235     largest = eigenvector.flatten().real
236     norm = sp.sign(largest.sum()) * sp.linalg.norm(largest)
237     return dict(zip(G, largest / norm))
238 
239 
240 # fixture for nose tests
241 def setup_module(module):
242     from nose import SkipTest
243     try:
244         import scipy
245     except:
246         raise SkipTest("SciPy not available")
247
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/networkx/algorithms/centrality/eigenvector.py b/networkx/algorithms/centrality/eigenvector.py
--- a/networkx/algorithms/centrality/eigenvector.py
+++ b/networkx/algorithms/centrality/eigenvector.py
@@ -28,16 +28,16 @@
 
     Eigenvector centrality computes the centrality for a node based on the
     centrality of its neighbors. The eigenvector centrality for node $i$ is
+    the $i$-th element of the vector $x$ defined by the equation
 
     .. math::
 
         Ax = \lambda x
 
     where $A$ is the adjacency matrix of the graph `G` with eigenvalue
-    $\lambda$. By virtue of the Perron–Frobenius theorem, there is
-    a unique and positive solution if $\lambda$ is the largest
-    eigenvalue associated with the eigenvector of the adjacency matrix
-    $A$ ([2]_).
+    $\lambda$. By virtue of the Perron–Frobenius theorem, there is a unique
+    solution $x$, all of whose entries are positive, if $\lambda$ is the
+    largest eigenvalue of the adjacency matrix $A$ ([2]_).
 
     Parameters
     ----------

{"golden_diff": "diff --git a/networkx/algorithms/centrality/eigenvector.py b/networkx/algorithms/centrality/eigenvector.py\n--- a/networkx/algorithms/centrality/eigenvector.py\n+++ b/networkx/algorithms/centrality/eigenvector.py\n@@ -28,16 +28,16 @@\n \n     Eigenvector centrality computes the centrality for a node based on the\n     centrality of its neighbors. The eigenvector centrality for node $i$ is\n+    the $i$-th element of the vector $x$ defined by the equation\n \n     .. math::\n \n         Ax = \\lambda x\n \n     where $A$ is the adjacency matrix of the graph `G` with eigenvalue\n-    $\\lambda$. By virtue of the Perron\u2013Frobenius theorem, there is\n-    a unique and positive solution if $\\lambda$ is the largest\n-    eigenvalue associated with the eigenvector of the adjacency matrix\n-    $A$ ([2]_).\n+    $\\lambda$. By virtue of the Perron\u2013Frobenius theorem, there is a unique\n+    solution $x$, all of whose entries are positive, if $\\lambda$ is the\n+    largest eigenvalue of the adjacency matrix $A$ ([2]_).\n \n     Parameters\n     ----------\n", "issue": "eigenvector_centrality() docstring needs rewording\nThe docstring for eigenvector_centrality() refers to the cluster centrality of a node i and then proceeds to give an equation for the vector of cluster centrality for all nodes. Suggest rewording similar to the katz_similarity() method.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#    Copyright (C) 2004-2018 by\n#    Aric Hagberg <hagberg@lanl.gov>\n#    Dan Schult <dschult@colgate.edu>\n#    Pieter Swart <swart@lanl.gov>\n#    All rights reserved.\n#    BSD license.\n#\n# Authors:\n#     Aric Hagberg <aric.hagberg@gmail.com>\n#     Pieter Swart <swart@lanl.gov>\n#     Sasha Gutfraind <ag362@cornell.edu>\n\"\"\"Functions for computing eigenvector centrality.\"\"\"\nfrom __future__ import division\n\nfrom math import sqrt\n\nimport networkx as nx\nfrom networkx.utils import not_implemented_for\n\n__all__ = ['eigenvector_centrality', 'eigenvector_centrality_numpy']\n\n\n@not_implemented_for('multigraph')\ndef eigenvector_centrality(G, max_iter=100, tol=1.0e-6, nstart=None,\n                           weight=None):\n    r\"\"\"Compute the eigenvector centrality for the graph `G`.\n\n    Eigenvector centrality computes the centrality for a node based on the\n    centrality of its neighbors. The eigenvector centrality for node $i$ is\n\n    .. math::\n\n        Ax = \\lambda x\n\n    where $A$ is the adjacency matrix of the graph `G` with eigenvalue\n    $\\lambda$. By virtue of the Perron\u2013Frobenius theorem, there is\n    a unique and positive solution if $\\lambda$ is the largest\n    eigenvalue associated with the eigenvector of the adjacency matrix\n    $A$ ([2]_).\n\n    Parameters\n    ----------\n    G : graph\n      A networkx graph\n\n    max_iter : integer, optional (default=100)\n      Maximum number of iterations in power method.\n\n    tol : float, optional (default=1.0e-6)\n      Error tolerance used to check convergence in power method iteration.\n\n    nstart : dictionary, optional (default=None)\n      Starting value of eigenvector iteration for each node.\n\n    weight : None or string, optional (default=None)\n      If None, all edge weights are considered equal.\n      Otherwise holds the name of the edge attribute used as weight.\n\n    Returns\n    -------\n    nodes : dictionary\n       Dictionary of nodes with eigenvector centrality as the value.\n\n    Examples\n    --------\n    >>> G = nx.path_graph(4)\n    >>> centrality = nx.eigenvector_centrality(G)\n    >>> sorted((v, '{:0.2f}'.format(c)) for v, c in centrality.items())\n    [(0, '0.37'), (1, '0.60'), (2, '0.60'), (3, '0.37')]\n\n    Raises\n    ------\n    NetworkXPointlessConcept\n        If the graph `G` is the null graph.\n\n    NetworkXError\n        If each value in `nstart` is zero.\n\n    PowerIterationFailedConvergence\n        If the algorithm fails to converge to the specified tolerance\n        within the specified number of iterations of the power iteration\n        method.\n\n    See Also\n    --------\n    eigenvector_centrality_numpy\n    pagerank\n    hits\n\n    Notes\n    -----\n    The measure was introduced by [1]_ and is discussed in [2]_.\n\n    The power iteration method is used to compute the eigenvector and\n    convergence is **not** guaranteed. Our method stops after ``max_iter``\n    iterations or when the change in the computed vector between two\n    iterations is smaller than an error tolerance of\n    ``G.number_of_nodes() * tol``. This implementation uses ($A + I$)\n    rather than the adjacency matrix $A$ because it shifts the spectrum\n    to enable discerning the correct eigenvector even for networks with\n    multiple dominant eigenvalues.\n\n    For directed graphs this is \"left\" eigenvector centrality which corresponds\n    to the in-edges in the graph. For out-edges eigenvector centrality\n    first reverse the graph with ``G.reverse()``.\n\n    References\n    ----------\n    .. [1] Phillip Bonacich.\n       \"Power and Centrality: A Family of Measures.\"\n       *American Journal of Sociology* 92(5):1170\u20131182, 1986\n       <http://www.leonidzhukov.net/hse/2014/socialnetworks/papers/Bonacich-Centrality.pdf>\n    .. [2] Mark E. J. Newman.\n       *Networks: An Introduction.*\n       Oxford University Press, USA, 2010, pp. 169.\n\n    \"\"\"\n    if len(G) == 0:\n        raise nx.NetworkXPointlessConcept('cannot compute centrality for the'\n                                          ' null graph')\n    # If no initial vector is provided, start with the all-ones vector.\n    if nstart is None:\n        nstart = {v: 1 for v in G}\n    if all(v == 0 for v in nstart.values()):\n        raise nx.NetworkXError('initial vector cannot have all zero values')\n    # Normalize the initial vector so that each entry is in [0, 1]. This is\n    # guaranteed to never have a divide-by-zero error by the previous line.\n    x = {k: v / sum(nstart.values()) for k, v in nstart.items()}\n    nnodes = G.number_of_nodes()\n    # make up to max_iter iterations\n    for i in range(max_iter):\n        xlast = x\n        x = xlast.copy()  # Start with xlast times I to iterate with (A+I)\n        # do the multiplication y^T = x^T A (left eigenvector)\n        for n in x:\n            for nbr in G[n]:\n                x[nbr] += xlast[n] * G[n][nbr].get(weight, 1)\n        # Normalize the vector. The normalization denominator `norm`\n        # should never be zero by the Perron--Frobenius\n        # theorem. However, in case it is due to numerical error, we\n        # assume the norm to be one instead.\n        norm = sqrt(sum(z ** 2 for z in x.values())) or 1\n        x = {k: v / norm for k, v in x.items()}\n        # Check for convergence (in the L_1 norm).\n        if sum(abs(x[n] - xlast[n]) for n in x) < nnodes * tol:\n            return x\n    raise nx.PowerIterationFailedConvergence(max_iter)\n\n\ndef eigenvector_centrality_numpy(G, weight=None, max_iter=50, tol=0):\n    r\"\"\"Compute the eigenvector centrality for the graph G.\n\n    Eigenvector centrality computes the centrality for a node based on the\n    centrality of its neighbors. The eigenvector centrality for node $i$ is\n\n    .. math::\n\n        Ax = \\lambda x\n\n    where $A$ is the adjacency matrix of the graph G with eigenvalue $\\lambda$.\n    By virtue of the Perron\u2013Frobenius theorem, there is a unique and positive\n    solution if $\\lambda$ is the largest eigenvalue associated with the\n    eigenvector of the adjacency matrix $A$ ([2]_).\n\n    Parameters\n    ----------\n    G : graph\n      A networkx graph\n\n    weight : None or string, optional (default=None)\n      The name of the edge attribute used as weight.\n      If None, all edge weights are considered equal.\n\n    max_iter : integer, optional (default=100)\n      Maximum number of iterations in power method.\n\n    tol : float, optional (default=1.0e-6)\n       Relative accuracy for eigenvalues (stopping criterion).\n       The default value of 0 implies machine precision.\n\n    Returns\n    -------\n    nodes : dictionary\n       Dictionary of nodes with eigenvector centrality as the value.\n\n    Examples\n    --------\n    >>> G = nx.path_graph(4)\n    >>> centrality = nx.eigenvector_centrality_numpy(G)\n    >>> print(['{} {:0.2f}'.format(node, centrality[node]) for node in centrality])\n    ['0 0.37', '1 0.60', '2 0.60', '3 0.37']\n\n    See Also\n    --------\n    eigenvector_centrality\n    pagerank\n    hits\n\n    Notes\n    -----\n    The measure was introduced by [1]_.\n\n    This algorithm uses the SciPy sparse eigenvalue solver (ARPACK) to\n    find the largest eigenvalue/eigenvector pair.\n\n    For directed graphs this is \"left\" eigenvector centrality which corresponds\n    to the in-edges in the graph. For out-edges eigenvector centrality\n    first reverse the graph with ``G.reverse()``.\n\n    Raises\n    ------\n    NetworkXPointlessConcept\n        If the graph ``G`` is the null graph.\n\n    References\n    ----------\n    .. [1] Phillip Bonacich:\n       Power and Centrality: A Family of Measures.\n       American Journal of Sociology 92(5):1170\u20131182, 1986\n       http://www.leonidzhukov.net/hse/2014/socialnetworks/papers/Bonacich-Centrality.pdf\n    .. [2] Mark E. J. Newman:\n       Networks: An Introduction.\n       Oxford University Press, USA, 2010, pp. 169.\n    \"\"\"\n    import scipy as sp\n    from scipy.sparse import linalg\n    if len(G) == 0:\n        raise nx.NetworkXPointlessConcept('cannot compute centrality for the'\n                                          ' null graph')\n    M = nx.to_scipy_sparse_matrix(G, nodelist=list(G), weight=weight,\n                                  dtype=float)\n    eigenvalue, eigenvector = linalg.eigs(M.T, k=1, which='LR',\n                                          maxiter=max_iter, tol=tol)\n    largest = eigenvector.flatten().real\n    norm = sp.sign(largest.sum()) * sp.linalg.norm(largest)\n    return dict(zip(G, largest / norm))\n\n\n# fixture for nose tests\ndef setup_module(module):\n    from nose import SkipTest\n    try:\n        import scipy\n    except:\n        raise SkipTest(\"SciPy not available\")\n", "path": "networkx/algorithms/centrality/eigenvector.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n#    Copyright (C) 2004-2018 by\n#    Aric Hagberg <hagberg@lanl.gov>\n#    Dan Schult <dschult@colgate.edu>\n#    Pieter Swart <swart@lanl.gov>\n#    All rights reserved.\n#    BSD license.\n#\n# Authors:\n#     Aric Hagberg <aric.hagberg@gmail.com>\n#     Pieter Swart <swart@lanl.gov>\n#     Sasha Gutfraind <ag362@cornell.edu>\n\"\"\"Functions for computing eigenvector centrality.\"\"\"\nfrom __future__ import division\n\nfrom math import sqrt\n\nimport networkx as nx\nfrom networkx.utils import not_implemented_for\n\n__all__ = ['eigenvector_centrality', 'eigenvector_centrality_numpy']\n\n\n@not_implemented_for('multigraph')\ndef eigenvector_centrality(G, max_iter=100, tol=1.0e-6, nstart=None,\n                           weight=None):\n    r\"\"\"Compute the eigenvector centrality for the graph `G`.\n\n    Eigenvector centrality computes the centrality for a node based on the\n    centrality of its neighbors. The eigenvector centrality for node $i$ is\n    the $i$-th element of the vector $x$ defined by the equation\n\n    .. math::\n\n        Ax = \\lambda x\n\n    where $A$ is the adjacency matrix of the graph `G` with eigenvalue\n    $\\lambda$. By virtue of the Perron\u2013Frobenius theorem, there is a unique\n    solution $x$, all of whose entries are positive, if $\\lambda$ is the\n    largest eigenvalue of the adjacency matrix $A$ ([2]_).\n\n    Parameters\n    ----------\n    G : graph\n      A networkx graph\n\n    max_iter : integer, optional (default=100)\n      Maximum number of iterations in power method.\n\n    tol : float, optional (default=1.0e-6)\n      Error tolerance used to check convergence in power method iteration.\n\n    nstart : dictionary, optional (default=None)\n      Starting value of eigenvector iteration for each node.\n\n    weight : None or string, optional (default=None)\n      If None, all edge weights are considered equal.\n      Otherwise holds the name of the edge attribute used as weight.\n\n    Returns\n    -------\n    nodes : dictionary\n       Dictionary of nodes with eigenvector centrality as the value.\n\n    Examples\n    --------\n    >>> G = nx.path_graph(4)\n    >>> centrality = nx.eigenvector_centrality(G)\n    >>> sorted((v, '{:0.2f}'.format(c)) for v, c in centrality.items())\n    [(0, '0.37'), (1, '0.60'), (2, '0.60'), (3, '0.37')]\n\n    Raises\n    ------\n    NetworkXPointlessConcept\n        If the graph `G` is the null graph.\n\n    NetworkXError\n        If each value in `nstart` is zero.\n\n    PowerIterationFailedConvergence\n        If the algorithm fails to converge to the specified tolerance\n        within the specified number of iterations of the power iteration\n        method.\n\n    See Also\n    --------\n    eigenvector_centrality_numpy\n    pagerank\n    hits\n\n    Notes\n    -----\n    The measure was introduced by [1]_ and is discussed in [2]_.\n\n    The power iteration method is used to compute the eigenvector and\n    convergence is **not** guaranteed. Our method stops after ``max_iter``\n    iterations or when the change in the computed vector between two\n    iterations is smaller than an error tolerance of\n    ``G.number_of_nodes() * tol``. This implementation uses ($A + I$)\n    rather than the adjacency matrix $A$ because it shifts the spectrum\n    to enable discerning the correct eigenvector even for networks with\n    multiple dominant eigenvalues.\n\n    For directed graphs this is \"left\" eigenvector centrality which corresponds\n    to the in-edges in the graph. For out-edges eigenvector centrality\n    first reverse the graph with ``G.reverse()``.\n\n    References\n    ----------\n    .. [1] Phillip Bonacich.\n       \"Power and Centrality: A Family of Measures.\"\n       *American Journal of Sociology* 92(5):1170\u20131182, 1986\n       <http://www.leonidzhukov.net/hse/2014/socialnetworks/papers/Bonacich-Centrality.pdf>\n    .. [2] Mark E. J. Newman.\n       *Networks: An Introduction.*\n       Oxford University Press, USA, 2010, pp. 169.\n\n    \"\"\"\n    if len(G) == 0:\n        raise nx.NetworkXPointlessConcept('cannot compute centrality for the'\n                                          ' null graph')\n    # If no initial vector is provided, start with the all-ones vector.\n    if nstart is None:\n        nstart = {v: 1 for v in G}\n    if all(v == 0 for v in nstart.values()):\n        raise nx.NetworkXError('initial vector cannot have all zero values')\n    # Normalize the initial vector so that each entry is in [0, 1]. This is\n    # guaranteed to never have a divide-by-zero error by the previous line.\n    x = {k: v / sum(nstart.values()) for k, v in nstart.items()}\n    nnodes = G.number_of_nodes()\n    # make up to max_iter iterations\n    for i in range(max_iter):\n        xlast = x\n        x = xlast.copy()  # Start with xlast times I to iterate with (A+I)\n        # do the multiplication y^T = x^T A (left eigenvector)\n        for n in x:\n            for nbr in G[n]:\n                x[nbr] += xlast[n] * G[n][nbr].get(weight, 1)\n        # Normalize the vector. The normalization denominator `norm`\n        # should never be zero by the Perron--Frobenius\n        # theorem. However, in case it is due to numerical error, we\n        # assume the norm to be one instead.\n        norm = sqrt(sum(z ** 2 for z in x.values())) or 1\n        x = {k: v / norm for k, v in x.items()}\n        # Check for convergence (in the L_1 norm).\n        if sum(abs(x[n] - xlast[n]) for n in x) < nnodes * tol:\n            return x\n    raise nx.PowerIterationFailedConvergence(max_iter)\n\n\ndef eigenvector_centrality_numpy(G, weight=None, max_iter=50, tol=0):\n    r\"\"\"Compute the eigenvector centrality for the graph G.\n\n    Eigenvector centrality computes the centrality for a node based on the\n    centrality of its neighbors. The eigenvector centrality for node $i$ is\n\n    .. math::\n\n        Ax = \\lambda x\n\n    where $A$ is the adjacency matrix of the graph G with eigenvalue $\\lambda$.\n    By virtue of the Perron\u2013Frobenius theorem, there is a unique and positive\n    solution if $\\lambda$ is the largest eigenvalue associated with the\n    eigenvector of the adjacency matrix $A$ ([2]_).\n\n    Parameters\n    ----------\n    G : graph\n      A networkx graph\n\n    weight : None or string, optional (default=None)\n      The name of the edge attribute used as weight.\n      If None, all edge weights are considered equal.\n\n    max_iter : integer, optional (default=100)\n      Maximum number of iterations in power method.\n\n    tol : float, optional (default=1.0e-6)\n       Relative accuracy for eigenvalues (stopping criterion).\n       The default value of 0 implies machine precision.\n\n    Returns\n    -------\n    nodes : dictionary\n       Dictionary of nodes with eigenvector centrality as the value.\n\n    Examples\n    --------\n    >>> G = nx.path_graph(4)\n    >>> centrality = nx.eigenvector_centrality_numpy(G)\n    >>> print(['{} {:0.2f}'.format(node, centrality[node]) for node in centrality])\n    ['0 0.37', '1 0.60', '2 0.60', '3 0.37']\n\n    See Also\n    --------\n    eigenvector_centrality\n    pagerank\n    hits\n\n    Notes\n    -----\n    The measure was introduced by [1]_.\n\n    This algorithm uses the SciPy sparse eigenvalue solver (ARPACK) to\n    find the largest eigenvalue/eigenvector pair.\n\n    For directed graphs this is \"left\" eigenvector centrality which corresponds\n    to the in-edges in the graph. For out-edges eigenvector centrality\n    first reverse the graph with ``G.reverse()``.\n\n    Raises\n    ------\n    NetworkXPointlessConcept\n        If the graph ``G`` is the null graph.\n\n    References\n    ----------\n    .. [1] Phillip Bonacich:\n       Power and Centrality: A Family of Measures.\n       American Journal of Sociology 92(5):1170\u20131182, 1986\n       http://www.leonidzhukov.net/hse/2014/socialnetworks/papers/Bonacich-Centrality.pdf\n    .. [2] Mark E. J. Newman:\n       Networks: An Introduction.\n       Oxford University Press, USA, 2010, pp. 169.\n    \"\"\"\n    import scipy as sp\n    from scipy.sparse import linalg\n    if len(G) == 0:\n        raise nx.NetworkXPointlessConcept('cannot compute centrality for the'\n                                          ' null graph')\n    M = nx.to_scipy_sparse_matrix(G, nodelist=list(G), weight=weight,\n                                  dtype=float)\n    eigenvalue, eigenvector = linalg.eigs(M.T, k=1, which='LR',\n                                          maxiter=max_iter, tol=tol)\n    largest = eigenvector.flatten().real\n    norm = sp.sign(largest.sum()) * sp.linalg.norm(largest)\n    return dict(zip(G, largest / norm))\n\n\n# fixture for nose tests\ndef setup_module(module):\n    from nose import SkipTest\n    try:\n        import scipy\n    except:\n        raise SkipTest(\"SciPy not available\")\n", "path": "networkx/algorithms/centrality/eigenvector.py"}]}