Skip to content

Commit 6574d58

Browse files
aaronzorossbar
andauthored
corrections to docstring of weisfeiler_lehman_subgraph_hashes (#6598)
* corrections to docstring of weisfeiler_lehman_subgraph_hashes * Update networkx/algorithms/graph_hashing.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> --------- Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
1 parent 7b8dea8 commit 6574d58

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

networkx/algorithms/graph_hashing.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,14 @@ def weisfeiler_lehman_subgraph_hashes(
163163
"""
164164
Return a dictionary of subgraph hashes by node.
165165
166-
The dictionary is keyed by node to a list of hashes in increasingly
167-
sized induced subgraphs containing the nodes within 2*k edges
168-
of the key node for increasing integer k until all nodes are included.
166+
Dictionary keys are nodes in `G`, and values are a list of hashes.
167+
Each hash corresponds to a subgraph rooted at a given node u in `G`.
168+
Lists of subgraph hashes are sorted in increasing order of depth from
169+
their root node, with the hash at index i corresponding to a subgraph
170+
of nodes at most i edges distance from u. Thus, each list will contain
171+
``iterations + 1`` elements - a hash for a subgraph at each depth, and
172+
additionally a hash of the initial node label (or equivalently a
173+
subgraph of depth 0)
169174
170175
The function iteratively aggregates and hashes neighbourhoods of each node.
171176
This is achieved for each step by replacing for each node its label from
@@ -179,13 +184,13 @@ def weisfeiler_lehman_subgraph_hashes(
179184
along the connecting edge from this neighbor to node $n$. The resulting string
180185
is then hashed to compress this information into a fixed digest size.
181186
182-
Thus, at the $i$th iteration nodes within $2i$ distance influence any given
187+
Thus, at the $i$-th iteration, nodes within $i$ hops influence any given
183188
hashed node label. We can therefore say that at depth $i$ for node $n$
184189
we have a hash for a subgraph induced by the $2i$-hop neighborhood of $n$.
185190
186-
Can be used to to create general Weisfeiler-Lehman graph kernels, or
187-
generate features for graphs or nodes, for example to generate 'words' in a
188-
graph as seen in the 'graph2vec' algorithm.
191+
The output can be used to to create general Weisfeiler-Lehman graph kernels,
192+
or generate features for graphs or nodes - for example to generate 'words' in
193+
a graph as seen in the 'graph2vec' algorithm.
189194
See [1]_ & [2]_ respectively for details.
190195
191196
Hashes are identical for isomorphic subgraphs and there exist strong

0 commit comments

Comments
 (0)