networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersBackRef
graph_edit_distance(G1, G2, node_match=None, edge_match=None, node_subst_cost=None, node_del_cost=None, node_ins_cost=None, edge_subst_cost=None, edge_del_cost=None, edge_ins_cost=None, roots=None, upper_bound=None, timeout=None)

Graph edit distance is a graph similarity measure analogous to Levenshtein distance for strings. It is defined as minimum cost of edit path (sequence of node and edge edit operations) transforming graph G1 to graph isomorphic to G2.

Parameters

G1, G2: graphs :

The two graphs G1 and G2 must be of the same type.

node_match : callable

A function that returns True if node n1 in G1 and n2 in G2 should be considered equal during matching.

The function will be called like

node_match(G1.nodes[n1], G2.nodes[n2]).

That is, the function will receive the node attribute dictionaries for n1 and n2 as inputs.

Ignored if node_subst_cost is specified. If neither node_match nor node_subst_cost are specified then node attributes are not considered.

edge_match : callable

A function that returns True if the edge attribute dictionaries for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during matching.

The function will be called like

edge_match(G1[u1][v1], G2[u2][v2]).

That is, the function will receive the edge attribute dictionaries of the edges under consideration.

Ignored if edge_subst_cost is specified. If neither edge_match nor edge_subst_cost are specified then edge attributes are not considered.

node_subst_cost, node_del_cost, node_ins_cost : callable

Functions that return the costs of node substitution, node deletion, and node insertion, respectively.

The functions will be called like

node_subst_cost(G1.nodes[n1], G2.nodes[n2]), node_del_cost(G1.nodes[n1]), node_ins_cost(G2.nodes[n2]).

That is, the functions will receive the node attribute dictionaries as inputs. The functions are expected to return positive numeric values.

Function node_subst_cost overrides node_match if specified. If neither node_match nor node_subst_cost are specified then default node substitution cost of 0 is used (node attributes are not considered during matching).

If node_del_cost is not specified then default node deletion cost of 1 is used. If node_ins_cost is not specified then default node insertion cost of 1 is used.

edge_subst_cost, edge_del_cost, edge_ins_cost : callable

Functions that return the costs of edge substitution, edge deletion, and edge insertion, respectively.

The functions will be called like

edge_subst_cost(G1[u1][v1], G2[u2][v2]), edge_del_cost(G1[u1][v1]), edge_ins_cost(G2[u2][v2]).

That is, the functions will receive the edge attribute dictionaries as inputs. The functions are expected to return positive numeric values.

Function edge_subst_cost overrides edge_match if specified. If neither edge_match nor edge_subst_cost are specified then default edge substitution cost of 0 is used (edge attributes are not considered during matching).

If edge_del_cost is not specified then default edge deletion cost of 1 is used. If edge_ins_cost is not specified then default edge insertion cost of 1 is used.

roots : 2-tuple

Tuple where first element is a node in G1 and the second is a node in G2. These nodes are forced to be matched in the comparison to allow comparison between rooted graphs.

upper_bound : numeric

Maximum edit distance to consider. Return None if no edit distance under or equal to upper_bound exists.

timeout : numeric

Maximum number of seconds to execute. After timeout is met, the current best GED is returned.

Returns GED (graph edit distance) between graphs G1 and G2.

See Also

is_isomorphic

test for graph edit distance of 0

optimal_edit_paths
optimize_graph_edit_distance

Examples

>>> G1 = nx.cycle_graph(6)
... G2 = nx.wheel_graph(7)
... nx.graph_edit_distance(G1, G2) 7.0
>>> G1 = nx.star_graph(5)
... G2 = nx.star_graph(5)
... nx.graph_edit_distance(G1, G2, roots=(0, 0)) 0.0
>>> nx.graph_edit_distance(G1, G2, roots=(1, 0))
8.0
See :

Back References

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

networkx.algorithms.similarity.optimize_graph_edit_distance networkx.algorithms.similarity.optimize_edit_paths networkx.algorithms.similarity.graph_edit_distance networkx.algorithms.similarity networkx.algorithms.similarity.optimal_edit_paths

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/similarity.py#40
type: <class 'function'>
Commit: