Browse Source

Fix bugs in MedianGraphEstimator.__decrease_order().

v0.2.x
jajupmochi 5 years ago
parent
commit
1c635daf9d
5 changed files with 297 additions and 55 deletions
  1. +32
    -5
      gklearn/ged/median/median_graph_estimator.py
  2. +82
    -8
      gklearn/ged/median/test_median_graph_estimator.py
  3. +172
    -36
      gklearn/preimage/experiments/xp_median_preimage.py
  4. +5
    -0
      gklearn/utils/dataset.py
  5. +6
    -6
      gklearn/utils/graph_files.py

+ 32
- 5
gklearn/ged/median/median_graph_estimator.py View File

@@ -406,7 +406,7 @@ class MedianGraphEstimator(object):
if not median_modified or self.__itrs[median_pos] == 0:
decreased_order = self.__decrease_order(graphs, median)
if not decreased_order or self.__itrs[median_pos] == 0:
increased_order = False
increased_order = self.__increase_order(graphs, median)
# Update the number of iterations without update of the median.
if median_modified or decreased_order or increased_order:
@@ -770,9 +770,9 @@ class MedianGraphEstimator(object):
decreased_order = False
# Decrease the order as long as the best deletion delta is negative.
while self.__compute_best_deletion_delta(graphs, median, id_deleted_node) > -self.__epsilon: # @todo
while self.__compute_best_deletion_delta(graphs, median, id_deleted_node) < -self.__epsilon: # @todo
decreased_order = True
self.__delete_node_from_median(id_deleted_node[0], median)
median = self.__delete_node_from_median(id_deleted_node[0], median)
# Print information about current iteration.
if self.__print_to_stdout == 2:
@@ -808,7 +808,7 @@ class MedianGraphEstimator(object):
if delta < best_delta - self.__epsilon:
best_delta = delta
id_deleted_node[0] = i
id_deleted_node[0] = i # @todo:
# id_deleted_node[0] = 3 # @todo:
return best_delta
@@ -816,12 +816,13 @@ class MedianGraphEstimator(object):
def __delete_node_from_median(self, id_deleted_node, median):
# Update the median.
median.remove_node(id_deleted_node)
median = nx.convert_node_labels_to_integers(median, first_label=0, ordering='default', label_attribute=None) # @todo: This doesn't guarantee that the order is the same as in G.
# Update the node maps.
for key, node_map in self.__node_maps_from_median.items():
new_node_map = NodeMap(nx.number_of_nodes(median), node_map.num_target_nodes())
is_unassigned_target_node = [True] * node_map.num_target_nodes()
for i in range(0, nx.number_of_nodes(median)):
for i in range(0, nx.number_of_nodes(median) + 1):
if i != id_deleted_node:
new_i = (i if i < id_deleted_node else i - 1)
k = node_map.image(i)
@@ -831,11 +832,37 @@ class MedianGraphEstimator(object):
for k in range(0, node_map.num_target_nodes()):
if is_unassigned_target_node[k]:
new_node_map.add_assignment(np.inf, k)
# print(new_node_map.get_forward_map(), new_node_map.get_backward_map())
self.__node_maps_from_median[key] = new_node_map
# Increase overall number of decreases.
self.__num_decrease_order += 1
return median
def __increase_order(self, graphs, median):
# Print information about current iteration.
if self.__print_to_stdout == 2:
print('Trying to increase order: ... ', end='')
# Initialize the best configuration and the best label of the node that is to be inserted.
best_config = {}
best_label = self.__ged_env.get_node_label(1)
increased_order = False
# Increase the order as long as the best insertion delta is negative.
while self.__compute_best_insertion_delta(graphs, best_config, best_label) < - self.__epsilon:
increased_order = True
self.__add_node_to_median(best_config, best_label, median)
# Print information about current iteration.
if self.__print_to_stdout == 2:
print('done.')
# Return true iff the order was increased.
return increased_order
def __improve_sum_of_distances(self, timer):
pass


+ 82
- 8
gklearn/ged/median/test_median_graph_estimator.py View File

@@ -25,16 +25,13 @@ def test_median_graph_estimator():
algo_options_suffix = ' --initial-solutions ' + str(initial_solutions) + ' --ratio-runs-from-initial-solutions 1 --initialization-method NODE '

edit_cost_name = 'LETTER2'
# edit_cost_name = 'CONSTANT'
edit_cost_constants = [0.02987291, 0.0178211, 0.01431966, 0.001, 0.001]
# edit_cost_constants = [4, 4, 2, 1, 1, 1]
ds_name = 'COIL-DEL'
ds_name = 'Letter_high'
# Load dataset.
# dataset = '../../datasets/COIL-DEL/COIL-DEL_A.txt'
dataset = '../../../datasets/Letter-high/Letter-high_A.txt'
# dataset = '../../../datasets/MUTAG/MUTAG_A.txt'
Gn, y_all, _ = load_dataset(dataset)
Gn, y_all, label_names = load_dataset(dataset)
y_idx = get_same_item_indices(y_all)
for i, (y, values) in enumerate(y_idx.items()):
Gn_i = [Gn[val] for val in values]
@@ -61,8 +58,84 @@ def test_median_graph_estimator():
# Select the GED algorithm.
algo_options = '--threads ' + str(threads) + algo_options_suffix
mge.set_options(mge_options)
mge.set_label_names(node_labels=[], edge_labels=[],
node_attrs=['x', 'y'], edge_attrs=[])
mge.set_label_names(node_labels=label_names['node_labels'],
edge_labels=label_names['edge_labels'],
node_attrs=label_names['node_attrs'],
edge_attrs=label_names['edge_attrs'])
mge.set_init_method(algo, algo_options)
mge.set_descent_method(algo, algo_options)
# Run the estimator.
mge.run(graph_ids, set_median_id, gen_median_id)
# Get SODs.
sod_sm = mge.get_sum_of_distances('initialized')
sod_gm = mge.get_sum_of_distances('converged')
print('sod_sm, sod_gm: ', sod_sm, sod_gm)
# Get median graphs.
set_median = ged_env.get_nx_graph(set_median_id)
gen_median = ged_env.get_nx_graph(gen_median_id)
return set_median, gen_median


def test_median_graph_estimator_symb():
from gklearn.utils import load_dataset
from gklearn.ged.median import MedianGraphEstimator, constant_node_costs
from gklearn.gedlib import librariesImport, gedlibpy
from gklearn.preimage.utils import get_same_item_indices
import multiprocessing

# estimator parameters.
init_type = 'MEDOID'
num_inits = 1
threads = multiprocessing.cpu_count()
time_limit = 60000
# algorithm parameters.
algo = 'IPFP'
initial_solutions = 1
algo_options_suffix = ' --initial-solutions ' + str(initial_solutions) + ' --ratio-runs-from-initial-solutions 1 --initialization-method NODE '

edit_cost_name = 'CONSTANT'
edit_cost_constants = [4, 4, 2, 1, 1, 1]
ds_name = 'MUTAG'
# Load dataset.
dataset = '../../../datasets/MUTAG/MUTAG_A.txt'
Gn, y_all, label_names = load_dataset(dataset)
y_idx = get_same_item_indices(y_all)
for i, (y, values) in enumerate(y_idx.items()):
Gn_i = [Gn[val] for val in values]
break
Gn_i = Gn_i[0:10]
# Set up the environment.
ged_env = gedlibpy.GEDEnv()
# gedlibpy.restart_env()
ged_env.set_edit_cost(edit_cost_name, edit_cost_constant=edit_cost_constants)
for G in Gn_i:
ged_env.add_nx_graph(G, '')
graph_ids = ged_env.get_all_graph_ids()
set_median_id = ged_env.add_graph('set_median')
gen_median_id = ged_env.add_graph('gen_median')
ged_env.init(init_option='EAGER_WITHOUT_SHUFFLED_COPIES')
# Set up the estimator.
mge = MedianGraphEstimator(ged_env, constant_node_costs(edit_cost_name))
mge.set_refine_method(algo, '--threads ' + str(threads) + ' --initial-solutions ' + str(initial_solutions) + ' --ratio-runs-from-initial-solutions 1')
mge_options = '--time-limit ' + str(time_limit) + ' --stdout 2 --init-type ' + init_type
mge_options += ' --random-inits ' + str(num_inits) + ' --seed ' + '1' + ' --update-order TRUE --refine FALSE'# @todo: std::to_string(rng())
# Select the GED algorithm.
algo_options = '--threads ' + str(threads) + algo_options_suffix
mge.set_options(mge_options)
mge.set_label_names(node_labels=label_names['node_labels'],
edge_labels=label_names['edge_labels'],
node_attrs=label_names['node_attrs'],
edge_attrs=label_names['edge_attrs'])
mge.set_init_method(algo, algo_options)
mge.set_descent_method(algo, algo_options)
@@ -82,4 +155,5 @@ def test_median_graph_estimator():


if __name__ == '__main__':
set_median, gen_median = test_median_graph_estimator()
# set_median, gen_median = test_median_graph_estimator()
set_median, gen_median = test_median_graph_estimator_symb()

+ 172
- 36
gklearn/preimage/experiments/xp_median_preimage.py View File

@@ -7,6 +7,7 @@ Created on Tue Jan 14 15:39:29 2020
"""
import multiprocessing
import functools
import sys
from gklearn.utils.kernels import deltakernel, gaussiankernel, kernelproduct
from gklearn.preimage.utils import generate_median_preimages_by_class
from gklearn.utils import compute_gram_matrices_by_class
@@ -51,6 +52,7 @@ def xp_median_preimage_13_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -58,6 +60,8 @@ def xp_median_preimage_13_1():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -113,6 +117,7 @@ def xp_median_preimage_13_2():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/' #
@@ -120,6 +125,8 @@ def xp_median_preimage_13_2():
edge_required = True #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -177,6 +184,7 @@ def xp_median_preimage_12_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '.unlabeled/'
@@ -184,6 +192,8 @@ def xp_median_preimage_12_1():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -238,6 +248,7 @@ def xp_median_preimage_12_2():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '.unlabeled/'
@@ -245,6 +256,8 @@ def xp_median_preimage_12_2():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -299,6 +312,7 @@ def xp_median_preimage_12_3():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '.unlabeled/'
@@ -306,6 +320,8 @@ def xp_median_preimage_12_3():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -359,6 +375,7 @@ def xp_median_preimage_12_4():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '.unlabeled/'
@@ -366,6 +383,8 @@ def xp_median_preimage_12_4():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -425,6 +444,7 @@ def xp_median_preimage_12_5():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '.unlabeled/' #
@@ -432,6 +452,8 @@ def xp_median_preimage_12_5():
edge_required = True #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -489,6 +511,7 @@ def xp_median_preimage_9_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '.symb/'
@@ -496,6 +519,8 @@ def xp_median_preimage_9_1():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -550,6 +575,7 @@ def xp_median_preimage_9_2():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '.symb/'
@@ -557,6 +583,8 @@ def xp_median_preimage_9_2():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -611,6 +639,7 @@ def xp_median_preimage_9_3():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '.symb/'
@@ -618,6 +647,8 @@ def xp_median_preimage_9_3():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -671,6 +702,7 @@ def xp_median_preimage_9_4():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '.symb/'
@@ -678,6 +710,8 @@ def xp_median_preimage_9_4():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -739,6 +773,7 @@ def xp_median_preimage_8_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -746,6 +781,8 @@ def xp_median_preimage_8_1():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -800,6 +837,7 @@ def xp_median_preimage_8_2():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -807,6 +845,8 @@ def xp_median_preimage_8_2():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -861,6 +901,7 @@ def xp_median_preimage_8_3():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -868,6 +909,8 @@ def xp_median_preimage_8_3():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -921,6 +964,7 @@ def xp_median_preimage_8_4():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -928,6 +972,8 @@ def xp_median_preimage_8_4():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -985,6 +1031,7 @@ def xp_median_preimage_7_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -992,6 +1039,8 @@ def xp_median_preimage_7_1():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1046,6 +1095,7 @@ def xp_median_preimage_7_2():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -1053,6 +1103,8 @@ def xp_median_preimage_7_2():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1107,6 +1159,7 @@ def xp_median_preimage_7_3():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -1114,6 +1167,8 @@ def xp_median_preimage_7_3():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1167,6 +1222,7 @@ def xp_median_preimage_7_4():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -1174,6 +1230,8 @@ def xp_median_preimage_7_4():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1231,6 +1289,7 @@ def xp_median_preimage_6_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -1238,6 +1297,8 @@ def xp_median_preimage_6_1():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1293,6 +1354,7 @@ def xp_median_preimage_6_2():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -1300,6 +1362,8 @@ def xp_median_preimage_6_2():
edge_required = True #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1357,6 +1421,7 @@ def xp_median_preimage_5_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -1364,6 +1429,8 @@ def xp_median_preimage_5_1():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1421,6 +1488,7 @@ def xp_median_preimage_4_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -1428,6 +1496,8 @@ def xp_median_preimage_4_1():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1483,6 +1553,7 @@ def xp_median_preimage_3_2():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -1490,6 +1561,8 @@ def xp_median_preimage_3_2():
edge_required = True #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1547,6 +1620,7 @@ def xp_median_preimage_3_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -1554,6 +1628,8 @@ def xp_median_preimage_3_1():
edge_required = False #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1611,12 +1687,15 @@ def xp_median_preimage_2_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '.node_attrs/'
irrelevant_labels = {'edge_labels': ['valence']}
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1678,11 +1757,14 @@ def xp_median_preimage_1_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1736,6 +1818,7 @@ def xp_median_preimage_1_2():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -1743,6 +1826,8 @@ def xp_median_preimage_1_2():
edge_required = True #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1800,11 +1885,14 @@ def xp_median_preimage_10_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1858,6 +1946,7 @@ def xp_median_preimage_10_2():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -1865,6 +1954,8 @@ def xp_median_preimage_10_2():
edge_required = True #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1922,11 +2013,14 @@ def xp_median_preimage_11_1():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -1980,6 +2074,7 @@ def xp_median_preimage_11_2():
'random_inits': 10,
'time_limit': 600,
'verbose': 2,
'update_order': False,
'refine': False}
save_results = True
dir_save = '../results/xp_median_preimage/' + ds_name + '.' + kernel_options['name'] + '/'
@@ -1987,6 +2082,8 @@ def xp_median_preimage_11_2():
edge_required = True #
# print settings.
file_output = open(dir_save + 'output.txt', 'w')
sys.stdout = file_output
print('parameters:')
print('dataset name:', ds_name)
print('mpg_options:', mpg_options)
@@ -2098,67 +2195,106 @@ if __name__ == "__main__":
# xp_median_preimage_12_5()

#### xp 13_1: PAH, StructuralSP, using NON_SYMBOLIC.
xp_median_preimage_13_1()
# xp_median_preimage_13_1()

#### xp 13_2: PAH, ShortestPath, using NON_SYMBOLIC.
# xp_median_preimage_13_2()



# #### xp 1_1: Letter-high, StructuralSP.
# xp_median_preimage_1_1()

# #### xp 7_4: MUTAG, WeisfeilerLehman, using CONSTANT.
# xp_median_preimage_7_4()
# #### xp 8_4: Monoterpenoides, WeisfeilerLehman, using CONSTANT.
# xp_median_preimage_8_4()
# #### xp 1_2: Letter-high, ShortestPath.
# xp_median_preimage_1_2()

# #### xp 9_4: MAO, WeisfeilerLehman, using CONSTANT, symbolic only.
# xp_median_preimage_9_4()
# #### xp 10_1: Letter-med, StructuralSP.
# xp_median_preimage_10_1()
# xp_median_preimage_10_1()

# #### xp 10_2: Letter-med, ShortestPath.
# xp_median_preimage_10_2()
# xp_median_preimage_10_2()

# #### xp 11_1: Letter-low, StructuralSP.
# xp_median_preimage_11_1()
# xp_median_preimage_11_1()

# #### xp 11_2: Letter-low, ShortestPath.
# xp_median_preimage_11_2()
#
# #### xp 1_1: Letter-high, StructuralSP.
# xp_median_preimage_1_1()
# xp_median_preimage_11_2()
#
# #### xp 2_1: COIL-DEL, StructuralSP, using LETTER2, only node attrs.
# # xp_median_preimage_2_1()
#
# #### xp 3_1: Fingerprint, StructuralSP, using LETTER2, only node attrs.
# # xp_median_preimage_3_1()

# #### xp 1_2: Letter-high, ShortestPath.
# xp_median_preimage_1_2()
# #### xp 3_2: Fingerprint, ShortestPath, using LETTER2, only node attrs.
# xp_median_preimage_3_2()

# #### xp 3_1: Fingerprint, StructuralSP, using LETTER2, only node attrs.
# xp_median_preimage_3_1()
#
# #### xp 6_1: COIL-RAG, StructuralSP, using NON_SYMBOLIC.
# #### xp 4_1: COLORS-3, StructuralSP, using NON_SYMBOLIC.
# # xp_median_preimage_4_1()
#
# #### xp 5_1: FRANKENSTEIN, StructuralSP, using NON_SYMBOLIC.
# # xp_median_preimage_5_1()
#
# #### xp 6_1: COIL-RAG, StructuralSP, using NON_SYMBOLIC.
# xp_median_preimage_6_1()

# #### xp 6_2: COIL-RAG, ShortestPath, using NON_SYMBOLIC.
# #### xp 6_2: COIL-RAG, ShortestPath, using NON_SYMBOLIC.
# xp_median_preimage_6_2()
#
# #### xp 3_2: Fingerprint, ShortestPath, using LETTER2, only node attrs.
# xp_median_preimage_3_2()

#### xp 7_1: MUTAG, StructuralSP, using CONSTANT.
# #### xp 7_1: MUTAG, StructuralSP, using CONSTANT.
# xp_median_preimage_7_1()

# #### xp 8_1: Monoterpenoides, StructuralSP, using CONSTANT.
# #### xp 7_2: MUTAG, PathUpToH, using CONSTANT.
# xp_median_preimage_7_2()

# #### xp 7_3: MUTAG, Treelet, using CONSTANT.
# xp_median_preimage_7_3()

# #### xp 7_4: MUTAG, WeisfeilerLehman, using CONSTANT.
# xp_median_preimage_7_4()
#
# #### xp 8_1: Monoterpenoides, StructuralSP, using CONSTANT.
# xp_median_preimage_8_1()

# #### xp 9_1: MAO, StructuralSP, using CONSTANT, symbolic only.
# xp_median_preimage_9_1()
# #### xp 8_2: Monoterpenoides, PathUpToH, using CONSTANT.
# xp_median_preimage_8_2()

# #### xp 8_3: Monoterpenoides, Treelet, using CONSTANT.
# xp_median_preimage_8_3()

# #### xp 8_4: Monoterpenoides, WeisfeilerLehman, using CONSTANT.
# xp_median_preimage_8_4()

# #### xp 9_1: MAO, StructuralSP, using CONSTANT, symbolic only.
xp_median_preimage_9_1()

# #### xp 9_2: MAO, PathUpToH, using CONSTANT, symbolic only.
xp_median_preimage_9_2()

# #### xp 2_1: COIL-DEL, StructuralSP, using LETTER2, only node attrs.
# xp_median_preimage_2_1()
# #### xp 9_3: MAO, Treelet, using CONSTANT, symbolic only.
xp_median_preimage_9_3()

# #### xp 9_4: MAO, WeisfeilerLehman, using CONSTANT, symbolic only.
xp_median_preimage_9_4()

#### xp 12_1: PAH, StructuralSP, using NON_SYMBOLIC, unlabeled.
xp_median_preimage_12_1()

#### xp 12_2: PAH, PathUpToH, using CONSTANT, unlabeled.
xp_median_preimage_12_2()

#### xp 12_3: PAH, Treelet, using CONSTANT, unlabeled.
xp_median_preimage_12_3()

#### xp 5_1: FRANKENSTEIN, StructuralSP, using NON_SYMBOLIC.
# xp_median_preimage_5_1()
#### xp 12_4: PAH, WeisfeilerLehman, using CONSTANT, unlabeled.
xp_median_preimage_12_4()

#### xp 12_5: PAH, ShortestPath, using NON_SYMBOLIC, unlabeled.
xp_median_preimage_12_5()

#### xp 13_1: PAH, StructuralSP, using NON_SYMBOLIC.
xp_median_preimage_13_1()

#### xp 13_2: PAH, ShortestPath, using NON_SYMBOLIC.
xp_median_preimage_13_2()

#### xp 4_1: COLORS-3, StructuralSP, using NON_SYMBOLIC.
# xp_median_preimage_4_1()

+ 5
- 0
gklearn/utils/dataset.py View File

@@ -416,6 +416,11 @@ class Dataset(object):
def remove_labels(self, node_labels=[], edge_labels=[], node_attrs=[], edge_attrs=[]):
node_labels = [item for item in node_labels if item in self.__node_labels]
edge_labels = [item for item in edge_labels if item in self.__edge_labels]
node_attrs = [item for item in node_attrs if item in self.__node_attrs]
edge_attrs = [item for item in edge_attrs if item in self.__edge_attrs]

for g in self.__graphs:
for nd in g.nodes():
for nl in node_labels:


+ 6
- 6
gklearn/utils/graph_files.py View File

@@ -63,7 +63,7 @@ def load_dataset(filename, filename_targets=None, gformat=None, **kwargs):
return data, y, label_names


def save_dataset(Gn, y, gformat='gxl', group=None, filename='gfile', xparams=None):
def save_dataset(Gn, y, gformat='gxl', group=None, filename='gfile', **kwargs):
"""Save list of graphs.
"""
import os
@@ -73,22 +73,22 @@ def save_dataset(Gn, y, gformat='gxl', group=None, filename='gfile', xparams=Non
if not os.path.exists(dirname_ds) :
os.makedirs(dirname_ds)
if xparams is not None and 'graph_dir' in xparams:
graph_dir = xparams['graph_dir'] + '/'
if 'graph_dir' in kwargs:
graph_dir = kwargs['graph_dir'] + '/'
if not os.path.exists(graph_dir):
os.makedirs(graph_dir)
del kwargs['graph_dir']
else:
graph_dir = dirname_ds
if group == 'xml' and gformat == 'gxl':
kwargs = {'method': xparams['method']} if xparams is not None else {}
with open(filename + '.xml', 'w') as fgroup:
fgroup.write("<?xml version=\"1.0\"?>")
fgroup.write("\n<!DOCTYPE GraphCollection SYSTEM \"http://www.inf.unibz.it/~blumenthal/dtd/GraphCollection.dtd\">")
fgroup.write("\n<GraphCollection>")
for idx, g in enumerate(Gn):
fname_tmp = "graph" + str(idx) + ".gxl"
saveGXL(g, graph_dir + fname_tmp, **kwargs)
save_gxl(g, graph_dir + fname_tmp, **kwargs)
fgroup.write("\n\t<graph file=\"" + fname_tmp + "\" class=\"" + str(y[idx]) + "\"/>")
fgroup.write("\n</GraphCollection>")
fgroup.close()
@@ -226,7 +226,7 @@ def load_gxl(filename): # @todo: directed graphs.
return g, label_names


def saveGXL(graph, filename, method='default', node_labels=[], edge_labels=[], node_attrs=[], edge_attrs=[]):
def save_gxl(graph, filename, method='default', node_labels=[], edge_labels=[], node_attrs=[], edge_attrs=[]):
if method == 'default':
gxl_file = open(filename, 'w')
gxl_file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")


Loading…
Cancel
Save