networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
weisfeiler_lehman_graph_hash(G, edge_attr=None, node_attr=None, iterations=3, digest_size=16)

The function iteratively aggregates and hashes neighbourhoods of each node. After each node's neighbors are hashed to obtain updated node labels, a hashed histogram of resulting labels is returned as the final hash.

Hashes are identical for isomorphic graphs and strong guarantees that non-isomorphic graphs will get different hashes. See for details.

If no node or edge attributes are provided, the degree of each node is used as its initial label. Otherwise, node and/or edge labels are used to compute the hash.

Notes

To return the WL hashes of each subgraph of a graph, use weisfeiler_lehman_subgraph_hashes

Similarity between hashes does not imply similarity between graphs.

Parameters

G: graph :

The graph to be hashed. Can have node and/or edge attributes. Can also have no attributes.

edge_attr: string, default=None :

The key in edge attribute dictionary to be used for hashing. If None, edge labels are ignored.

node_attr: string, default=None :

The key in node attribute dictionary to be used for hashing. If None, and no edge_attr given, use the degrees of the nodes as labels.

iterations: int, default=3 :

Number of neighbor aggregations to perform. Should be larger for larger graphs.

digest_size: int, default=16 :

Size (in bits) of blake2b hash digest to use for hashing node labels.

Returns

h : string

Hexadecimal string corresponding to hash of the input graph.

Return Weisfeiler Lehman (WL) graph hash.

See Also

weisfeiler_lehman_subgraph_hashes

Examples

Two graphs with edge attributes that are isomorphic, except for differences in the edge labels.

>>> G1 = nx.Graph()
... G1.add_edges_from(
...  [
...  (1, 2, {"label": "A"}),
...  (2, 3, {"label": "A"}),
...  (3, 1, {"label": "A"}),
...  (1, 4, {"label": "B"}),
...  ]
... )
... G2 = nx.Graph()
... G2.add_edges_from(
...  [
...  (5, 6, {"label": "B"}),
...  (6, 7, {"label": "A"}),
...  (7, 5, {"label": "A"}),
...  (7, 8, {"label": "A"}),
...  ]
... )

Omitting the :None:None:`edge_attr` option, results in identical hashes.

>>> nx.weisfeiler_lehman_graph_hash(G1)
'7bc4dde9a09d0b94c5097b219891d81a'
>>> nx.weisfeiler_lehman_graph_hash(G2)
'7bc4dde9a09d0b94c5097b219891d81a'

With edge labels, the graphs are no longer assigned the same hash digest.

>>> nx.weisfeiler_lehman_graph_hash(G1, edge_attr="label")
'c653d85538bcf041d88c011f4f905f10'
>>> nx.weisfeiler_lehman_graph_hash(G2, edge_attr="label")
'3dcd84af1ca855d0eff3c978d88e7ec7'
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.graph_hashing.weisfeiler_lehman_subgraph_hashes networkx.algorithms.graph_hashing.weisfeiler_lehman_graph_hash

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/graph_hashing.py#38
type: <class 'function'>
Commit: