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.7 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 gklearn.kernels.commonWalkKernel import commonwalkkernel\n",
  70. "from gklearn.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_A.txt'}, # node/edge symb\n",
  81. " {'name': 'Letter-med', 'dataset': '../datasets/Letter-med/Letter-med_A.txt'},\n",
  82. " # node nsymb\n",
  83. " {'name': 'ENZYMES', 'dataset': '../datasets/ENZYMES_txt/ENZYMES_A_sparse.txt'},\n",
  84. " # node symb/nsymb\n",
  85. "# {'name': 'Mutagenicity', 'dataset': '../datasets/Mutagenicity/Mutagenicity_A.txt'},\n",
  86. "# # node/edge symb\n",
  87. "# {'name': 'D&D', 'dataset': '../datasets/DD/DD_A.txt'}, # node symb\n",
  88. "\n",
  89. " # {'name': 'COIL-DEL', 'dataset': '../datasets/COIL-DEL/COIL-DEL_A.txt'}, # edge symb, node nsymb\n",
  90. " # # # {'name': 'BZR', 'dataset': '../datasets/BZR_txt/BZR_A_sparse.txt'}, # node symb/nsymb\n",
  91. " # # # {'name': 'COX2', 'dataset': '../datasets/COX2_txt/COX2_A_sparse.txt'}, # node symb/nsymb\n",
  92. " # {'name': 'Fingerprint', 'dataset': '../datasets/Fingerprint/Fingerprint_A.txt'},\n",
  93. " #\n",
  94. " # # {'name': 'DHFR', 'dataset': '../datasets/DHFR_txt/DHFR_A_sparse.txt'}, # node symb/nsymb\n",
  95. " # # {'name': 'SYNTHETIC', 'dataset': '../datasets/SYNTHETIC_txt/SYNTHETIC_A_sparse.txt'}, # node symb/nsymb\n",
  96. " # # {'name': 'MSRC9', 'dataset': '../datasets/MSRC_9_txt/MSRC_9_A.txt'}, # node symb\n",
  97. " # # {'name': 'MSRC21', 'dataset': '../datasets/MSRC_21_txt/MSRC_21_A.txt'}, # node symb\n",
  98. " # # {'name': 'FIRSTMM_DB', 'dataset': '../datasets/FIRSTMM_DB/FIRSTMM_DB_A.txt'}, # node symb/nsymb ,edge nsymb\n",
  99. "\n",
  100. " # # {'name': 'PROTEINS', 'dataset': '../datasets/PROTEINS_txt/PROTEINS_A_sparse.txt'}, # node symb/nsymb\n",
  101. " # # {'name': 'PROTEINS_full', 'dataset': '../datasets/PROTEINS_full_txt/PROTEINS_full_A_sparse.txt'}, # node symb/nsymb\n",
  102. " # # {'name': 'AIDS', 'dataset': '../datasets/AIDS/AIDS_A.txt'}, # node symb/nsymb, edge symb\n",
  103. " # {'name': 'NCI1', 'dataset': '../datasets/NCI1/NCI1.mat',\n",
  104. " # 'extra_params': {'am_sp_al_nl_el': [1, 1, 2, 0, -1]}}, # node symb\n",
  105. " # {'name': 'NCI109', 'dataset': '../datasets/NCI109/NCI109.mat',\n",
  106. " # 'extra_params': {'am_sp_al_nl_el': [1, 1, 2, 0, -1]}}, # node symb\n",
  107. " # {'name': 'NCI-HIV', 'dataset': '../datasets/NCI-HIV/AIDO99SD.sdf',\n",
  108. " # 'dataset_y': '../datasets/NCI-HIV/aids_conc_may04.txt',}, # node/edge symb\n",
  109. "\n",
  110. " # # not working below\n",
  111. " # {'name': 'PTC_FM', 'dataset': '../datasets/PTC/Train/FM.ds',},\n",
  112. " # {'name': 'PTC_FR', 'dataset': '../datasets/PTC/Train/FR.ds',},\n",
  113. " # {'name': 'PTC_MM', 'dataset': '../datasets/PTC/Train/MM.ds',},\n",
  114. " # {'name': 'PTC_MR', 'dataset': '../datasets/PTC/Train/MR.ds',},\n",
  115. "]\n",
  116. "estimator = commonwalkkernel\n",
  117. "param_grid_precomputed = [{'compute_method': ['geo'], \n",
  118. " 'weight': np.linspace(0.01, 0.15, 15)},\n",
  119. "# 'weight': np.logspace(-1, -10, num=10, base=10)},\n",
  120. " {'compute_method': ['exp'], 'weight': range(0, 15)}]\n",
  121. "param_grid = [{'C': np.logspace(-10, 10, num=41, base=10)},\n",
  122. " {'alpha': np.logspace(-10, 10, num=41, base=10)}]\n",
  123. "\n",
  124. "for ds in dslist:\n",
  125. " print()\n",
  126. " print(ds['name'])\n",
  127. " model_selection_for_precomputed_kernel(\n",
  128. " ds['dataset'],\n",
  129. " estimator,\n",
  130. " param_grid_precomputed,\n",
  131. " (param_grid[1] if ('task' in ds and ds['task']\n",
  132. " == 'regression') else param_grid[0]),\n",
  133. " (ds['task'] if 'task' in ds else 'classification'),\n",
  134. " NUM_TRIALS=30,\n",
  135. " datafile_y=(ds['dataset_y'] if 'dataset_y' in ds else None),\n",
  136. " extra_params=(ds['extra_params'] if 'extra_params' in ds else None),\n",
  137. " ds_name=ds['name'],\n",
  138. " n_jobs=multiprocessing.cpu_count(),\n",
  139. " read_gm_from_file=False,\n",
  140. " verbose=True)\n",
  141. " print()"
  142. ]
  143. }
  144. ],
  145. "metadata": {
  146. "kernelspec": {
  147. "display_name": "Python 3",
  148. "language": "python",
  149. "name": "python3"
  150. },
  151. "language_info": {
  152. "codemirror_mode": {
  153. "name": "ipython",
  154. "version": 3
  155. },
  156. "file_extension": ".py",
  157. "mimetype": "text/x-python",
  158. "name": "python",
  159. "nbconvert_exporter": "python",
  160. "pygments_lexer": "ipython3",
  161. "version": "3.6.7"
  162. }
  163. },
  164. "nbformat": 4,
  165. "nbformat_minor": 2
  166. }

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