Browse Source

Update to NetworkX 2.0

v0.1
Benoit GAUZERE 7 years ago
parent
commit
66129a66df
3 changed files with 84 additions and 1875 deletions
  1. +72
    -1859
      notebooks/py-graph_test.ipynb
  2. +7
    -11
      pygraph/ged/GED.py
  3. +5
    -5
      pygraph/ged/bipartiteGED.py

+ 72
- 1859
notebooks/py-graph_test.ipynb
File diff suppressed because it is too large
View File


+ 7
- 11
pygraph/ged/GED.py View File

@@ -1,6 +1,6 @@
from ged.costfunctions import ConstantCostFunction, RiesenCostFunction
from ged.costfunctions import NeighboorhoodCostFunction
from ged.bipartiteGED import computeBipartiteCostMatrix, getOptimalMapping
from pygraph.ged.costfunctions import ConstantCostFunction, RiesenCostFunction
from pygraph.ged.costfunctions import NeighboorhoodCostFunction
from pygraph.ged.bipartiteGED import computeBipartiteCostMatrix, getOptimalMapping
from scipy.optimize import linear_sum_assignment from scipy.optimize import linear_sum_assignment


def ged(G1, G2, method='Riesen', rho=None, varrho=None, def ged(G1, G2, method='Riesen', rho=None, varrho=None,
@@ -29,18 +29,18 @@ def ged(G1, G2, method='Riesen', rho=None, varrho=None,
n = G1.number_of_nodes() n = G1.number_of_nodes()
m = G2.number_of_nodes() m = G2.number_of_nodes()
ged = 0 ged = 0
for i in G1.nodes_iter():
for i in G1.nodes():
phi_i = rho[i] phi_i = rho[i]
if(phi_i >= m): if(phi_i >= m):
ged += cf.cnd(i, G1) ged += cf.cnd(i, G1)
else: else:
ged += cf.cns(i, phi_i, G1, G2) ged += cf.cns(i, phi_i, G1, G2)
for j in G2.nodes_iter():
for j in G2.nodes():
phi_j = varrho[j] phi_j = varrho[j]
if(phi_j >= n): if(phi_j >= n):
ged += cf.cni(j, G2) ged += cf.cni(j, G2)


for e in G1.edges_iter(data=True):
for e in G1.edges(data=True):
i = e[0] i = e[0]
j = e[1] j = e[1]
phi_i = rho[i] phi_i = rho[i]
@@ -57,7 +57,7 @@ def ged(G1, G2, method='Riesen', rho=None, varrho=None,
ged += cf.ced(e, G1) ged += cf.ced(e, G1)
else: else:
ged += cf.ced(e, G1) ged += cf.ced(e, G1)
for e in G2.edges_iter(data=True):
for e in G2.edges(data=True):
i = e[0] i = e[0]
j = e[1] j = e[1]
phi_i = varrho[i] phi_i = varrho[i]
@@ -70,7 +70,3 @@ def ged(G1, G2, method='Riesen', rho=None, varrho=None,
else: else:
ged += cf.ced(e, G2) ged += cf.ced(e, G2)
return ged, rho, varrho return ged, rho, varrho


def computeDistanceMatrix(dataset):
pass

+ 5
- 5
pygraph/ged/bipartiteGED.py View File

@@ -1,6 +1,6 @@
import numpy as np import numpy as np
from scipy.optimize import linear_sum_assignment from scipy.optimize import linear_sum_assignment
from ged.costfunctions import ConstantCostFunction
from pygraph.ged.costfunctions import ConstantCostFunction




def computeBipartiteCostMatrix(G1, G2, cf=ConstantCostFunction(1, 3, 1, 3)): def computeBipartiteCostMatrix(G1, G2, cf=ConstantCostFunction(1, 3, 1, 3)):
@@ -11,15 +11,15 @@ def computeBipartiteCostMatrix(G1, G2, cf=ConstantCostFunction(1, 3, 1, 3)):
C = np.ones([nm, nm])*np.inf C = np.ones([nm, nm])*np.inf
C[n:, m:] = 0 C[n:, m:] = 0


for u in G1.nodes_iter():
for v in G2.nodes_iter():
for u in G1.nodes():
for v in G2.nodes():
cost = cf.cns(u, v, G1, G2) cost = cf.cns(u, v, G1, G2)
C[u, v] = cost C[u, v] = cost


for v in G1.nodes_iter():
for v in G1.nodes():
C[v, m + v] = cf.cnd(v, G1) C[v, m + v] = cf.cnd(v, G1)


for v in G2.nodes_iter():
for v in G2.nodes():
C[n + v, v] = cf.cni(v, G2) C[n + v, v] = cf.cni(v, G2)
return C return C




Loading…
Cancel
Save