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_marginalizedkernel.ipynb 9.3 kB

7 years ago
5 years ago
7 years ago
7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": null,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "name": "stdout",
  10. "output_type": "stream",
  11. "text": [
  12. "\n",
  13. "Acyclic\n",
  14. "\n",
  15. "--- This is a regression problem ---\n",
  16. "\n",
  17. "\n",
  18. "1. Loading dataset from file...\n",
  19. "\n",
  20. "2. Calculating gram matrices. This could take a while...\n",
  21. "calculating kernels: 16836it [00:00, 18811.60it/s]\n",
  22. "\n",
  23. " --- marginalized kernel matrix of size 183 built in 1.0535125732421875 seconds ---\n",
  24. "\n",
  25. "the gram matrix with parameters {'n_iteration': 1.0, 'p_quit': 0.1, 'remove_totters': False, 'n_jobs': 8} is: \n",
  26. "\n",
  27. "\n",
  28. "calculating kernels: 16836it [00:00, 18469.31it/s]\n",
  29. "\n",
  30. " --- marginalized kernel matrix of size 183 built in 1.037832498550415 seconds ---\n",
  31. "\n",
  32. "the gram matrix with parameters {'n_iteration': 1.0, 'p_quit': 0.2, 'remove_totters': False, 'n_jobs': 8} is: \n",
  33. "\n",
  34. "\n",
  35. "calculating kernels: 16836it [00:00, 17905.98it/s]\n",
  36. "\n",
  37. " --- marginalized kernel matrix of size 183 built in 1.030360460281372 seconds ---\n",
  38. "\n",
  39. "the gram matrix with parameters {'n_iteration': 1.0, 'p_quit': 0.30000000000000004, 'remove_totters': False, 'n_jobs': 8} is: \n",
  40. "\n",
  41. "\n",
  42. "calculating kernels: 16836it [00:00, 17494.74it/s]\n",
  43. "\n",
  44. " --- marginalized kernel matrix of size 183 built in 1.0369200706481934 seconds ---\n",
  45. "\n",
  46. "the gram matrix with parameters {'n_iteration': 1.0, 'p_quit': 0.4, 'remove_totters': False, 'n_jobs': 8} is: \n",
  47. "\n",
  48. "\n",
  49. "calculating kernels: 16836it [00:00, 18481.51it/s]\n",
  50. "\n",
  51. " --- marginalized kernel matrix of size 183 built in 1.0335497856140137 seconds ---\n",
  52. "\n",
  53. "the gram matrix with parameters {'n_iteration': 1.0, 'p_quit': 0.5, 'remove_totters': False, 'n_jobs': 8} is: \n",
  54. "\n",
  55. "\n",
  56. "calculating kernels: 16836it [00:00, 18173.29it/s]\n",
  57. "\n",
  58. " --- marginalized kernel matrix of size 183 built in 1.0338375568389893 seconds ---\n",
  59. "\n",
  60. "the gram matrix with parameters {'n_iteration': 1.0, 'p_quit': 0.6, 'remove_totters': False, 'n_jobs': 8} is: \n",
  61. "\n",
  62. "\n",
  63. "calculating kernels: 16836it [00:00, 18516.39it/s]\n",
  64. "\n",
  65. " --- marginalized kernel matrix of size 183 built in 1.0297644138336182 seconds ---\n",
  66. "\n",
  67. "the gram matrix with parameters {'n_iteration': 1.0, 'p_quit': 0.7000000000000001, 'remove_totters': False, 'n_jobs': 8} is: \n",
  68. "\n",
  69. "\n",
  70. "calculating kernels: 16836it [00:00, 18708.47it/s]\n",
  71. "\n",
  72. " --- marginalized kernel matrix of size 183 built in 1.0404298305511475 seconds ---\n",
  73. "\n",
  74. "the gram matrix with parameters {'n_iteration': 1.0, 'p_quit': 0.8, 'remove_totters': False, 'n_jobs': 8} is: \n",
  75. "\n",
  76. "\n",
  77. "calculating kernels: 16836it [00:00, 18376.82it/s]\n",
  78. "\n",
  79. " --- marginalized kernel matrix of size 183 built in 1.0408570766448975 seconds ---\n",
  80. "\n",
  81. "the gram matrix with parameters {'n_iteration': 1.0, 'p_quit': 0.9, 'remove_totters': False, 'n_jobs': 8} is: \n",
  82. "\n",
  83. "\n",
  84. "calculating kernels: 16836it [00:08, 1984.14it/s]\n",
  85. "\n",
  86. " --- marginalized kernel matrix of size 183 built in 8.540878295898438 seconds ---\n",
  87. "\n",
  88. "the gram matrix with parameters {'n_iteration': 4.0, 'p_quit': 0.1, 'remove_totters': False, 'n_jobs': 8} is: \n",
  89. "\n",
  90. "\n",
  91. "calculating kernels: 14901it [00:07, 1221.99it/s]"
  92. ]
  93. }
  94. ],
  95. "source": [
  96. "# %load_ext line_profiler\n",
  97. "# %matplotlib inline\n",
  98. "from libs import *\n",
  99. "import multiprocessing\n",
  100. "\n",
  101. "from gklearn.kernels.marginalizedKernel import marginalizedkernel\n",
  102. "\n",
  103. "dslist = [\n",
  104. " {'name': 'Acyclic', 'dataset': '../datasets/acyclic/dataset_bps.ds',\n",
  105. " 'task': 'regression'}, # node symb\n",
  106. " {'name': 'Alkane', 'dataset': '../datasets/Alkane/dataset.ds', 'task': 'regression',\n",
  107. " 'dataset_y': '../datasets/Alkane/dataset_boiling_point_names.txt'}, \n",
  108. " # contains single node graph, node symb\n",
  109. " {'name': 'MAO', 'dataset': '../datasets/MAO/dataset.ds'}, # node/edge symb\n",
  110. " {'name': 'PAH', 'dataset': '../datasets/PAH/dataset.ds'}, # unlabeled\n",
  111. " {'name': 'MUTAG', 'dataset': '../datasets/MUTAG/MUTAG_A.txt'}, # node/edge symb\n",
  112. " {'name': 'Letter-med', 'dataset': '../datasets/Letter-med/Letter-med_A.txt'},\n",
  113. " # node nsymb\n",
  114. " {'name': 'ENZYMES', 'dataset': '../datasets/ENZYMES_txt/ENZYMES_A_sparse.txt'},\n",
  115. " # node symb/nsymb\n",
  116. "# {'name': 'Mutagenicity', 'dataset': '../datasets/Mutagenicity/Mutagenicity_A.txt'},\n",
  117. "# # node/edge symb\n",
  118. "# {'name': 'D&D', 'dataset': '../datasets/DD/DD_A.txt'}, # node symb\n",
  119. "\n",
  120. " # {'name': 'COIL-DEL', 'dataset': '../datasets/COIL-DEL/COIL-DEL_A.txt'}, # edge symb, node nsymb\n",
  121. " # # # {'name': 'BZR', 'dataset': '../datasets/BZR_txt/BZR_A_sparse.txt'}, # node symb/nsymb\n",
  122. " # # # {'name': 'COX2', 'dataset': '../datasets/COX2_txt/COX2_A_sparse.txt'}, # node symb/nsymb\n",
  123. " # {'name': 'Fingerprint', 'dataset': '../datasets/Fingerprint/Fingerprint_A.txt'},\n",
  124. " #\n",
  125. " # # {'name': 'DHFR', 'dataset': '../datasets/DHFR_txt/DHFR_A_sparse.txt'}, # node symb/nsymb\n",
  126. " # # {'name': 'SYNTHETIC', 'dataset': '../datasets/SYNTHETIC_txt/SYNTHETIC_A_sparse.txt'}, # node symb/nsymb\n",
  127. " # # {'name': 'MSRC9', 'dataset': '../datasets/MSRC_9_txt/MSRC_9_A.txt'}, # node symb\n",
  128. " # # {'name': 'MSRC21', 'dataset': '../datasets/MSRC_21_txt/MSRC_21_A.txt'}, # node symb\n",
  129. " # # {'name': 'FIRSTMM_DB', 'dataset': '../datasets/FIRSTMM_DB/FIRSTMM_DB_A.txt'}, # node symb/nsymb ,edge nsymb\n",
  130. "\n",
  131. " # # {'name': 'PROTEINS', 'dataset': '../datasets/PROTEINS_txt/PROTEINS_A_sparse.txt'}, # node symb/nsymb\n",
  132. " # # {'name': 'PROTEINS_full', 'dataset': '../datasets/PROTEINS_full_txt/PROTEINS_full_A_sparse.txt'}, # node symb/nsymb\n",
  133. " # # {'name': 'AIDS', 'dataset': '../datasets/AIDS/AIDS_A.txt'}, # node symb/nsymb, edge symb\n",
  134. " # {'name': 'NCI1', 'dataset': '../datasets/NCI1/NCI1.mat',\n",
  135. " # 'extra_params': {'am_sp_al_nl_el': [1, 1, 2, 0, -1]}}, # node symb\n",
  136. " # {'name': 'NCI109', 'dataset': '../datasets/NCI109/NCI109.mat',\n",
  137. " # 'extra_params': {'am_sp_al_nl_el': [1, 1, 2, 0, -1]}}, # node symb\n",
  138. " # {'name': 'NCI-HIV', 'dataset': '../datasets/NCI-HIV/AIDO99SD.sdf',\n",
  139. " # 'dataset_y': '../datasets/NCI-HIV/aids_conc_may04.txt',}, # node/edge symb\n",
  140. "\n",
  141. " # # not working below\n",
  142. " # {'name': 'PTC_FM', 'dataset': '../datasets/PTC/Train/FM.ds',},\n",
  143. " # {'name': 'PTC_FR', 'dataset': '../datasets/PTC/Train/FR.ds',},\n",
  144. " # {'name': 'PTC_MM', 'dataset': '../datasets/PTC/Train/MM.ds',},\n",
  145. " # {'name': 'PTC_MR', 'dataset': '../datasets/PTC/Train/MR.ds',},\n",
  146. "]\n",
  147. "estimator = marginalizedkernel\n",
  148. "#param_grid_precomputed = {'p_quit': np.linspace(0.1, 0.3, 3),\n",
  149. "# 'n_iteration': np.linspace(1, 1, 1),\n",
  150. "param_grid_precomputed = {'p_quit': np.linspace(0.1, 0.9, 9),\n",
  151. " 'n_iteration': np.linspace(1, 19, 7), \n",
  152. " 'remove_totters': [False]}\n",
  153. "param_grid = [{'C': np.logspace(-10, 10, num=41, base=10)},\n",
  154. " {'alpha': np.logspace(-10, 10, num=41, base=10)}]\n",
  155. "\n",
  156. "for ds in dslist:\n",
  157. " print()\n",
  158. " print(ds['name'])\n",
  159. " model_selection_for_precomputed_kernel(\n",
  160. " ds['dataset'],\n",
  161. " estimator,\n",
  162. " param_grid_precomputed,\n",
  163. " (param_grid[1] if ('task' in ds and ds['task']\n",
  164. " == 'regression') else param_grid[0]),\n",
  165. " (ds['task'] if 'task' in ds else 'classification'),\n",
  166. " NUM_TRIALS=30,\n",
  167. " datafile_y=(ds['dataset_y'] if 'dataset_y' in ds else None),\n",
  168. " extra_params=(ds['extra_params'] if 'extra_params' in ds else None),\n",
  169. " ds_name=ds['name'],\n",
  170. " n_jobs=multiprocessing.cpu_count(),\n",
  171. " read_gm_from_file=False,\n",
  172. " verbose=True)\n",
  173. " print()"
  174. ]
  175. }
  176. ],
  177. "metadata": {
  178. "kernelspec": {
  179. "display_name": "Python 3",
  180. "language": "python",
  181. "name": "python3"
  182. },
  183. "language_info": {
  184. "codemirror_mode": {
  185. "name": "ipython",
  186. "version": 3
  187. },
  188. "file_extension": ".py",
  189. "mimetype": "text/x-python",
  190. "name": "python",
  191. "nbconvert_exporter": "python",
  192. "pygments_lexer": "ipython3",
  193. "version": "3.6.7"
  194. }
  195. },
  196. "nbformat": 4,
  197. "nbformat_minor": 2
  198. }

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