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.

run_commonwalkkernel.ipynb 7.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": null,
  6. "metadata": {
  7. "scrolled": false
  8. },
  9. "outputs": [
  10. {
  11. "name": "stdout",
  12. "output_type": "stream",
  13. "text": [
  14. "\n",
  15. "Acyclic\n",
  16. "\n",
  17. "--- This is a regression problem ---\n",
  18. "\n",
  19. "\n",
  20. "1. Loading dataset from file...\n",
  21. "\n",
  22. "2. Calculating gram matrices. This could take a while...\n",
  23. "calculating kernels: 16836it [00:04, 3664.86it/s]\n",
  24. "\n",
  25. " --- kernel matrix of common walk kernel of size 183 built in 4.640817880630493 seconds ---\n",
  26. "\n",
  27. "the gram matrix with parameters {'compute_method': 'geo', 'weight': 0.01, 'n_jobs': 8} is: \n",
  28. "\n",
  29. "\n",
  30. "calculating kernels: 16836it [00:04, 3737.97it/s]\n",
  31. "\n",
  32. " --- kernel matrix of common walk kernel of size 183 built in 4.647830486297607 seconds ---\n",
  33. "\n",
  34. "the gram matrix with parameters {'compute_method': 'geo', 'weight': 0.019999999999999997, 'n_jobs': 8} is: \n",
  35. "\n",
  36. "\n",
  37. "calculating kernels: 16836it [00:04, 3385.68it/s]\n",
  38. "\n",
  39. " --- kernel matrix of common walk kernel of size 183 built in 5.04192042350769 seconds ---\n",
  40. "\n",
  41. "the gram matrix with parameters {'compute_method': 'geo', 'weight': 0.03, 'n_jobs': 8} is: \n",
  42. "\n",
  43. "\n",
  44. "calculating kernels: 16836it [00:04, 3624.84it/s]\n",
  45. "\n",
  46. " --- kernel matrix of common walk kernel of size 183 built in 4.778176546096802 seconds ---\n",
  47. "\n",
  48. "the gram matrix with parameters {'compute_method': 'geo', 'weight': 0.039999999999999994, 'n_jobs': 8} is: \n",
  49. "\n",
  50. "\n",
  51. "calculating kernels: 16836it [00:04, 3619.18it/s]\n",
  52. "\n",
  53. " --- kernel matrix of common walk kernel of size 183 built in 4.761460542678833 seconds ---\n",
  54. "\n",
  55. "the gram matrix with parameters {'compute_method': 'geo', 'weight': 0.049999999999999996, 'n_jobs': 8} is: \n",
  56. "\n",
  57. "\n",
  58. "calculating kernels: 10201it [00:02, 3556.34it/s]"
  59. ]
  60. }
  61. ],
  62. "source": [
  63. "# %load_ext line_profiler\n",
  64. "# %matplotlib inline\n",
  65. "from libs import *\n",
  66. "import multiprocessing\n",
  67. "from sklearn.metrics.pairwise import rbf_kernel\n",
  68. "\n",
  69. "from pygraph.kernels.commonWalkKernel import commonwalkkernel\n",
  70. "from pygraph.utils.kernels import deltakernel, kernelproduct\n",
  71. "\n",
  72. "dslist = [\n",
  73. " {'name': 'Acyclic', 'dataset': '../datasets/acyclic/dataset_bps.ds',\n",
  74. " 'task': 'regression'}, # node symb\n",
  75. " {'name': 'Alkane', 'dataset': '../datasets/Alkane/dataset.ds', 'task': 'regression',\n",
  76. " 'dataset_y': '../datasets/Alkane/dataset_boiling_point_names.txt', }, \n",
  77. " # contains single node graph, node symb\n",
  78. " {'name': 'MAO', 'dataset': '../datasets/MAO/dataset.ds', }, # node/edge symb\n",
  79. " {'name': 'PAH', 'dataset': '../datasets/PAH/dataset.ds', }, # unlabeled\n",
  80. " {'name': 'MUTAG', 'dataset': '../datasets/MUTAG/MUTAG.mat',\n",
  81. " 'extra_params': {'am_sp_al_nl_el': [0, 0, 3, 1, 2]}}, # node/edge symb\n",
  82. " {'name': 'Letter-med', 'dataset': '../datasets/Letter-med/Letter-med_A.txt'},\n",
  83. " # node nsymb\n",
  84. " {'name': 'ENZYMES', 'dataset': '../datasets/ENZYMES_txt/ENZYMES_A_sparse.txt'},\n",
  85. " # node symb/nsymb\n",
  86. "# {'name': 'Mutagenicity', 'dataset': '../datasets/Mutagenicity/Mutagenicity_A.txt'},\n",
  87. "# # node/edge symb\n",
  88. "# {'name': 'D&D', 'dataset': '../datasets/D&D/DD.mat',\n",
  89. "# 'extra_params': {'am_sp_al_nl_el': [0, 1, 2, 1, -1]}}, # node symb\n",
  90. "\n",
  91. " # {'name': 'COIL-DEL', 'dataset': '../datasets/COIL-DEL/COIL-DEL_A.txt'}, # edge symb, node nsymb\n",
  92. " # # # {'name': 'BZR', 'dataset': '../datasets/BZR_txt/BZR_A_sparse.txt'}, # node symb/nsymb\n",
  93. " # # # {'name': 'COX2', 'dataset': '../datasets/COX2_txt/COX2_A_sparse.txt'}, # node symb/nsymb\n",
  94. " # {'name': 'Fingerprint', 'dataset': '../datasets/Fingerprint/Fingerprint_A.txt'},\n",
  95. " #\n",
  96. " # # {'name': 'DHFR', 'dataset': '../datasets/DHFR_txt/DHFR_A_sparse.txt'}, # node symb/nsymb\n",
  97. " # # {'name': 'SYNTHETIC', 'dataset': '../datasets/SYNTHETIC_txt/SYNTHETIC_A_sparse.txt'}, # node symb/nsymb\n",
  98. " # # {'name': 'MSRC9', 'dataset': '../datasets/MSRC_9_txt/MSRC_9_A.txt'}, # node symb\n",
  99. " # # {'name': 'MSRC21', 'dataset': '../datasets/MSRC_21_txt/MSRC_21_A.txt'}, # node symb\n",
  100. " # # {'name': 'FIRSTMM_DB', 'dataset': '../datasets/FIRSTMM_DB/FIRSTMM_DB_A.txt'}, # node symb/nsymb ,edge nsymb\n",
  101. "\n",
  102. " # # {'name': 'PROTEINS', 'dataset': '../datasets/PROTEINS_txt/PROTEINS_A_sparse.txt'}, # node symb/nsymb\n",
  103. " # # {'name': 'PROTEINS_full', 'dataset': '../datasets/PROTEINS_full_txt/PROTEINS_full_A_sparse.txt'}, # node symb/nsymb\n",
  104. " # # {'name': 'AIDS', 'dataset': '../datasets/AIDS/AIDS_A.txt'}, # node symb/nsymb, edge symb\n",
  105. " # {'name': 'NCI1', 'dataset': '../datasets/NCI1/NCI1.mat',\n",
  106. " # 'extra_params': {'am_sp_al_nl_el': [1, 1, 2, 0, -1]}}, # node symb\n",
  107. " # {'name': 'NCI109', 'dataset': '../datasets/NCI109/NCI109.mat',\n",
  108. " # 'extra_params': {'am_sp_al_nl_el': [1, 1, 2, 0, -1]}}, # node symb\n",
  109. " # {'name': 'NCI-HIV', 'dataset': '../datasets/NCI-HIV/AIDO99SD.sdf',\n",
  110. " # 'dataset_y': '../datasets/NCI-HIV/aids_conc_may04.txt',}, # node/edge symb\n",
  111. "\n",
  112. " # # not working below\n",
  113. " # {'name': 'PTC_FM', 'dataset': '../datasets/PTC/Train/FM.ds',},\n",
  114. " # {'name': 'PTC_FR', 'dataset': '../datasets/PTC/Train/FR.ds',},\n",
  115. " # {'name': 'PTC_MM', 'dataset': '../datasets/PTC/Train/MM.ds',},\n",
  116. " # {'name': 'PTC_MR', 'dataset': '../datasets/PTC/Train/MR.ds',},\n",
  117. "]\n",
  118. "estimator = commonwalkkernel\n",
  119. "param_grid_precomputed = [{'compute_method': ['geo'], \n",
  120. " 'weight': np.linspace(0.01, 0.15, 15)},\n",
  121. "# 'weight': np.logspace(-1, -10, num=10, base=10)},\n",
  122. " {'compute_method': ['exp'], 'weight': range(0, 15)}]\n",
  123. "param_grid = [{'C': np.logspace(-10, 10, num=41, base=10)},\n",
  124. " {'alpha': np.logspace(-10, 10, num=41, base=10)}]\n",
  125. "\n",
  126. "for ds in dslist:\n",
  127. " print()\n",
  128. " print(ds['name'])\n",
  129. " model_selection_for_precomputed_kernel(\n",
  130. " ds['dataset'],\n",
  131. " estimator,\n",
  132. " param_grid_precomputed,\n",
  133. " (param_grid[1] if ('task' in ds and ds['task']\n",
  134. " == 'regression') else param_grid[0]),\n",
  135. " (ds['task'] if 'task' in ds else 'classification'),\n",
  136. " NUM_TRIALS=30,\n",
  137. " datafile_y=(ds['dataset_y'] if 'dataset_y' in ds else None),\n",
  138. " extra_params=(ds['extra_params'] if 'extra_params' in ds else None),\n",
  139. " ds_name=ds['name'],\n",
  140. " n_jobs=multiprocessing.cpu_count(),\n",
  141. " read_gm_from_file=False,\n",
  142. " verbose=True)\n",
  143. " print()"
  144. ]
  145. }
  146. ],
  147. "metadata": {
  148. "kernelspec": {
  149. "display_name": "Python 3",
  150. "language": "python",
  151. "name": "python3"
  152. },
  153. "language_info": {
  154. "codemirror_mode": {
  155. "name": "ipython",
  156. "version": 3
  157. },
  158. "file_extension": ".py",
  159. "mimetype": "text/x-python",
  160. "name": "python",
  161. "nbconvert_exporter": "python",
  162. "pygments_lexer": "ipython3",
  163. "version": "3.6.7"
  164. }
  165. },
  166. "nbformat": 4,
  167. "nbformat_minor": 2
  168. }

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