Browse Source

Add of tests repository to play with pygraph. Use of virtualenv

v0.1
Benoit GAUZERE 7 years ago
parent
commit
e1c2c3ac8e
3 changed files with 87 additions and 0 deletions
  1. +5
    -0
      tests/README.md
  2. +66
    -0
      tests/opt.py
  3. +16
    -0
      tests/requirements.txt

+ 5
- 0
tests/README.md View File

@@ -0,0 +1,5 @@
To use the library :
$> virtualenv --python=/usr/bin/python3.5 venv
$> pip install -r requirements.txt
$> source venv/bin/activate
... Go use pygraph

+ 66
- 0
tests/opt.py View File

@@ -0,0 +1,66 @@
import ot
import sys
import pathlib
sys.path.insert(0, "../")

from pygraph.utils.graphfiles import loadDataset
from pygraph.ged.costfunctions import ConstantCostFunction
from pygraph.utils.utils import getSPLengths
from tqdm import tqdm
import numpy as np
from scipy.optimize import linear_sum_assignment
from pygraph.ged.GED import ged
import scipy

def pad(C, n):
C_pad = np.zeros((n, n))
C_pad[:C.shape[0], :C.shape[1]] = C
return C_pad

if (__name__ == "__main__"):
ds_filename = "/home/bgauzere/work/Datasets/Acyclic/dataset_bps.ds"
dataset, y = loadDataset(ds_filename)
cf = ConstantCostFunction(1, 3, 1, 3)
N = len(dataset)

pairs = list()
ged_distances = list() #np.zeros((N, N))
gw_distances = list() #np.zeros((N, N))
for i in tqdm(range(0, N)):
for j in tqdm(range(i, N)):
G1 = dataset[i]
G2 = dataset[j]
n = G1.number_of_nodes()
m = G2.number_of_nodes()
if(n == m):
C1 = getSPLengths(G1)
C2 = getSPLengths(G2)

C1 /= C1.max()
C2 /= C2.max()

dim = max(n, m)
if(n < m):
C1 = pad(C1, dim)
elif (m < n):
C2 = pad(C2, dim)

p = ot.unif(dim)
q = ot.unif(dim)

gw = ot.gromov_wasserstein(C1, C2, p, q,
'square_loss', epsilon=5e-3)
row_ind, col_ind = linear_sum_assignment(-gw)
rho = col_ind
varrho = row_ind[np.argsort(col_ind)]
pairs.append((i,j))
gw_distances.append(ged(G1, G2, cf=cf, rho=rho, varrho=varrho)[0])

ged_distances.append(ged(G1, G2, cf=cf)[0])

print("Moyenne sur Riesen : {}".format(np.mean(ged_distances)))
print("Moyenne sur GW : {} ".format(np.mean(gw_distances)))

np.save("distances_riesen", ged_distances)
np.save("distances_gw", gw_distances)

+ 16
- 0
tests/requirements.txt View File

@@ -0,0 +1,16 @@
cycler==0.10.0
Cython==0.27.3
decorator==4.1.2
matplotlib==2.1.0
networkx==2.0
numpy==1.13.3
pkg-resources==0.0.0
POT==0.4.0
pyparsing==2.2.0
python-dateutil==2.6.1
pytz==2017.3
scikit-learn==0.19.1
scipy==1.0.0
six==1.11.0
sklearn==0.0
tqdm==4.19.4

Loading…
Cancel
Save