Pular para o conteúdo principal

Graph Edit Distance - Python

NetworkX

NetworkX (NX) is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

https://networkx.lanl.gov/

similarity

https://www.kite.com/python/docs/networkx.similarity

The graph edit distance is the number of edge/node changes needed to make two graphs isomorphic.
The default algorithm/implementation is sub-optimal for some graphs.
The problem of finding the exact Graph Edit Distance (GED) is NP-hard so it is often slow. 

graph edit distance

https://www.kite.com/python/docs/networkx.similarity.graph_edit_distance

Returns GED (graph edit distance) between graphs G1 and G2.
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.

Signature

graph_edit_distance (
G1,
G2,
node_match: __class__=None,
edge_match: __class__=None,
node_subst_cost: __class__=None,
node_del_cost: __class__=None,
node_ins_cost: __class__=None,
edge_subst_cost: __class__=None,
edge_del_cost: __class__=None,
edge_ins_cost: __class__=None,
upper_bound: __class__=None
)

Parameters   

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

node_match : 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 : 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.

>>> Operações básicas de edição e seus custos <<<

node_subst_cost, node_del_cost, node_ins_cost : 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 : 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.

>>> Limite máximo para a distância <<<  

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

Examples

 G1 = nx.cycle_graph(6)
 G2 = nx.wheel_graph(7)
 nx.graph_edit_distance(G1, G2) 7.0

optimal_edit_paths

https://www.kite.com/python/docs/networkx.similarity.optimal_edit_paths

Retorna não só a distância mas também a sequencia de operações de edição para essa distância

optimize_graph_edit_distance

https://www.kite.com/python/docs/networkx.similarity.optimize_graph_edit_distance

Generator of consecutive approximations of graph edit distance.

Comentários

Postar um comentário

Sinta-se a vontade para comentar. Críticas construtivas são sempre bem vindas.

Postagens mais visitadas deste blog

Connected Papers: Uma abordagem alternativa para revisão da literatura

Durante um projeto de pesquisa podemos encontrar um artigo que nos identificamos em termos de problema de pesquisa e também de solução. Então surge a vontade de saber como essa área de pesquisa se desenvolveu até chegar a esse ponto ou quais desdobramentos ocorreram a partir dessa solução proposta para identificar o estado da arte nesse tema. Podemos seguir duas abordagens:  realizar uma revisão sistemática usando palavras chaves que melhor caracterizam o tema em bibliotecas digitais de referência para encontrar artigos relacionados ou realizar snowballing ancorado nesse artigo que identificamos previamente, explorando os artigos citados (backward) ou os artigos que o citam (forward)  Mas a ferramenta Connected Papers propõe uma abordagem alternativa para essa busca. O problema inicial é dado um artigo de interesse, precisamos encontrar outros artigos relacionados de "certa forma". Find different methods and approaches to the same subject Track down the state of the art rese...

Knowledge Graph Embedding with Triple Context - Leitura de Abstract

  Jun Shi, Huan Gao, Guilin Qi, and Zhangquan Zhou. 2017. Knowledge Graph Embedding with Triple Context. In Proceedings of the 2017 ACM on Conference on Information and Knowledge Management (CIKM '17). Association for Computing Machinery, New York, NY, USA, 2299–2302. https://doi.org/10.1145/3132847.3133119 ABSTRACT Knowledge graph embedding, which aims to represent entities and relations in vector spaces, has shown outstanding performance on a few knowledge graph completion tasks. Most existing methods are based on the assumption that a knowledge graph is a set of separate triples, ignoring rich graph features, i.e., structural information in the graph. In this paper, we take advantages of structures in knowledge graphs, especially local structures around a triple, which we refer to as triple context. We then propose a Triple-Context-based knowledge Embedding model (TCE). For each triple, two kinds of structure information are considered as its context in the graph; one is the out...

KnOD 2021

Beyond Facts: Online Discourse and Knowledge Graphs A preface to the proceedings of the 1st International Workshop on Knowledge Graphs for Online Discourse Analysis (KnOD 2021, co-located with TheWebConf’21) https://ceur-ws.org/Vol-2877/preface.pdf https://knod2021.wordpress.com/   ABSTRACT Expressing opinions and interacting with others on the Web has led to the production of an abundance of online discourse data, such as claims and viewpoints on controversial topics, their sources and contexts . This data constitutes a valuable source of insights for studies into misinformation spread, bias reinforcement, echo chambers or political agenda setting. While knowledge graphs promise to provide the key to a Web of structured information, they are mainly focused on facts without keeping track of the diversity, connection or temporal evolution of online discourse data. As opposed to facts, claims are inherently more complex. Their interpretation strongly depends on the context and a vari...