Commit b3e85f33 authored by Guillaume RENTON's avatar Guillaume RENTON

Ajout de commentaires, et modification des différents chemins d'accès

parent 4566d33d
......@@ -134,7 +134,7 @@ if __name__ == "__main__":
for j in range(len(liste_file)):
graph1= create_graph_from_gxl(path+liste_file[i])
graph2= create_graph_from_gxl(path+liste_file[j])
C_node, C_star = create_cost_matrix(graph1,graph2,c_node_sub=None,c_node_del_ins=4,c_edge_sub=None,c_edge_del_ins=1)
C_node, C_star, C_edge = create_cost_matrix(graph1,graph2,c_node_sub=None,c_node_del_ins=4,c_edge_sub=None,c_edge_del_ins=1)
upper,lower,permutation=calcul_Munkres(graph1,graph2,C_node,C_star,c_edge_del_ins=1)
print(upper,lower)
......
......@@ -9,32 +9,74 @@ import pickle
from Bipartite import calcul_Munkres,create_cost_matrix
from load_gxl import create_graph_from_gxl
import os
if __name__ == "__main__":
with open("LETTER_HIGH/base_app.p","rb") as fp:
with open("../../../LETTER_HIGH/base_app.p","rb") as fp:
app=pickle.load(fp, encoding="bytes")
with open("LETTER_HIGH/base_valid.p","rb") as fp:
with open("../../../LETTER_HIGH/base_valid.p","rb") as fp:
valid = pickle.load(fp,encoding="bytes")
with open("../../../LETTER_HIGH/base_test.p","rb") as fp:
test = pickle.load(fp,encoding="bytes")
print(len(app))
print(len(valid))
MSE = 0
path = "../Datasets/Letter/HIGH/"
Mre_up = 0
Mre_down = 0
for fileapp in app:
graph1=create_graph_from_gxl(path+fileapp[4])
graph2=create_graph_from_gxl(path+fileapp[5])
c_star_node, c_star = create_cost_matrix(graph1,graph2)
cost,lower,h = calcul_Munkres(graph1,graph2,c_star_node,c_star)
MSE += (cost - fileapp[1])**2
print(MSE/len(app))
if fileapp[2] < fileapp[3]:
exit()
MSE += (fileapp[2]- fileapp[1])**2
#print (fileapp[2]- fileapp[1])**2
if fileapp[1]!=0:
Mre_up += abs((fileapp[1]-fileapp[2])/fileapp[1])
Mre_down += abs((fileapp[1]-fileapp[3])/fileapp[1])
#print abs((fileapp[1]-fileapp[2])/fileapp[1])
print("MSE on app", MSE/len(app))
print("Mean relative error on app upper bound : ", (Mre_up*100/len(app)))
print("Mean relative error on app lower bound : ", (Mre_down*100/len(app)))
MSE = 0
Mre_up = 0
Mre_down = 0
for filetest in test:
MSE += (filetest[2]- filetest[1])**2
if filetest[1] !=0:
Mre_up += abs((filetest[1]-filetest[2])/filetest[1])
Mre_down += abs((filetest[1]-filetest[3])/filetest[1])
else:
Mre_up += abs((filetest[1]-filetest[2]))
Mre_down += abs((filetest[1]-filetest[3]))
print("MSE on test : ", MSE/len(test))
print("Mean relative error on test upper bound : ", (Mre_up*100/len(test)))
print("Mean relative error on test lower bound : ", (Mre_down*100/len(test)))
Mre_up = 0
Mre_down = 0
for fileapp in app:
if fileapp[1]!=0:
Mre_up += abs((fileapp[1]-fileapp[2])/fileapp[1])
Mre_down += abs((fileapp[1]-fileapp[3])/fileapp[1])
else:
Mre_up += abs(fileapp[1]-fileapp[2])
Mre_down += abs(fileapp[1]-fileapp[3])
for filetest in test:
if filetest[1]!=0:
Mre_up += abs((filetest[1]-filetest[2])/filetest[1])
Mre_down += abs((filetest[1]-filetest[3])/filetest[1])
else:
Mre_up += abs(filetest[1]-filetest[2])
Mre_down += abs(filetest[1]-filetest[3])
for filevalid in valid:
graph1=create_graph_from_gxl(path+filevalid[4])
graph2=create_graph_from_gxl(path+filevalid[5])
c_star_node, c_star = create_cost_matrix(graph1,graph2)
cost,lower,h = calcul_Munkres(graph1,graph2,c_star_node,c_star)
MSE += (cost - filevalid[1])**2
print(MSE/len(valid))
\ No newline at end of file
if filevalid[1]!=0:
Mre_up += abs((filevalid[1]-filevalid[2])/filevalid[1])
Mre_down += abs((filevalid[1]-filevalid[3])/filevalid[1])
else:
Mre_up += abs(filevalid[1]-filevalid[2])
Mre_down += abs(filevalid[1]-filevalid[3])
print("Mre_up total", (Mre_up*100/(len(app)+len(valid)+len(test))))
print("Mre_down total", (Mre_down*100/(len(app)+len(valid)+len(test))))
\ No newline at end of file
......@@ -13,6 +13,10 @@ import time
def computeSVR(path):
"""
Compute a SVR in the Riesen way.
We try to predict the true ged from both upper ad lower bounds
"""
with open(path + "base_app.p", "rb") as fp:
baseapp = pickle.load(fp, encoding="bytes")
with open(path + "base_valid.p", "rb") as fp:
......@@ -57,5 +61,5 @@ def computeSVR(path):
if __name__ == "__main__":
path = "LETTER_HIGH/"
path = "../../../LETTER_HIGH/"
computeSVR(path)
......@@ -12,17 +12,26 @@ from functions import A_star
import glob
import random
import pickle
import os
import time
import sys
import math
import numpy as np
from GED import ged
from costfunctions import ConstantCostFunction
import matplotlib.pyplot as plt
from tqdm import tqdm
def extractor(path_G1, path_G2):
"""
The way (do you know the way ?) data are extracted of the graph.
Actually, are extracted from the graph :
- a 3d matrix containing both node and edge matrix cost
- The true ged from A star
- Upper bound from bipartite
- Lower bound from bipartite
- The matrix of assignment calculated from true ged
- Path to first graph
- Path to second graph
"""
G1 = create_graph_from_gxl(path_G1)
G2 = create_graph_from_gxl(path_G2)
if G1.number_of_nodes()<G2.number_of_nodes():
......@@ -42,6 +51,11 @@ def extractor(path_G1, path_G2):
return out
def compute_matrix_assignment(tuple_assignment,G1,G2,permutation):
"""
function for creating the matrix assignment from the true ged and its permuation
Take as entry the list of permutation obtained by A star from the file function
"""
n=G1.number_of_nodes()
m=G2.number_of_nodes()
......@@ -75,8 +89,18 @@ def compute_matrix_assignment(tuple_assignment,G1,G2,permutation):
return mat_assignment
def create_base_app(path, number_of_file_for_app, c_edge_sub=None, c_edge_del_ins = None, c_node_sub = None, c_node_del_ins =None, load = False):
"""
Function for creation of an app base from a subset of a whole base
Take as entry :
-Dataset path
-number of file from the dataset to randowly pick. If 60 are picked, 60*61/2 couple of graph will be created.
-Costs for node/edge substitution/deletion
- A load parameter, in case of crash =D
3 datasets are saved under the name "base_app","base_valid", "base_test".
"""
t = time.time()
if load:
with open("liste_tuple.p", "rb") as fp:
......@@ -130,6 +154,19 @@ def create_base_app(path, number_of_file_for_app, c_edge_sub=None, c_edge_del_in
def create_base_from_cxl(path,filename, fichier_result, c_edge_sub=None, c_edge_del_ins = None, c_node_sub = None, c_node_del_ins =None):
"""
Function for creation of an app base from a cxl file
Take as entry :
-cxl path
-cxl filename
-Existing result for true ged
-Costs for node/edge substitution/deletion
- A load parameter should be added
3 datasets are saved under the name "base_app","base_valid", "base_test".
"""
t=time.time()
tree = ET.parse(path+filename)
liste_file = []
......@@ -167,6 +204,20 @@ def create_base_from_cxl(path,filename, fichier_result, c_edge_sub=None, c_edge_
def create_base_from_cxl_with_max(path,filename, fichier_result, c_edge_sub=None, c_edge_del_ins = None, c_node_sub = None, c_node_del_ins =None, longueur_max = 8):
"""
Function for creation of an app base from a cxl file
Take as entry :
-cxl path
-cxl filename
-Existing result for true ged
-Costs for node/edge substitution/deletion
- A max length parameter. Dataset are created so that hard to compute couples are only tested and not learned.
- A load parameter should be added
3 datasets are saved under the name "base_app","base_valid", "base_test".
"""
t=time.time()
tree = ET.parse(path+filename)
liste_file = []
......@@ -211,6 +262,10 @@ def create_base_from_cxl_with_max(path,filename, fichier_result, c_edge_sub=None
def calcul_hist_nb_nodes(path, filename):
"""
Function to display an histogram of the number of node per graph.
"""
t=time.time()
tree = ET.parse(path+filename)
liste_file = []
......@@ -230,6 +285,10 @@ def calcul_hist_nb_nodes(path, filename):
def modifyExistingDataset(path, c_edge_sub=None, c_edge_del_ins = None, c_node_sub = None, c_node_del_ins =None ):
"""
Function using the tmp save for modifying the existing datasets
"""
with open("liste_tuple.p", "rb") as fp:
existing_dataset=pickle.load(fp, encoding = "bytes")
liste_tuple=[]
......@@ -271,7 +330,7 @@ def modifyExistingDataset(path, c_edge_sub=None, c_edge_del_ins = None, c_node_s
if __name__ == "__main__":
costs = (2,4,1,1)
path = "../Datasets/Letter/HIGH/"
path = "../../../../Datasets/Letter/HIGH/"
create_base_app(path+"*.gxl", 60, c_node_sub=costs[0], c_node_del_ins = costs[1], c_edge_sub = costs[2], c_edge_del_ins =costs[3])
# calcul_hist_nb_nodes(path,"dataset.cxl", longueur_max=9)
# create_base_from_cxl_with_max(path,"dataset.cxl","result_symbolic_acyclic_romain-f2_cost1_distances", c_node_sub=costs[0], c_node_del_ins = costs[1], c_edge_sub = costs[2], c_edge_del_ins =costs[3], longueur_max=9)
......
......@@ -9,6 +9,10 @@ Created on Wed May 10 09:49:33 2017
import re
import matplotlib.pyplot as plt
"""
Function used to display the learning advancement saved in the file save_metric.txt"
"""
filesave = open("save_metric.txt", "r")
loss =[]
......
......@@ -9,6 +9,9 @@ import networkx as nx
import xml.etree.ElementTree as ET
def create_graph_from_gxl(filename):
"""
funciton returning a networkx graph from a gxl file
"""
tree = ET.parse(filename)
graph = tree.find(".//graph")
index = 0
......
......@@ -267,7 +267,7 @@ def trainModel_assignment(path, nbEpoch, weights_Recognizer, dataset_type = ""):
if __name__ == "__main__":
path = "LETTER_HIGH/"
path = "../../../LETTER_HIGH/"
epoch = 500
trainModel_assignment(path, epoch, "test_letter_GED_double",dataset_type = "_little")
......@@ -81,16 +81,6 @@ def predict_assignment(path, weights):
print(len(basetest))
model = creerModel_assignment(2,weights)
Mse_bp_ged = 0
Mse_model = 0
Mre_bp_ged = 0
Mre_model = 0
erreur = np.full((len(basetest)), 0.0)
erreur_bp = np.full((len(basetest)), 0.0)
True_ged = []
Modele_ged = []
BP_GED = []
i = 0
for test in basetest:
batch = np.expand_dims(test[0], axis=0)
print(test[0].shape)
......@@ -111,42 +101,7 @@ def predict_assignment(path, weights):
plt.show()
# value_approx = min((value_approx,test[2]))
# Mse_bp_ged += (test[2] - test[1])**2
# Mse_model += (value_approx-test[1])**2
# if test[1]!=0:
# Mre_bp_ged += abs((test[2] - test[1])/test[1])
# Mre_model += abs((value_approx-test[1])/test[1])
# else:
# Mre_bp_ged += abs((test[2] - test[1]))
# Mre_model += abs((value_approx-test[1]))
#
# print test[1], test[2], value_approx, value_approx-test[1]
# erreur[i]=value_approx-test[1]
# erreur_bp[i]=test[2]-test[1]
# i+=1
# True_ged.append(test[1])
# Modele_ged.append(value_approx)
# BP_GED.append(test[2])
# Mse_bp_ged = Mse_bp_ged/len(basetest)
# Mse_model = Mse_model/len(basetest)
# Mre_bp_ged = Mre_bp_ged*100/len(basetest)
# Mre_model = Mre_model*100/len(basetest)
#
#
# print("Mse BP GED : ", Mse_bp_ged)
# print("Mse modele : ", Mse_model)
# print("Mre BP GED : ", Mre_bp_ged)
# print("Mre modele : ", Mre_model)
#
# plt.subplot(211)
# plt.plot(True_ged,BP_GED,'b*')
# plt.subplot(212)
# plt.plot(True_ged,Modele_ged,'b*')
# plt.show()
if __name__ == "__main__":
t = time.time()
predict_GED("LETTER_HIGH/", "weights/model_test_letter_GED_60.h5")
predict_GED("../../../LETTER_HIGH/", "weights/model_test_letter_GED_60.h5")
print("Temps ecoule : ", time.time() - t)
\ No newline at end of file
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