networkx.algorithms.similarity.optimal_edit_paths
的用法。用法:
optimal_edit_paths(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, upper_bound=None)
返回將 G1 轉換為 G2 的所有 minimum-cost 編輯路徑。
圖編輯路徑是一係列節點和邊編輯操作,將圖 G1 轉換為與 G2 同構的圖。編輯操作包括替換、刪除和插入。
- G1, G2: graphs:
兩個圖形 G1 和 G2 必須屬於同一類型。
- node_match:可調用的
如果在匹配期間應將 G1 中的節點 n1 和 G2 中的 n2 視為相等,則返回 True 的函數。
該函數將被稱為
node_match(G1.nodes[n1], G2.nodes[n2])。
也就是說,該函數將接收 n1 和 n2 的節點屬性字典作為輸入。
如果指定了node_subst_cost,則忽略。如果既沒有指定node_match 也沒有指定node_subst_cost,則不考慮節點屬性。
- edge_match:可調用的
如果 G1 中的節點對 (u1, v1) 和 G2 中的 (u2, v2) 的邊屬性字典在匹配期間應被視為相等,則返回 True 的函數。
該函數將被稱為
edge_match(G1[u1][v1], G2[u2][v2])。
也就是說,該函數將接收正在考慮的邊的邊屬性字典。
如果指定了edge_subst_cost,則忽略。如果既沒有指定edge_match 也沒有指定edge_subst_cost,則不考慮邊屬性。
- node_subst_cost, node_del_cost, node_ins_cost:可調用的
分別返回節點替換、節點刪除和節點插入成本的函數。
這些函數將被稱為
node_subst_cost(G1.nodes[n1], G2.nodes[n2]), node_del_cost(G1.nodes[n1]), node_ins_cost(G2.nodes[n2])。
也就是說,函數將接收節點屬性字典作為輸入。這些函數應返回正數值。
如果指定,函數 node_subst_cost 會覆蓋 node_match。如果既沒有指定node_match 也沒有指定node_subst_cost,則使用默認節點替換成本 0(匹配期間不考慮節點屬性)。
如果未指定node_del_cost,則使用默認節點刪除成本 1。如果未指定node_ins_cost,則使用默認節點插入成本 1。
- edge_subst_cost, edge_del_cost, edge_ins_cost:可調用的
分別返回邊替換、邊刪除和邊插入成本的函數。
這些函數將被稱為
edge_subst_cost(G1[u1][v1], G2[u2][v2]), edge_del_cost(G1[u1][v1]), edge_ins_cost(G2[u2][v2])。
也就是說,函數將接收邊屬性字典作為輸入。這些函數應返回正數值。
如果指定,函數 edge_subst_cost 會覆蓋 edge_match。如果既沒有指定 edge_match 也沒有指定 edge_subst_cost,則使用默認的邊替換成本 0(匹配期間不考慮邊屬性)。
如果未指定edge_del_cost,則使用默認的邊刪除成本 1。如果未指定edge_ins_cost,則使用默認的邊插入成本 1。
- upper_bound:數字
要考慮的最大編輯距離。
- edit_paths:元組列表 (node_edit_path, edge_edit_path)
node_edit_path: 元組列表 (u, v) edge_edit_path: 元組列表 ((u1, v1), (u2, v2))
- cost:數字
最佳編輯路徑成本(圖形編輯距離)。
參數:
返回:
參考:
- 1
Zeina Abu-Aisheh, Romain Raveaux, Jean-Yves Ramel, Patrick Martineau. An Exact Graph Edit Distance Algorithm for Solving Pattern Recognition Problems. 4th International Conference on Pattern Recognition Applications and Methods 2015, Jan 2015, Lisbon, Portugal. 2015, <10.5220/0005209202710278>. <hal-01168816> https://hal.archives-ouvertes.fr/hal-01168816
例子:
>>> G1 = nx.cycle_graph(4) >>> G2 = nx.wheel_graph(5) >>> paths, cost = nx.optimal_edit_paths(G1, G2) >>> len(paths) 40 >>> cost 5.0
相關用法
- Python NetworkX optimize_graph_edit_distance用法及代碼示例
- Python NetworkX open_file用法及代碼示例
- Python NetworkX overlap_weighted_projected_graph用法及代碼示例
- Python NetworkX negative_edge_cycle用法及代碼示例
- Python NetworkX voronoi_cells用法及代碼示例
- Python NetworkX numerical_edge_match用法及代碼示例
- Python NetworkX inverse_line_graph用法及代碼示例
- Python NetworkX LFR_benchmark_graph用法及代碼示例
- Python NetworkX write_graph6用法及代碼示例
- Python NetworkX DiGraph.__contains__用法及代碼示例
- Python NetworkX average_degree_connectivity用法及代碼示例
- Python NetworkX eulerian_circuit用法及代碼示例
- Python NetworkX single_source_dijkstra_path_length用法及代碼示例
- Python NetworkX from_dict_of_dicts用法及代碼示例
- Python NetworkX weisfeiler_lehman_subgraph_hashes用法及代碼示例
- Python NetworkX transitive_closure_dag用法及代碼示例
- Python NetworkX intersection用法及代碼示例
- Python NetworkX MultiGraph.size用法及代碼示例
- Python NetworkX Graph.size用法及代碼示例
- Python NetworkX from_scipy_sparse_array用法及代碼示例
- Python NetworkX local_and_global_consistency用法及代碼示例
- Python NetworkX number_of_selfloops用法及代碼示例
- Python NetworkX single_source_bellman_ford用法及代碼示例
- Python NetworkX all_simple_paths用法及代碼示例
- Python NetworkX Graph.to_undirected用法及代碼示例
注:本文由純淨天空篩選整理自networkx.org大神的英文原創作品 networkx.algorithms.similarity.optimal_edit_paths。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。