Skip to content

Commit 87e9da8

Browse files
committed
Fix bugs.
1 parent 681802a commit 87e9da8

File tree

7 files changed

+96
-8
lines changed

7 files changed

+96
-8
lines changed

Problems.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# About graph kenrels.
2+
3+
## (Random walk) Sylvester equation kernel.
4+
5+
### ImportError: cannot import name 'frange' from 'matplotlib.mlab'
6+
7+
You are using an outdated `control` with a recent `matplotlib`. `mlab.frange` was removed in `matplotlib-3.1.0`, and `control` removed the call in `control-0.8.2`.
8+
9+
Update your `control` package.
10+
11+
### Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so.
12+
13+
The Intel Math Kernel Library (MKL) is missing or not properly set. I assume the MKL is required by `control` module.
14+
15+
Install MKL. Then add the following to your path:
16+
17+
```
18+
export PATH=/opt/intel/bin:$PATH
19+
20+
export LD_LIBRARY_PATH=/opt/intel/lib/intel64:/opt/intel/mkl/lib/intel64:$LD_LIBRARY_PATH
21+
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Mon Sep 21 10:34:26 2020
5+
6+
@author: ljia
7+
"""
8+
from utils import Graph_Kernel_List_VSym, compute_graph_kernel
9+
10+
11+
def generate_graphs(num_nl_alp):
12+
from gklearn.utils.graph_synthesizer import GraphSynthesizer
13+
gsyzer = GraphSynthesizer()
14+
graphs = gsyzer.unified_graphs(num_graphs=100, num_nodes=20, num_edges=40, num_node_labels=num_nl_alp, num_edge_labels=0, seed=None, directed=False)
15+
return graphs
16+
17+
18+
def xp_synthesied_graphs_num_node_label_alphabet():
19+
20+
# Run and save.
21+
import pickle
22+
import os
23+
save_dir = 'outputs/synthesized_graphs_num_node_label_alphabet/'
24+
if not os.path.exists(save_dir):
25+
os.makedirs(save_dir)
26+
27+
run_times = {}
28+
29+
for kernel_name in Graph_Kernel_List_VSym:
30+
print()
31+
print('Kernel:', kernel_name)
32+
33+
run_times[kernel_name] = []
34+
for num_nl_alp in [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]: # [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40]:
35+
print()
36+
print('Number of node label alphabet:', num_nl_alp)
37+
38+
# Generate graphs.
39+
graphs = generate_graphs(num_nl_alp)
40+
41+
# Compute Gram matrix.
42+
gram_matrix, run_time = compute_graph_kernel(graphs, kernel_name)
43+
run_times[kernel_name].append(run_time)
44+
45+
pickle.dump(run_times, open(save_dir + 'run_time.' + kernel_name + '.' + str(num_nl_alp) + '.pkl', 'wb'))
46+
47+
# Save all.
48+
pickle.dump(run_times, open(save_dir + 'run_times.pkl', 'wb'))
49+
50+
return
51+
52+
53+
if __name__ == '__main__':
54+
xp_synthesied_graphs_num_node_label_alphabet()

gklearn/experiments/papers/PRL_2020/utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@
55
66
@author: ljia
77
"""
8-
Graph_Kernel_List = ['PathUpToH', 'WLSubtree', 'SylvesterEquation', 'Marginalized', 'ShortestPath', 'Treelet', 'ConjugateGradient', 'FixedPoint', 'SpectralDecomposition', 'StructuralSP', 'CommonWalk']
8+
Graph_Kernel_List = ['PathUpToH', 'WLSubtree', 'SylvesterEquation', 'Marginalized', 'ShortestPath', 'Treelet', 'ConjugateGradient', 'FixedPoint', 'SpectralDecomposition', 'StructuralSP', 'CommonWalk']
99
# Graph_Kernel_List = ['CommonWalk', 'Marginalized', 'SylvesterEquation', 'ConjugateGradient', 'FixedPoint', 'SpectralDecomposition', 'ShortestPath', 'StructuralSP', 'PathUpToH', 'Treelet', 'WLSubtree']
1010

1111

12+
Graph_Kernel_List_VSym = ['PathUpToH', 'WLSubtree', 'Marginalized', 'ShortestPath', 'Treelet', 'ConjugateGradient', 'FixedPoint', 'StructuralSP', 'CommonWalk']
13+
14+
15+
Graph_Kernel_List_ESym = ['PathUpToH', 'Marginalized', 'Treelet', 'ConjugateGradient', 'FixedPoint', 'StructuralSP', 'CommonWalk']
16+
17+
18+
Graph_Kernel_List_VCon = ['ShortestPath', 'ConjugateGradient', 'FixedPoint', 'StructuralSP']
19+
20+
21+
Graph_Kernel_List_ECon = ['ConjugateGradient', 'FixedPoint', 'StructuralSP']
22+
23+
1224
def compute_graph_kernel(graphs, kernel_name):
1325
import multiprocessing
1426

@@ -86,6 +98,7 @@ def compute_graph_kernel(graphs, kernel_name):
8698
estimator = weisfeilerlehmankernel
8799
params = {'base_kernel': 'subtree', 'height': 5}
88100

101+
# params['parallel'] = None
89102
params['n_jobs'] = multiprocessing.cpu_count()
90103
params['verbose'] = True
91104
results = estimator(graphs, **params)

gklearn/kernels/untilHPathKernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def paths2labelseqs(plist, G, ds_attrs, node_label, edge_label):
649649
# path_strs.append(tuple(strlist))
650650
else:
651651
path_strs = [
652-
tuple([G.node[node][node_label] for node in path])
652+
tuple([G.nodes[node][node_label] for node in path])
653653
for path in plist
654654
]
655655
return path_strs

gklearn/utils/graph_synthesizer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def __init__(self):
2020
def random_graph(self, num_nodes, num_edges, num_node_labels=0, num_edge_labels=0, seed=None, directed=False, max_num_edges=None, all_edges=None):
2121
g = nx.Graph()
2222
if num_node_labels > 0:
23+
node_labels = np.random.randint(0, high=num_node_labels, size=num_nodes)
2324
for i in range(0, num_nodes):
24-
node_labels = np.random.randint(0, high=num_node_labels, size=num_nodes)
25-
g.add_node(str(i), node_label=node_labels[i])
25+
g.add_node(str(i), atom=node_labels[i]) # @todo: update "atom".
2626
else:
2727
for i in range(0, num_nodes):
2828
g.add_node(str(i))
@@ -31,11 +31,11 @@ def random_graph(self, num_nodes, num_edges, num_node_labels=0, num_edge_labels=
3131
edge_labels = np.random.randint(0, high=num_edge_labels, size=num_edges)
3232
for i in random.sample(range(0, max_num_edges), num_edges):
3333
node1, node2 = all_edges[i]
34-
g.add_edge(node1, node2, edge_label=edge_labels[i])
34+
g.add_edge(str(node1), str(node2), bond_type=edge_labels[i]) # @todo: update "bond_type".
3535
else:
3636
for i in random.sample(range(0, max_num_edges), num_edges):
3737
node1, node2 = all_edges[i]
38-
g.add_edge(node1, node2)
38+
g.add_edge(str(node1), str(node2))
3939

4040
return g
4141

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
numpy>=1.16.2
22
scipy>=1.1.0
3-
matplotlib>=3.0.0
3+
matplotlib>=3.1.0
44
networkx>=2.2
55
scikit-learn>=0.20.0
66
tabulate>=0.8.2

requirements_pypi.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
numpy>=1.16.2
22
scipy>=1.1.0
3-
matplotlib>=3.0.0
3+
matplotlib>=3.1.0
44
networkx>=2.2
55
scikit-learn>=0.20.0
66
tabulate>=0.8.2

0 commit comments

Comments
 (0)