-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhash_graph_kernels.py
54 lines (41 loc) · 1.82 KB
/
hash_graph_kernels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright (c) 2017 by Christopher Morris
# Web site: https://ls11-www.cs.uni-dortmund.de/staff/morris
# Email: christopher.morris at udo.edu
from auxiliarymethods import auxiliary_methods as aux
from auxiliarymethods import dataset_parsers as dp
from graphkernel import hash_graph_kernel as rbk
from graphkernel import shortest_path_kernel_explicit as sp_exp
from graphkernel import wl_kernel as wl
def main():
# Load ENZYMES data set
graph_db, classes = dp.read_txt("ENZYMES")
# Parameters used:
# Compute gram matrix: False,
# Normalize gram matrix: False
# Use discrete labels: False
kernel_parameters_sp = [False, False, 0]
# Parameters used:
# Compute gram matrix: False,
# Normalize gram matrix: False
# Use discrete labels: False
# Number of iterations for WL: 3
kernel_parameters_wl = [3, False, False, 0]
# Use discrete labels, too
# kernel_parameters_sp = [False, False, 1]
# kernel_parameters_wl = [3, False, False, 1]
# Compute gram matrix for HGK-WL
# 20 is the number of iterations
gram_matrix = rbk.hash_graph_kernel(graph_db, sp_exp.shortest_path_kernel, kernel_parameters_sp, 20,
scale_attributes=True, lsh_bin_width=1.0, sigma=1.0)
# Normalize gram matrix
gram_matrix = aux.normalize_gram_matrix(gram_matrix)
# Compute gram matrix for HGK-SP
# 20 is the number of iterations
gram_matrix = rbk.hash_graph_kernel(graph_db, wl.weisfeiler_lehman_subtree_kernel, kernel_parameters_wl, 20,
scale_attributes=True, lsh_bin_width=1.0, sigma=1.0)
# Normalize gram matrix
gram_matrix = aux.normalize_gram_matrix(gram_matrix)
# Write out LIBSVM matrix
dp.write_lib_svm(gram_matrix, classes, "gram_matrix")
if __name__ == "__main__":
main()