Commit c6bacf41 authored by Fize Jacques's avatar Fize Jacques

Debug GED

parent 412cf758
......@@ -76,7 +76,7 @@ cpdef intersection(G, H):
cpdef union_(G, H):
R = nx.create_empty_copy(G)
R.add_edges_from(G.edges(data=True))
R.add_edges_from(G.edges(data=True))
R.add_edges_from(H.edges(data=True))
return R
cdef class Base:
......
......@@ -6,7 +6,7 @@ import networkx as nx
import numpy as np
cimport numpy as np
from .abstract_graph_edit_dist cimport AbstractGraphEditDistance
from ..base cimport intersection
from ..base cimport intersection,union_
cdef class GraphEditDistance(AbstractGraphEditDistance):
......@@ -18,20 +18,24 @@ cdef class GraphEditDistance(AbstractGraphEditDistance):
return self.relabel_cost(node1, node2, G, H)
def relabel_cost(self, node1, node2, G, H):
if node1 != node2:
if len(G.edges(node1)) == 0 and len(H.edges(node2)) ==0:
return self.node_del+self.node_ins
R = nx.create_empty_copy(G)
R.add_edges_from(G.edges(node1,data=True))
nx.relabel_nodes(R,{node1:node2},copy=False)
R2 = nx.create_empty_copy(H)
R2.add_edges_from(H.edges(node2,data=True))
diff=abs(R2.number_of_edges()-intersection(R,R2).number_of_edges())
return (diff*self.edge_ins)+(diff*self.edge_del)
else:
return 0.
if len(G.edges(node1)) == 0 and len(H.edges(node2)) ==0:
if node1 == node2:
return 0.0
return self.node_del+self.node_ins
R = nx.create_empty_copy(G)
R.add_edges_from(G.edges(node1,data=True))
nx.relabel_nodes(R,{node1:node2},copy=False)
R2 = nx.create_empty_copy(H)
R2.add_edges_from(H.edges(node2,data=True))
inter_=intersection(R,R2).number_of_edges()
add_diff=abs(R2.number_of_edges()-inter_)
del_diff=abs(R.number_of_edges()-inter_)
return (add_diff*self.edge_ins)+(del_diff*self.edge_del)+(0 if node1 == node2 else self.node_del+self.node_ins)
cdef double delete_cost(self, int i, int j, nodesG, G):
if i == j:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment