We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Misleading description in the doc
In this page
https://networkx.github.io/documentation/stable/reference/algorithms/generated/networkx.algorithms.structuralholes.effective_size.html
The description of *Return* is "Dictionary with nodes as keys and the constraint on the node as values."
But this is effective size. I think it should be  "Dictionary with nodes as keys and the **effective size of** the node as values."

--- 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/structuralholes.py`
Content:
```
1 """Functions for computing measures of structural holes."""
2 
3 import networkx as nx
4 
5 __all__ = ['constraint', 'local_constraint', 'effective_size']
6 
7 
8 def mutual_weight(G, u, v, weight=None):
9     """Returns the sum of the weights of the edge from `u` to `v` and
10     the edge from `v` to `u` in `G`.
11 
12     `weight` is the edge data key that represents the edge weight. If
13     the specified key is `None` or is not in the edge data for an edge,
14     that edge is assumed to have weight 1.
15 
16     Pre-conditions: `u` and `v` must both be in `G`.
17 
18     """
19     try:
20         a_uv = G[u][v].get(weight, 1)
21     except KeyError:
22         a_uv = 0
23     try:
24         a_vu = G[v][u].get(weight, 1)
25     except KeyError:
26         a_vu = 0
27     return a_uv + a_vu
28 
29 
30 def normalized_mutual_weight(G, u, v, norm=sum, weight=None):
31     """Returns normalized mutual weight of the edges from `u` to `v`
32     with respect to the mutual weights of the neighbors of `u` in `G`.
33 
34     `norm` specifies how the normalization factor is computed. It must
35     be a function that takes a single argument and returns a number.
36     The argument will be an iterable of mutual weights
37     of pairs ``(u, w)``, where ``w`` ranges over each (in- and
38     out-)neighbor of ``u``. Commons values for `normalization` are
39     ``sum`` and ``max``.
40 
41     `weight` can be ``None`` or a string, if None, all edge weights
42     are considered equal. Otherwise holds the name of the edge
43     attribute used as weight.
44 
45     """
46     scale = norm(mutual_weight(G, u, w, weight)
47                  for w in set(nx.all_neighbors(G, u)))
48     return 0 if scale == 0 else mutual_weight(G, u, v, weight) / scale
49 
50 
51 def effective_size(G, nodes=None, weight=None):
52     r"""Returns the effective size of all nodes in the graph ``G``.
53 
54     The *effective size* of a node's ego network is based on the concept
55     of redundancy. A person's ego network has redundancy to the extent
56     that her contacts are connected to each other as well. The
57     nonredundant part of a person's relationships it's the effective
58     size of her ego network [1]_.  Formally, the effective size of a
59     node $u$, denoted $e(u)$, is defined by
60 
61     .. math::
62 
63        e(u) = \sum_{v \in N(u) \setminus \{u\}}
64        \left(1 - \sum_{w \in N(v)} p_{uw} m_{vw}\right)
65 
66     where $N(u)$ is the set of neighbors of $u$ and $p_{uw}$ is the
67     normalized mutual weight of the (directed or undirected) edges
68     joining $u$ and $v$, for each vertex $u$ and $v$ [1]_. And $m_{vw}$
69     is the mutual weight of $v$ and $w$ divided by $v$ highest mutual
70     weight with any of its neighbors. The *mutual weight* of $u$ and $v$
71     is the sum of the weights of edges joining them (edge weights are
72     assumed to be one if the graph is unweighted).
73 
74     For the case of unweighted and undirected graphs, Borgatti proposed
75     a simplified formula to compute effective size [2]_
76 
77     .. math::
78 
79        e(u) = n - \frac{2t}{n}
80 
81     where `t` is the number of ties in the ego network (not including
82     ties to ego) and `n` is the number of nodes (excluding ego).
83 
84     Parameters
85     ----------
86     G : NetworkX graph
87         The graph containing ``v``. Directed graphs are treated like
88         undirected graphs when computing neighbors of ``v``.
89 
90     nodes : container, optional
91         Container of nodes in the graph ``G`` to compute the effective size.
92         If None, the effective size of every node is computed.
93 
94     weight : None or string, optional
95       If None, all edge weights are considered equal.
96       Otherwise holds the name of the edge attribute used as weight.
97 
98     Returns
99     -------
100     dict
101         Dictionary with nodes as keys and the constraint on the node as values.
102 
103     Notes
104     -----
105     Burt also defined the related concept of *efficiency* of a node's ego
106     network, which is its effective size divided by the degree of that
107     node [1]_. So you can easily compute efficiency:
108 
109     >>> G = nx.DiGraph()
110     >>> G.add_edges_from([(0, 1), (0, 2), (1, 0), (2, 1)])
111     >>> esize = nx.effective_size(G)
112     >>> efficiency = {n: v / G.degree(n) for n, v in esize.items()}
113 
114     See also
115     --------
116     constraint
117 
118     References
119     ----------
120     .. [1] Burt, Ronald S.
121            *Structural Holes: The Social Structure of Competition.*
122            Cambridge: Harvard University Press, 1995.
123 
124     .. [2] Borgatti, S.
125            "Structural Holes: Unpacking Burt's Redundancy Measures"
126            CONNECTIONS 20(1):35-38.
127            http://www.analytictech.com/connections/v20(1)/holes.htm
128 
129     """
130     def redundancy(G, u, v, weight=None):
131         nmw = normalized_mutual_weight
132         r = sum(nmw(G, u, w, weight=weight) * nmw(G, v, w, norm=max, weight=weight)
133                 for w in set(nx.all_neighbors(G, u)))
134         return 1 - r
135     effective_size = {}
136     if nodes is None:
137         nodes = G
138     # Use Borgatti's simplified formula for unweighted and undirected graphs
139     if not G.is_directed() and weight is None:
140         for v in nodes:
141             # Effective size is not defined for isolated nodes
142             if len(G[v]) == 0:
143                 effective_size[v] = float('nan')
144                 continue
145             E = nx.ego_graph(G, v, center=False, undirected=True)
146             effective_size[v] = len(E) - (2 * E.size()) / len(E)
147     else:
148         for v in nodes:
149             # Effective size is not defined for isolated nodes
150             if len(G[v]) == 0:
151                 effective_size[v] = float('nan')
152                 continue
153             effective_size[v] = sum(redundancy(G, v, u, weight)
154                                     for u in set(nx.all_neighbors(G, v)))
155     return effective_size
156 
157 
158 def constraint(G, nodes=None, weight=None):
159     r"""Returns the constraint on all nodes in the graph ``G``.
160 
161     The *constraint* is a measure of the extent to which a node *v* is
162     invested in those nodes that are themselves invested in the
163     neighbors of *v*. Formally, the *constraint on v*, denoted `c(v)`,
164     is defined by
165 
166     .. math::
167 
168        c(v) = \sum_{w \in N(v) \setminus \{v\}} \ell(v, w)
169 
170     where `N(v)` is the subset of the neighbors of `v` that are either
171     predecessors or successors of `v` and `\ell(v, w)` is the local
172     constraint on `v` with respect to `w` [1]_. For the definition of local
173     constraint, see :func:`local_constraint`.
174 
175     Parameters
176     ----------
177     G : NetworkX graph
178         The graph containing ``v``. This can be either directed or undirected.
179 
180     nodes : container, optional
181         Container of nodes in the graph ``G`` to compute the constraint. If
182         None, the constraint of every node is computed.
183 
184     weight : None or string, optional
185       If None, all edge weights are considered equal.
186       Otherwise holds the name of the edge attribute used as weight.
187 
188     Returns
189     -------
190     dict
191         Dictionary with nodes as keys and the constraint on the node as values.
192 
193     See also
194     --------
195     local_constraint
196 
197     References
198     ----------
199     .. [1] Burt, Ronald S.
200            "Structural holes and good ideas".
201            American Journal of Sociology (110): 349–399.
202 
203     """
204     if nodes is None:
205         nodes = G
206     constraint = {}
207     for v in nodes:
208         # Constraint is not defined for isolated nodes
209         if len(G[v]) == 0:
210             constraint[v] = float('nan')
211             continue
212         constraint[v] = sum(local_constraint(G, v, n, weight)
213                             for n in set(nx.all_neighbors(G, v)))
214     return constraint
215 
216 
217 def local_constraint(G, u, v, weight=None):
218     r"""Returns the local constraint on the node ``u`` with respect to
219     the node ``v`` in the graph ``G``.
220 
221     Formally, the *local constraint on u with respect to v*, denoted
222     $\ell(v)$, is defined by
223 
224     .. math::
225 
226        \ell(u, v) = \left(p_{uv} + \sum_{w \in N(v)} p_{uw} p{wv}\right)^2,
227 
228     where $N(v)$ is the set of neighbors of $v$ and $p_{uv}$ is the
229     normalized mutual weight of the (directed or undirected) edges
230     joining $u$ and $v$, for each vertex $u$ and $v$ [1]_. The *mutual
231     weight* of $u$ and $v$ is the sum of the weights of edges joining
232     them (edge weights are assumed to be one if the graph is
233     unweighted).
234 
235     Parameters
236     ----------
237     G : NetworkX graph
238         The graph containing ``u`` and ``v``. This can be either
239         directed or undirected.
240 
241     u : node
242         A node in the graph ``G``.
243 
244     v : node
245         A node in the graph ``G``.
246 
247     weight : None or string, optional
248       If None, all edge weights are considered equal.
249       Otherwise holds the name of the edge attribute used as weight.
250 
251     Returns
252     -------
253     float
254         The constraint of the node ``v`` in the graph ``G``.
255 
256     See also
257     --------
258     constraint
259 
260     References
261     ----------
262     .. [1] Burt, Ronald S.
263            "Structural holes and good ideas".
264            American Journal of Sociology (110): 349–399.
265 
266     """
267     nmw = normalized_mutual_weight
268     direct = nmw(G, u, v, weight=weight)
269     indirect = sum(nmw(G, u, w, weight=weight) * nmw(G, w, v, weight=weight)
270                    for w in set(nx.all_neighbors(G, u)))
271     return (direct + indirect) ** 2
272
```
--- 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/structuralholes.py b/networkx/algorithms/structuralholes.py
--- a/networkx/algorithms/structuralholes.py
+++ b/networkx/algorithms/structuralholes.py
@@ -98,7 +98,7 @@
     Returns
     -------
     dict
-        Dictionary with nodes as keys and the constraint on the node as values.
+        Dictionary with nodes as keys and the effective size of the node as values.
 
     Notes
     -----

{"golden_diff": "diff --git a/networkx/algorithms/structuralholes.py b/networkx/algorithms/structuralholes.py\n--- a/networkx/algorithms/structuralholes.py\n+++ b/networkx/algorithms/structuralholes.py\n@@ -98,7 +98,7 @@\n     Returns\n     -------\n     dict\n-        Dictionary with nodes as keys and the constraint on the node as values.\n+        Dictionary with nodes as keys and the effective size of the node as values.\n \n     Notes\n     -----\n", "issue": "Misleading description in the doc\nIn this page\r\nhttps://networkx.github.io/documentation/stable/reference/algorithms/generated/networkx.algorithms.structuralholes.effective_size.html\r\nThe description of *Return* is \"Dictionary with nodes as keys and the constraint on the node as values.\"\r\nBut this is effective size. I think it should be  \"Dictionary with nodes as keys and the **effective size of** the node as values.\"\n", "before_files": [{"content": "\"\"\"Functions for computing measures of structural holes.\"\"\"\n\nimport networkx as nx\n\n__all__ = ['constraint', 'local_constraint', 'effective_size']\n\n\ndef mutual_weight(G, u, v, weight=None):\n    \"\"\"Returns the sum of the weights of the edge from `u` to `v` and\n    the edge from `v` to `u` in `G`.\n\n    `weight` is the edge data key that represents the edge weight. If\n    the specified key is `None` or is not in the edge data for an edge,\n    that edge is assumed to have weight 1.\n\n    Pre-conditions: `u` and `v` must both be in `G`.\n\n    \"\"\"\n    try:\n        a_uv = G[u][v].get(weight, 1)\n    except KeyError:\n        a_uv = 0\n    try:\n        a_vu = G[v][u].get(weight, 1)\n    except KeyError:\n        a_vu = 0\n    return a_uv + a_vu\n\n\ndef normalized_mutual_weight(G, u, v, norm=sum, weight=None):\n    \"\"\"Returns normalized mutual weight of the edges from `u` to `v`\n    with respect to the mutual weights of the neighbors of `u` in `G`.\n\n    `norm` specifies how the normalization factor is computed. It must\n    be a function that takes a single argument and returns a number.\n    The argument will be an iterable of mutual weights\n    of pairs ``(u, w)``, where ``w`` ranges over each (in- and\n    out-)neighbor of ``u``. Commons values for `normalization` are\n    ``sum`` and ``max``.\n\n    `weight` can be ``None`` or a string, if None, all edge weights\n    are considered equal. Otherwise holds the name of the edge\n    attribute used as weight.\n\n    \"\"\"\n    scale = norm(mutual_weight(G, u, w, weight)\n                 for w in set(nx.all_neighbors(G, u)))\n    return 0 if scale == 0 else mutual_weight(G, u, v, weight) / scale\n\n\ndef effective_size(G, nodes=None, weight=None):\n    r\"\"\"Returns the effective size of all nodes in the graph ``G``.\n\n    The *effective size* of a node's ego network is based on the concept\n    of redundancy. A person's ego network has redundancy to the extent\n    that her contacts are connected to each other as well. The\n    nonredundant part of a person's relationships it's the effective\n    size of her ego network [1]_.  Formally, the effective size of a\n    node $u$, denoted $e(u)$, is defined by\n\n    .. math::\n\n       e(u) = \\sum_{v \\in N(u) \\setminus \\{u\\}}\n       \\left(1 - \\sum_{w \\in N(v)} p_{uw} m_{vw}\\right)\n\n    where $N(u)$ is the set of neighbors of $u$ and $p_{uw}$ is the\n    normalized mutual weight of the (directed or undirected) edges\n    joining $u$ and $v$, for each vertex $u$ and $v$ [1]_. And $m_{vw}$\n    is the mutual weight of $v$ and $w$ divided by $v$ highest mutual\n    weight with any of its neighbors. The *mutual weight* of $u$ and $v$\n    is the sum of the weights of edges joining them (edge weights are\n    assumed to be one if the graph is unweighted).\n\n    For the case of unweighted and undirected graphs, Borgatti proposed\n    a simplified formula to compute effective size [2]_\n\n    .. math::\n\n       e(u) = n - \\frac{2t}{n}\n\n    where `t` is the number of ties in the ego network (not including\n    ties to ego) and `n` is the number of nodes (excluding ego).\n\n    Parameters\n    ----------\n    G : NetworkX graph\n        The graph containing ``v``. Directed graphs are treated like\n        undirected graphs when computing neighbors of ``v``.\n\n    nodes : container, optional\n        Container of nodes in the graph ``G`` to compute the effective size.\n        If None, the effective size of every node is computed.\n\n    weight : None or string, optional\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    dict\n        Dictionary with nodes as keys and the constraint on the node as values.\n\n    Notes\n    -----\n    Burt also defined the related concept of *efficiency* of a node's ego\n    network, which is its effective size divided by the degree of that\n    node [1]_. So you can easily compute efficiency:\n\n    >>> G = nx.DiGraph()\n    >>> G.add_edges_from([(0, 1), (0, 2), (1, 0), (2, 1)])\n    >>> esize = nx.effective_size(G)\n    >>> efficiency = {n: v / G.degree(n) for n, v in esize.items()}\n\n    See also\n    --------\n    constraint\n\n    References\n    ----------\n    .. [1] Burt, Ronald S.\n           *Structural Holes: The Social Structure of Competition.*\n           Cambridge: Harvard University Press, 1995.\n\n    .. [2] Borgatti, S.\n           \"Structural Holes: Unpacking Burt's Redundancy Measures\"\n           CONNECTIONS 20(1):35-38.\n           http://www.analytictech.com/connections/v20(1)/holes.htm\n\n    \"\"\"\n    def redundancy(G, u, v, weight=None):\n        nmw = normalized_mutual_weight\n        r = sum(nmw(G, u, w, weight=weight) * nmw(G, v, w, norm=max, weight=weight)\n                for w in set(nx.all_neighbors(G, u)))\n        return 1 - r\n    effective_size = {}\n    if nodes is None:\n        nodes = G\n    # Use Borgatti's simplified formula for unweighted and undirected graphs\n    if not G.is_directed() and weight is None:\n        for v in nodes:\n            # Effective size is not defined for isolated nodes\n            if len(G[v]) == 0:\n                effective_size[v] = float('nan')\n                continue\n            E = nx.ego_graph(G, v, center=False, undirected=True)\n            effective_size[v] = len(E) - (2 * E.size()) / len(E)\n    else:\n        for v in nodes:\n            # Effective size is not defined for isolated nodes\n            if len(G[v]) == 0:\n                effective_size[v] = float('nan')\n                continue\n            effective_size[v] = sum(redundancy(G, v, u, weight)\n                                    for u in set(nx.all_neighbors(G, v)))\n    return effective_size\n\n\ndef constraint(G, nodes=None, weight=None):\n    r\"\"\"Returns the constraint on all nodes in the graph ``G``.\n\n    The *constraint* is a measure of the extent to which a node *v* is\n    invested in those nodes that are themselves invested in the\n    neighbors of *v*. Formally, the *constraint on v*, denoted `c(v)`,\n    is defined by\n\n    .. math::\n\n       c(v) = \\sum_{w \\in N(v) \\setminus \\{v\\}} \\ell(v, w)\n\n    where `N(v)` is the subset of the neighbors of `v` that are either\n    predecessors or successors of `v` and `\\ell(v, w)` is the local\n    constraint on `v` with respect to `w` [1]_. For the definition of local\n    constraint, see :func:`local_constraint`.\n\n    Parameters\n    ----------\n    G : NetworkX graph\n        The graph containing ``v``. This can be either directed or undirected.\n\n    nodes : container, optional\n        Container of nodes in the graph ``G`` to compute the constraint. If\n        None, the constraint of every node is computed.\n\n    weight : None or string, optional\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    dict\n        Dictionary with nodes as keys and the constraint on the node as values.\n\n    See also\n    --------\n    local_constraint\n\n    References\n    ----------\n    .. [1] Burt, Ronald S.\n           \"Structural holes and good ideas\".\n           American Journal of Sociology (110): 349\u2013399.\n\n    \"\"\"\n    if nodes is None:\n        nodes = G\n    constraint = {}\n    for v in nodes:\n        # Constraint is not defined for isolated nodes\n        if len(G[v]) == 0:\n            constraint[v] = float('nan')\n            continue\n        constraint[v] = sum(local_constraint(G, v, n, weight)\n                            for n in set(nx.all_neighbors(G, v)))\n    return constraint\n\n\ndef local_constraint(G, u, v, weight=None):\n    r\"\"\"Returns the local constraint on the node ``u`` with respect to\n    the node ``v`` in the graph ``G``.\n\n    Formally, the *local constraint on u with respect to v*, denoted\n    $\\ell(v)$, is defined by\n\n    .. math::\n\n       \\ell(u, v) = \\left(p_{uv} + \\sum_{w \\in N(v)} p_{uw} p{wv}\\right)^2,\n\n    where $N(v)$ is the set of neighbors of $v$ and $p_{uv}$ is the\n    normalized mutual weight of the (directed or undirected) edges\n    joining $u$ and $v$, for each vertex $u$ and $v$ [1]_. The *mutual\n    weight* of $u$ and $v$ is the sum of the weights of edges joining\n    them (edge weights are assumed to be one if the graph is\n    unweighted).\n\n    Parameters\n    ----------\n    G : NetworkX graph\n        The graph containing ``u`` and ``v``. This can be either\n        directed or undirected.\n\n    u : node\n        A node in the graph ``G``.\n\n    v : node\n        A node in the graph ``G``.\n\n    weight : None or string, optional\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    float\n        The constraint of the node ``v`` in the graph ``G``.\n\n    See also\n    --------\n    constraint\n\n    References\n    ----------\n    .. [1] Burt, Ronald S.\n           \"Structural holes and good ideas\".\n           American Journal of Sociology (110): 349\u2013399.\n\n    \"\"\"\n    nmw = normalized_mutual_weight\n    direct = nmw(G, u, v, weight=weight)\n    indirect = sum(nmw(G, u, w, weight=weight) * nmw(G, w, v, weight=weight)\n                   for w in set(nx.all_neighbors(G, u)))\n    return (direct + indirect) ** 2\n", "path": "networkx/algorithms/structuralholes.py"}], "after_files": [{"content": "\"\"\"Functions for computing measures of structural holes.\"\"\"\n\nimport networkx as nx\n\n__all__ = ['constraint', 'local_constraint', 'effective_size']\n\n\ndef mutual_weight(G, u, v, weight=None):\n    \"\"\"Returns the sum of the weights of the edge from `u` to `v` and\n    the edge from `v` to `u` in `G`.\n\n    `weight` is the edge data key that represents the edge weight. If\n    the specified key is `None` or is not in the edge data for an edge,\n    that edge is assumed to have weight 1.\n\n    Pre-conditions: `u` and `v` must both be in `G`.\n\n    \"\"\"\n    try:\n        a_uv = G[u][v].get(weight, 1)\n    except KeyError:\n        a_uv = 0\n    try:\n        a_vu = G[v][u].get(weight, 1)\n    except KeyError:\n        a_vu = 0\n    return a_uv + a_vu\n\n\ndef normalized_mutual_weight(G, u, v, norm=sum, weight=None):\n    \"\"\"Returns normalized mutual weight of the edges from `u` to `v`\n    with respect to the mutual weights of the neighbors of `u` in `G`.\n\n    `norm` specifies how the normalization factor is computed. It must\n    be a function that takes a single argument and returns a number.\n    The argument will be an iterable of mutual weights\n    of pairs ``(u, w)``, where ``w`` ranges over each (in- and\n    out-)neighbor of ``u``. Commons values for `normalization` are\n    ``sum`` and ``max``.\n\n    `weight` can be ``None`` or a string, if None, all edge weights\n    are considered equal. Otherwise holds the name of the edge\n    attribute used as weight.\n\n    \"\"\"\n    scale = norm(mutual_weight(G, u, w, weight)\n                 for w in set(nx.all_neighbors(G, u)))\n    return 0 if scale == 0 else mutual_weight(G, u, v, weight) / scale\n\n\ndef effective_size(G, nodes=None, weight=None):\n    r\"\"\"Returns the effective size of all nodes in the graph ``G``.\n\n    The *effective size* of a node's ego network is based on the concept\n    of redundancy. A person's ego network has redundancy to the extent\n    that her contacts are connected to each other as well. The\n    nonredundant part of a person's relationships it's the effective\n    size of her ego network [1]_.  Formally, the effective size of a\n    node $u$, denoted $e(u)$, is defined by\n\n    .. math::\n\n       e(u) = \\sum_{v \\in N(u) \\setminus \\{u\\}}\n       \\left(1 - \\sum_{w \\in N(v)} p_{uw} m_{vw}\\right)\n\n    where $N(u)$ is the set of neighbors of $u$ and $p_{uw}$ is the\n    normalized mutual weight of the (directed or undirected) edges\n    joining $u$ and $v$, for each vertex $u$ and $v$ [1]_. And $m_{vw}$\n    is the mutual weight of $v$ and $w$ divided by $v$ highest mutual\n    weight with any of its neighbors. The *mutual weight* of $u$ and $v$\n    is the sum of the weights of edges joining them (edge weights are\n    assumed to be one if the graph is unweighted).\n\n    For the case of unweighted and undirected graphs, Borgatti proposed\n    a simplified formula to compute effective size [2]_\n\n    .. math::\n\n       e(u) = n - \\frac{2t}{n}\n\n    where `t` is the number of ties in the ego network (not including\n    ties to ego) and `n` is the number of nodes (excluding ego).\n\n    Parameters\n    ----------\n    G : NetworkX graph\n        The graph containing ``v``. Directed graphs are treated like\n        undirected graphs when computing neighbors of ``v``.\n\n    nodes : container, optional\n        Container of nodes in the graph ``G`` to compute the effective size.\n        If None, the effective size of every node is computed.\n\n    weight : None or string, optional\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    dict\n        Dictionary with nodes as keys and the effective size of the node as values.\n\n    Notes\n    -----\n    Burt also defined the related concept of *efficiency* of a node's ego\n    network, which is its effective size divided by the degree of that\n    node [1]_. So you can easily compute efficiency:\n\n    >>> G = nx.DiGraph()\n    >>> G.add_edges_from([(0, 1), (0, 2), (1, 0), (2, 1)])\n    >>> esize = nx.effective_size(G)\n    >>> efficiency = {n: v / G.degree(n) for n, v in esize.items()}\n\n    See also\n    --------\n    constraint\n\n    References\n    ----------\n    .. [1] Burt, Ronald S.\n           *Structural Holes: The Social Structure of Competition.*\n           Cambridge: Harvard University Press, 1995.\n\n    .. [2] Borgatti, S.\n           \"Structural Holes: Unpacking Burt's Redundancy Measures\"\n           CONNECTIONS 20(1):35-38.\n           http://www.analytictech.com/connections/v20(1)/holes.htm\n\n    \"\"\"\n    def redundancy(G, u, v, weight=None):\n        nmw = normalized_mutual_weight\n        r = sum(nmw(G, u, w, weight=weight) * nmw(G, v, w, norm=max, weight=weight)\n                for w in set(nx.all_neighbors(G, u)))\n        return 1 - r\n    effective_size = {}\n    if nodes is None:\n        nodes = G\n    # Use Borgatti's simplified formula for unweighted and undirected graphs\n    if not G.is_directed() and weight is None:\n        for v in nodes:\n            # Effective size is not defined for isolated nodes\n            if len(G[v]) == 0:\n                effective_size[v] = float('nan')\n                continue\n            E = nx.ego_graph(G, v, center=False, undirected=True)\n            effective_size[v] = len(E) - (2 * E.size()) / len(E)\n    else:\n        for v in nodes:\n            # Effective size is not defined for isolated nodes\n            if len(G[v]) == 0:\n                effective_size[v] = float('nan')\n                continue\n            effective_size[v] = sum(redundancy(G, v, u, weight)\n                                    for u in set(nx.all_neighbors(G, v)))\n    return effective_size\n\n\ndef constraint(G, nodes=None, weight=None):\n    r\"\"\"Returns the constraint on all nodes in the graph ``G``.\n\n    The *constraint* is a measure of the extent to which a node *v* is\n    invested in those nodes that are themselves invested in the\n    neighbors of *v*. Formally, the *constraint on v*, denoted `c(v)`,\n    is defined by\n\n    .. math::\n\n       c(v) = \\sum_{w \\in N(v) \\setminus \\{v\\}} \\ell(v, w)\n\n    where `N(v)` is the subset of the neighbors of `v` that are either\n    predecessors or successors of `v` and `\\ell(v, w)` is the local\n    constraint on `v` with respect to `w` [1]_. For the definition of local\n    constraint, see :func:`local_constraint`.\n\n    Parameters\n    ----------\n    G : NetworkX graph\n        The graph containing ``v``. This can be either directed or undirected.\n\n    nodes : container, optional\n        Container of nodes in the graph ``G`` to compute the constraint. If\n        None, the constraint of every node is computed.\n\n    weight : None or string, optional\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    dict\n        Dictionary with nodes as keys and the constraint on the node as values.\n\n    See also\n    --------\n    local_constraint\n\n    References\n    ----------\n    .. [1] Burt, Ronald S.\n           \"Structural holes and good ideas\".\n           American Journal of Sociology (110): 349\u2013399.\n\n    \"\"\"\n    if nodes is None:\n        nodes = G\n    constraint = {}\n    for v in nodes:\n        # Constraint is not defined for isolated nodes\n        if len(G[v]) == 0:\n            constraint[v] = float('nan')\n            continue\n        constraint[v] = sum(local_constraint(G, v, n, weight)\n                            for n in set(nx.all_neighbors(G, v)))\n    return constraint\n\n\ndef local_constraint(G, u, v, weight=None):\n    r\"\"\"Returns the local constraint on the node ``u`` with respect to\n    the node ``v`` in the graph ``G``.\n\n    Formally, the *local constraint on u with respect to v*, denoted\n    $\\ell(v)$, is defined by\n\n    .. math::\n\n       \\ell(u, v) = \\left(p_{uv} + \\sum_{w \\in N(v)} p_{uw} p{wv}\\right)^2,\n\n    where $N(v)$ is the set of neighbors of $v$ and $p_{uv}$ is the\n    normalized mutual weight of the (directed or undirected) edges\n    joining $u$ and $v$, for each vertex $u$ and $v$ [1]_. The *mutual\n    weight* of $u$ and $v$ is the sum of the weights of edges joining\n    them (edge weights are assumed to be one if the graph is\n    unweighted).\n\n    Parameters\n    ----------\n    G : NetworkX graph\n        The graph containing ``u`` and ``v``. This can be either\n        directed or undirected.\n\n    u : node\n        A node in the graph ``G``.\n\n    v : node\n        A node in the graph ``G``.\n\n    weight : None or string, optional\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    float\n        The constraint of the node ``v`` in the graph ``G``.\n\n    See also\n    --------\n    constraint\n\n    References\n    ----------\n    .. [1] Burt, Ronald S.\n           \"Structural holes and good ideas\".\n           American Journal of Sociology (110): 349\u2013399.\n\n    \"\"\"\n    nmw = normalized_mutual_weight\n    direct = nmw(G, u, v, weight=weight)\n    indirect = sum(nmw(G, u, w, weight=weight) * nmw(G, w, v, weight=weight)\n                   for w in set(nx.all_neighbors(G, u)))\n    return (direct + indirect) ** 2\n", "path": "networkx/algorithms/structuralholes.py"}]}