diff options
author | Dan Schult <dschult@colgate.edu> | 2021-10-15 20:42:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-15 20:42:57 -0400 |
commit | c028e334138cbc2f89a1a440e71c2e33ba58fb7e (patch) | |
tree | a6c9b2c70f5914efb1d220175911eda87290cfb3 | |
parent | e611fa1e439f6bd0c35fd8db2ca1ced56070a915 (diff) | |
download | networkx-c028e334138cbc2f89a1a440e71c2e33ba58fb7e.tar.gz |
minor tweaks in assortativity docs and code (#5129)
* minor tweaks in assortativity docs and code
docs switch adjacent to incident
more readable code in node_degree_xy
tuple formatting in docs
* fix multigraph treatment
* Capitalize Pearson
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
-rw-r--r-- | networkx/algorithms/assortativity/correlation.py | 4 | ||||
-rw-r--r-- | networkx/algorithms/assortativity/pairs.py | 19 |
2 files changed, 12 insertions, 11 deletions
diff --git a/networkx/algorithms/assortativity/correlation.py b/networkx/algorithms/assortativity/correlation.py index 529311f7..3036ff8b 100644 --- a/networkx/algorithms/assortativity/correlation.py +++ b/networkx/algorithms/assortativity/correlation.py @@ -237,8 +237,8 @@ def numeric_assortativity_coefficient(G, attribute, nodes=None): Notes ----- - This computes Eq. (21) in Ref. [1]_ , for the mixing matrix - of the specified attribute. + This computes Eq. (21) in Ref. [1]_ , which is the Pearson correlation + coefficient of the specified (scalar valued) attribute across edges. References ---------- diff --git a/networkx/algorithms/assortativity/pairs.py b/networkx/algorithms/assortativity/pairs.py index 83bde34c..a34d5afc 100644 --- a/networkx/algorithms/assortativity/pairs.py +++ b/networkx/algorithms/assortativity/pairs.py @@ -13,13 +13,13 @@ def node_attribute_xy(G, attribute, nodes=None): The node attribute key. nodes: list or iterable (optional) - Use only edges that are adjacency to specified nodes. + Use only edges that are incident to specified nodes. The default is all nodes. Returns ------- - (x,y): 2-tuple - Generates 2-tuple of (attribute,attribute) values. + (x, y): 2-tuple + Generates 2-tuple of (attribute, attribute) values. Examples -------- @@ -33,7 +33,7 @@ def node_attribute_xy(G, attribute, nodes=None): Notes ----- For undirected graphs each edge is produced twice, once for each edge - representation (u,v) and (v,u), with the exception of self-loop edges + representation (u, v) and (v, u), with the exception of self-loop edges which only appear once. """ if nodes is None: @@ -80,8 +80,8 @@ def node_degree_xy(G, x="out", y="in", weight=None, nodes=None): Returns ------- - (x,y): 2-tuple - Generates 2-tuple of (degree,degree) values. + (x, y): 2-tuple + Generates 2-tuple of (degree, degree) values. Examples @@ -96,21 +96,22 @@ def node_degree_xy(G, x="out", y="in", weight=None, nodes=None): Notes ----- For undirected graphs each edge is produced twice, once for each edge - representation (u,v) and (v,u), with the exception of self-loop edges + representation (u, v) and (v, u), with the exception of self-loop edges which only appear once. """ if nodes is None: nodes = set(G) else: nodes = set(nodes) - xdeg = G.degree - ydeg = G.degree if G.is_directed(): direction = {"out": G.out_degree, "in": G.in_degree} xdeg = direction[x] ydeg = direction[y] + else: + xdeg = ydeg = G.degree for u, degu in xdeg(nodes, weight=weight): + # use G.edges to treat multigraphs correctly neighbors = (nbr for _, nbr in G.edges(u) if nbr in nodes) for v, degv in ydeg(neighbors, weight=weight): yield degu, degv |