You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

untilHPathKernel.py 23 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. """
  2. @author: linlin
  3. @references: Liva Ralaivola, Sanjay J Swamidass, Hiroto Saigo, and Pierre
  4. Baldi. Graph kernels for chemical informatics. Neural networks,
  5. 18(8):1093–1110, 2005.
  6. """
  7. import sys
  8. sys.path.insert(0, "../")
  9. import time
  10. from collections import Counter
  11. from itertools import chain
  12. from functools import partial
  13. from multiprocessing import Pool
  14. from tqdm import tqdm
  15. import networkx as nx
  16. import numpy as np
  17. from pygraph.utils.graphdataset import get_dataset_attributes
  18. from pygraph.utils.parallel import parallel_gm
  19. from pygraph.utils.trie import Trie
  20. def untilhpathkernel(*args,
  21. node_label='atom',
  22. edge_label='bond_type',
  23. depth=10,
  24. k_func='tanimoto',
  25. compute_method='trie',
  26. n_jobs=None,
  27. verbose=True):
  28. """Calculate path graph kernels up to depth/hight h between graphs.
  29. Parameters
  30. ----------
  31. Gn : List of NetworkX graph
  32. List of graphs between which the kernels are calculated.
  33. /
  34. G1, G2 : NetworkX graphs
  35. 2 graphs between which the kernel is calculated.
  36. node_label : string
  37. Node attribute used as label. The default node label is atom.
  38. edge_label : string
  39. Edge attribute used as label. The default edge label is bond_type.
  40. depth : integer
  41. Depth of search. Longest length of paths.
  42. k_func : function
  43. A kernel function applied using different notions of fingerprint
  44. similarity.
  45. compute_method: string
  46. Computation method, 'trie' or 'naive'.
  47. Return
  48. ------
  49. Kmatrix : Numpy matrix
  50. Kernel matrix, each element of which is the path kernel up to h between
  51. 2 praphs.
  52. """
  53. # pre-process
  54. depth = int(depth)
  55. Gn = args[0] if len(args) == 1 else [args[0], args[1]]
  56. Gn = [g.copy() for g in Gn]
  57. Kmatrix = np.zeros((len(Gn), len(Gn)))
  58. ds_attrs = get_dataset_attributes(
  59. Gn,
  60. attr_names=['node_labeled', 'edge_labeled', 'is_directed'],
  61. node_label=node_label, edge_label=edge_label)
  62. if not ds_attrs['node_labeled']:
  63. for G in Gn:
  64. nx.set_node_attributes(G, '0', 'atom')
  65. if not ds_attrs['edge_labeled']:
  66. for G in Gn:
  67. nx.set_edge_attributes(G, '0', 'bond_type')
  68. start_time = time.time()
  69. # ---- use pool.imap_unordered to parallel and track progress. ----
  70. # get all paths of all graphs before calculating kernels to save time,
  71. # but this may cost a lot of memory for large datasets.
  72. pool = Pool(n_jobs)
  73. itr = zip(Gn, range(0, len(Gn)))
  74. if len(Gn) < 100 * n_jobs:
  75. chunksize = int(len(Gn) / n_jobs) + 1
  76. else:
  77. chunksize = 100
  78. all_paths = [[] for _ in range(len(Gn))]
  79. if compute_method == 'trie':
  80. getps_partial = partial(wrapper_find_all_path_as_trie, depth,
  81. ds_attrs, node_label, edge_label)
  82. else:
  83. getps_partial = partial(wrapper_find_all_paths_until_length, depth,
  84. ds_attrs, node_label, edge_label)
  85. if verbose:
  86. iterator = tqdm(pool.imap_unordered(getps_partial, itr, chunksize),
  87. desc='getting paths', file=sys.stdout)
  88. else:
  89. iterator = pool.imap_unordered(getps_partial, itr, chunksize)
  90. for i, ps in iterator:
  91. all_paths[i] = ps
  92. pool.close()
  93. pool.join()
  94. # for g in Gn:
  95. # if compute_method == 'trie':
  96. # find_all_path_as_trie(g, depth, ds_attrs, node_label, edge_label)
  97. # else:
  98. # find_all_paths_until_length(g, depth, ds_attrs, node_label, edge_label)
  99. ## size = sys.getsizeof(all_paths)
  100. ## for item in all_paths:
  101. ## size += sys.getsizeof(item)
  102. ## for pppps in item:
  103. ## size += sys.getsizeof(pppps)
  104. ## print(size)
  105. #
  106. ## ttt = time.time()
  107. ## # ---- ---- use pool.map to parallel ----
  108. ## for i, ps in tqdm(
  109. ## pool.map(getps_partial, range(0, len(Gn))),
  110. ## desc='getting paths', file=sys.stdout):
  111. ## all_paths[i] = ps
  112. ## print(time.time() - ttt)
  113. if compute_method == 'trie':
  114. def init_worker(trie_toshare):
  115. global G_trie
  116. G_trie = trie_toshare
  117. do_partial = partial(wrapper_uhpath_do_trie, k_func)
  118. parallel_gm(do_partial, Kmatrix, Gn, init_worker=init_worker,
  119. glbv=(all_paths,), n_jobs=n_jobs, verbose=verbose)
  120. else:
  121. def init_worker(plist_toshare):
  122. global G_plist
  123. G_plist = plist_toshare
  124. do_partial = partial(wrapper_uhpath_do_naive, k_func)
  125. parallel_gm(do_partial, Kmatrix, Gn, init_worker=init_worker,
  126. glbv=(all_paths,), n_jobs=n_jobs, verbose=verbose)
  127. # # ---- direct running, normally use single CPU core. ----
  128. # all_paths = [
  129. # find_all_paths_until_length(
  130. # Gn[i],
  131. # depth,
  132. # ds_attrs,
  133. # node_label=node_label,
  134. # edge_label=edge_label) for i in tqdm(
  135. # range(0, len(Gn)), desc='getting paths', file=sys.stdout)
  136. # ]
  137. #
  138. # if compute_method == 'trie':
  139. # pbar = tqdm(
  140. # total=((len(Gn) + 1) * len(Gn) / 2),
  141. # desc='calculating kernels',
  142. # file=sys.stdout)
  143. # for i in range(0, len(Gn)):
  144. # for j in range(i, len(Gn)):
  145. # Kmatrix[i][j] = _untilhpathkernel_do_trie(all_paths[i],
  146. # all_paths[j], k_func)
  147. # Kmatrix[j][i] = Kmatrix[i][j]
  148. # pbar.update(1)
  149. # else:
  150. # pbar = tqdm(
  151. # total=((len(Gn) + 1) * len(Gn) / 2),
  152. # desc='calculating kernels',
  153. # file=sys.stdout)
  154. # for i in range(0, len(Gn)):
  155. # for j in range(i, len(Gn)):
  156. # Kmatrix[i][j] = _untilhpathkernel_do_naive(all_paths[i], all_paths[j],
  157. # k_func)
  158. # Kmatrix[j][i] = Kmatrix[i][j]
  159. # pbar.update(1)
  160. run_time = time.time() - start_time
  161. if verbose:
  162. print("\n --- kernel matrix of path kernel up to %d of size %d built in %s seconds ---"
  163. % (depth, len(Gn), run_time))
  164. # print(Kmatrix[0][0:10])
  165. return Kmatrix, run_time
  166. def _untilhpathkernel_do_trie(trie1, trie2, k_func):
  167. """Calculate path graph kernels up to depth d between 2 graphs using trie.
  168. Parameters
  169. ----------
  170. trie1, trie2 : list
  171. Tries that contains all paths in 2 graphs.
  172. k_func : function
  173. A kernel function applied using different notions of fingerprint
  174. similarity.
  175. Return
  176. ------
  177. kernel : float
  178. Path kernel up to h between 2 graphs.
  179. """
  180. if k_func == 'tanimoto':
  181. # traverse all paths in graph1 and search them in graph2. Deep-first
  182. # search is applied.
  183. def traverseTrie1t(root, trie2, setlist, pcurrent=[]):
  184. for key, node in root['children'].items():
  185. pcurrent.append(key)
  186. if node['isEndOfWord']:
  187. setlist[1] += 1
  188. count2 = trie2.searchWord(pcurrent)
  189. if count2 != 0:
  190. setlist[0] += 1
  191. if node['children'] != {}:
  192. traverseTrie1t(node, trie2, setlist, pcurrent)
  193. else:
  194. del pcurrent[-1]
  195. if pcurrent != []:
  196. del pcurrent[-1]
  197. # traverse all paths in graph2 and find out those that are not in
  198. # graph1. Deep-first search is applied.
  199. def traverseTrie2t(root, trie1, setlist, pcurrent=[]):
  200. for key, node in root['children'].items():
  201. pcurrent.append(key)
  202. if node['isEndOfWord']:
  203. # print(node['count'])
  204. count1 = trie1.searchWord(pcurrent)
  205. if count1 == 0:
  206. setlist[1] += 1
  207. if node['children'] != {}:
  208. traverseTrie2t(node, trie1, setlist, pcurrent)
  209. else:
  210. del pcurrent[-1]
  211. if pcurrent != []:
  212. del pcurrent[-1]
  213. setlist = [0, 0] # intersection and union of path sets of g1, g2.
  214. # print(trie1.root)
  215. # print(trie2.root)
  216. traverseTrie1t(trie1.root, trie2, setlist)
  217. # print(setlist)
  218. traverseTrie2t(trie2.root, trie1, setlist)
  219. # print(setlist)
  220. kernel = setlist[0] / setlist[1]
  221. else: # MinMax kernel
  222. # traverse all paths in graph1 and search them in graph2. Deep-first
  223. # search is applied.
  224. def traverseTrie1m(root, trie2, sumlist, pcurrent=[]):
  225. for key, node in root['children'].items():
  226. pcurrent.append(key)
  227. if node['isEndOfWord']:
  228. # print(node['count'])
  229. count1 = node['count']
  230. count2 = trie2.searchWord(pcurrent)
  231. sumlist[0] += min(count1, count2)
  232. sumlist[1] += max(count1, count2)
  233. if node['children'] != {}:
  234. traverseTrie1m(node, trie2, sumlist, pcurrent)
  235. else:
  236. del pcurrent[-1]
  237. if pcurrent != []:
  238. del pcurrent[-1]
  239. # traverse all paths in graph2 and find out those that are not in
  240. # graph1. Deep-first search is applied.
  241. def traverseTrie2m(root, trie1, sumlist, pcurrent=[]):
  242. for key, node in root['children'].items():
  243. pcurrent.append(key)
  244. if node['isEndOfWord']:
  245. # print(node['count'])
  246. count1 = trie1.searchWord(pcurrent)
  247. if count1 == 0:
  248. sumlist[1] += node['count']
  249. if node['children'] != {}:
  250. traverseTrie2m(node, trie1, sumlist, pcurrent)
  251. else:
  252. del pcurrent[-1]
  253. if pcurrent != []:
  254. del pcurrent[-1]
  255. sumlist = [0, 0] # sum of mins and sum of maxs
  256. # print(trie1.root)
  257. # print(trie2.root)
  258. traverseTrie1m(trie1.root, trie2, sumlist)
  259. # print(sumlist)
  260. traverseTrie2m(trie2.root, trie1, sumlist)
  261. # print(sumlist)
  262. kernel = sumlist[0] / sumlist[1]
  263. return kernel
  264. def wrapper_uhpath_do_trie(k_func, itr):
  265. i = itr[0]
  266. j = itr[1]
  267. return i, j, _untilhpathkernel_do_trie(G_trie[i], G_trie[j], k_func)
  268. def _untilhpathkernel_do_naive(paths1, paths2, k_func):
  269. """Calculate path graph kernels up to depth d between 2 graphs naively.
  270. Parameters
  271. ----------
  272. paths_list : list of list
  273. List of list of paths in all graphs, where for unlabeled graphs, each
  274. path is represented by a list of nodes; while for labeled graphs, each
  275. path is represented by a string consists of labels of nodes and/or
  276. edges on that path.
  277. k_func : function
  278. A kernel function applied using different notions of fingerprint
  279. similarity.
  280. Return
  281. ------
  282. kernel : float
  283. Path kernel up to h between 2 graphs.
  284. """
  285. all_paths = list(set(paths1 + paths2))
  286. if k_func == 'tanimoto':
  287. length_union = len(set(paths1 + paths2))
  288. kernel = (len(set(paths1)) + len(set(paths2)) -
  289. length_union) / length_union
  290. # vector1 = [(1 if path in paths1 else 0) for path in all_paths]
  291. # vector2 = [(1 if path in paths2 else 0) for path in all_paths]
  292. # kernel_uv = np.dot(vector1, vector2)
  293. # kernel = kernel_uv / (len(set(paths1)) + len(set(paths2)) - kernel_uv)
  294. else: # MinMax kernel
  295. path_count1 = Counter(paths1)
  296. path_count2 = Counter(paths2)
  297. vector1 = [(path_count1[key] if (key in path_count1.keys()) else 0)
  298. for key in all_paths]
  299. vector2 = [(path_count2[key] if (key in path_count2.keys()) else 0)
  300. for key in all_paths]
  301. kernel = np.sum(np.minimum(vector1, vector2)) / \
  302. np.sum(np.maximum(vector1, vector2))
  303. return kernel
  304. def wrapper_uhpath_do_naive(k_func, itr):
  305. i = itr[0]
  306. j = itr[1]
  307. return i, j, _untilhpathkernel_do_naive(G_plist[i], G_plist[j], k_func)
  308. # @todo: (can be removed maybe) this method find paths repetively, it could be faster.
  309. def find_all_paths_until_length(G,
  310. length,
  311. ds_attrs,
  312. node_label='atom',
  313. edge_label='bond_type'):
  314. """Find all paths no longer than a certain maximum length in a graph. A
  315. recursive depth first search is applied.
  316. Parameters
  317. ----------
  318. G : NetworkX graphs
  319. The graph in which paths are searched.
  320. length : integer
  321. The maximum length of paths.
  322. ds_attrs: dict
  323. Dataset attributes.
  324. node_label : string
  325. Node attribute used as label. The default node label is atom.
  326. edge_label : string
  327. Edge attribute used as label. The default edge label is bond_type.
  328. Return
  329. ------
  330. path : list
  331. List of paths retrieved, where for unlabeled graphs, each path is
  332. represented by a list of nodes; while for labeled graphs, each path is
  333. represented by a list of strings consists of labels of nodes and/or
  334. edges on that path.
  335. """
  336. # path_l = [tuple([n]) for n in G.nodes] # paths of length l
  337. # all_paths = path_l[:]
  338. # for l in range(1, length + 1):
  339. # path_l_new = []
  340. # for path in path_l:
  341. # for neighbor in G[path[-1]]:
  342. # if len(path) < 2 or neighbor != path[-2]:
  343. # tmp = path + (neighbor, )
  344. # if tuple(tmp[::-1]) not in path_l_new:
  345. # path_l_new.append(tuple(tmp))
  346. # all_paths += path_l_new
  347. # path_l = path_l_new[:]
  348. path_l = [[n] for n in G.nodes] # paths of length l
  349. all_paths = path_l[:]
  350. for l in range(1, length + 1):
  351. path_lplus1 = []
  352. for path in path_l:
  353. for neighbor in G[path[-1]]:
  354. if neighbor not in path:
  355. tmp = path + [neighbor]
  356. # if tmp[::-1] not in path_lplus1:
  357. path_lplus1.append(tmp)
  358. all_paths += path_lplus1
  359. path_l = path_lplus1[:]
  360. # for i in range(0, length + 1):
  361. # new_paths = find_all_paths(G, i)
  362. # if new_paths == []:
  363. # break
  364. # all_paths.extend(new_paths)
  365. # consider labels
  366. # print(paths2labelseqs(all_paths, G, ds_attrs, node_label, edge_label))
  367. return paths2labelseqs(all_paths, G, ds_attrs, node_label, edge_label)
  368. def wrapper_find_all_paths_until_length(length, ds_attrs, node_label,
  369. edge_label, itr_item):
  370. g = itr_item[0]
  371. i = itr_item[1]
  372. return i, find_all_paths_until_length(g, length, ds_attrs,
  373. node_label=node_label, edge_label=edge_label)
  374. def find_all_path_as_trie(G,
  375. length,
  376. ds_attrs,
  377. node_label='atom',
  378. edge_label='bond_type'):
  379. # time1 = time.time()
  380. # all_path = find_all_paths_until_length(G, length, ds_attrs,
  381. # node_label=node_label,
  382. # edge_label=edge_label)
  383. # ptrie = Trie()
  384. # for path in all_path:
  385. # ptrie.insertWord(path)
  386. # ptrie = Trie()
  387. # path_l = [[n] for n in G.nodes] # paths of length l
  388. # path_l_str = paths2labelseqs(path_l, G, ds_attrs, node_label, edge_label)
  389. # for p in path_l_str:
  390. # ptrie.insertWord(p)
  391. # for l in range(1, length + 1):
  392. # path_lplus1 = []
  393. # for path in path_l:
  394. # for neighbor in G[path[-1]]:
  395. # if neighbor not in path:
  396. # tmp = path + [neighbor]
  397. ## if tmp[::-1] not in path_lplus1:
  398. # path_lplus1.append(tmp)
  399. # path_l = path_lplus1[:]
  400. # # consider labels
  401. # path_l_str = paths2labelseqs(path_l, G, ds_attrs, node_label, edge_label)
  402. # for p in path_l_str:
  403. # ptrie.insertWord(p)
  404. #
  405. # print(time.time() - time1)
  406. # print(ptrie.root)
  407. # print()
  408. # traverse all paths up to length h in a graph and construct a trie with
  409. # them. Deep-first search is applied. Notice the reverse of each path is
  410. # also stored to the trie.
  411. def traverseGraph(root, ptrie, length, G, ds_attrs, node_label, edge_label,
  412. pcurrent=[]):
  413. if len(pcurrent) < length + 1:
  414. for neighbor in G[root]:
  415. if neighbor not in pcurrent:
  416. pcurrent.append(neighbor)
  417. plstr = paths2labelseqs([pcurrent], G, ds_attrs,
  418. node_label, edge_label)
  419. ptrie.insertWord(plstr[0])
  420. traverseGraph(neighbor, ptrie, length, G, ds_attrs,
  421. node_label, edge_label, pcurrent)
  422. del pcurrent[-1]
  423. ptrie = Trie()
  424. path_l = [[n] for n in G.nodes] # paths of length l
  425. path_l_str = paths2labelseqs(path_l, G, ds_attrs, node_label, edge_label)
  426. for p in path_l_str:
  427. ptrie.insertWord(p)
  428. for n in G.nodes:
  429. traverseGraph(n, ptrie, length, G, ds_attrs, node_label, edge_label,
  430. pcurrent=[n])
  431. # def traverseGraph(root, all_paths, length, G, ds_attrs, node_label, edge_label,
  432. # pcurrent=[]):
  433. # if len(pcurrent) < length + 1:
  434. # for neighbor in G[root]:
  435. # if neighbor not in pcurrent:
  436. # pcurrent.append(neighbor)
  437. # plstr = paths2labelseqs([pcurrent], G, ds_attrs,
  438. # node_label, edge_label)
  439. # all_paths.append(pcurrent[:])
  440. # traverseGraph(neighbor, all_paths, length, G, ds_attrs,
  441. # node_label, edge_label, pcurrent)
  442. # del pcurrent[-1]
  443. #
  444. #
  445. # path_l = [[n] for n in G.nodes] # paths of length l
  446. # all_paths = path_l[:]
  447. # path_l_str = paths2labelseqs(path_l, G, ds_attrs, node_label, edge_label)
  448. ## for p in path_l_str:
  449. ## ptrie.insertWord(p)
  450. # for n in G.nodes:
  451. # traverseGraph(n, all_paths, length, G, ds_attrs, node_label, edge_label,
  452. # pcurrent=[n])
  453. # print(ptrie.root)
  454. return ptrie
  455. def wrapper_find_all_path_as_trie(length, ds_attrs, node_label,
  456. edge_label, itr_item):
  457. g = itr_item[0]
  458. i = itr_item[1]
  459. return i, find_all_path_as_trie(g, length, ds_attrs,
  460. node_label=node_label, edge_label=edge_label)
  461. def paths2labelseqs(plist, G, ds_attrs, node_label, edge_label):
  462. if ds_attrs['node_labeled']:
  463. if ds_attrs['edge_labeled']:
  464. path_strs = [
  465. tuple(
  466. list(
  467. chain.from_iterable(
  468. (G.node[node][node_label],
  469. G[node][path[idx + 1]][edge_label])
  470. for idx, node in enumerate(path[:-1]))) +
  471. [G.node[path[-1]][node_label]]) for path in plist
  472. ]
  473. # path_strs = []
  474. # for path in all_paths:
  475. # strlist = list(
  476. # chain.from_iterable((G.node[node][node_label],
  477. # G[node][path[idx + 1]][edge_label])
  478. # for idx, node in enumerate(path[:-1])))
  479. # strlist.append(G.node[path[-1]][node_label])
  480. # path_strs.append(tuple(strlist))
  481. else:
  482. path_strs = [
  483. tuple([G.node[node][node_label] for node in path])
  484. for path in plist
  485. ]
  486. return path_strs
  487. else:
  488. if ds_attrs['edge_labeled']:
  489. return [
  490. tuple([] if len(path) == 1 else [
  491. G[node][path[idx + 1]][edge_label]
  492. for idx, node in enumerate(path[:-1])
  493. ]) for path in plist
  494. ]
  495. else:
  496. return [tuple(['0' for node in path]) for path in plist]
  497. # return [tuple([len(path)]) for path in all_paths]
  498. #
  499. #def paths2GSuffixTree(paths):
  500. # return Tree(paths, builder=ukkonen.Builder)
  501. # def find_paths(G, source_node, length):
  502. # """Find all paths no longer than a certain length those start from a source node. A recursive depth first search is applied.
  503. # Parameters
  504. # ----------
  505. # G : NetworkX graphs
  506. # The graph in which paths are searched.
  507. # source_node : integer
  508. # The number of the node from where all paths start.
  509. # length : integer
  510. # The length of paths.
  511. # Return
  512. # ------
  513. # path : list of list
  514. # List of paths retrieved, where each path is represented by a list of nodes.
  515. # """
  516. # return [[source_node]] if length == 0 else \
  517. # [[source_node] + path for neighbor in G[source_node]
  518. # for path in find_paths(G, neighbor, length - 1) if source_node not in path]
  519. # def find_all_paths(G, length):
  520. # """Find all paths with a certain length in a graph. A recursive depth first search is applied.
  521. # Parameters
  522. # ----------
  523. # G : NetworkX graphs
  524. # The graph in which paths are searched.
  525. # length : integer
  526. # The length of paths.
  527. # Return
  528. # ------
  529. # path : list of list
  530. # List of paths retrieved, where each path is represented by a list of nodes.
  531. # """
  532. # all_paths = []
  533. # for node in G:
  534. # all_paths.extend(find_paths(G, node, length))
  535. # # The following process is not carried out according to the original article
  536. # # all_paths_r = [ path[::-1] for path in all_paths ]
  537. # # # For each path, two presentation are retrieved from its two extremities. Remove one of them.
  538. # # for idx, path in enumerate(all_paths[:-1]):
  539. # # for path2 in all_paths_r[idx+1::]:
  540. # # if path == path2:
  541. # # all_paths[idx] = []
  542. # # break
  543. # # return list(filter(lambda a: a != [], all_paths))
  544. # return all_paths

A Python package for graph kernels, graph edit distances and graph pre-image problem.