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_untilhpathkernel.ipynb 34 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. "getting paths: 183it [00:00, 33583.79it/s]\n",
  24. "calculating kernels: 16836it [00:00, 382919.33it/s]\n",
  25. "\n",
  26. " --- kernel matrix of path kernel up to 1 of size 183 built in 0.28138017654418945 seconds ---\n",
  27. "\n",
  28. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 1.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  29. "\n",
  30. "\n",
  31. "getting paths: 183it [00:00, 49932.19it/s]\n",
  32. "calculating kernels: 16836it [00:00, 339040.24it/s]\n",
  33. "\n",
  34. " --- kernel matrix of path kernel up to 1 of size 183 built in 0.2915959358215332 seconds ---\n",
  35. "\n",
  36. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 1.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  37. "\n",
  38. "\n",
  39. "getting paths: 183it [00:00, 13100.71it/s]\n",
  40. "calculating kernels: 16836it [00:00, 195915.25it/s]\n",
  41. "\n",
  42. " --- kernel matrix of path kernel up to 2 of size 183 built in 0.39291882514953613 seconds ---\n",
  43. "\n",
  44. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 2.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  45. "\n",
  46. "\n",
  47. "getting paths: 183it [00:00, 15186.23it/s]\n",
  48. "calculating kernels: 16836it [00:00, 216679.82it/s]\n",
  49. "\n",
  50. " --- kernel matrix of path kernel up to 2 of size 183 built in 0.2922053337097168 seconds ---\n",
  51. "\n",
  52. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 2.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  53. "\n",
  54. "\n",
  55. "getting paths: 183it [00:00, 8410.48it/s]\n",
  56. "calculating kernels: 16836it [00:00, 146690.73it/s]\n",
  57. "\n",
  58. " --- kernel matrix of path kernel up to 3 of size 183 built in 0.3915746212005615 seconds ---\n",
  59. "\n",
  60. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 3.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  61. "\n",
  62. "\n",
  63. "getting paths: 183it [00:00, 13951.28it/s]\n",
  64. "calculating kernels: 16836it [00:00, 201673.88it/s]\n",
  65. "\n",
  66. " --- kernel matrix of path kernel up to 3 of size 183 built in 0.3854410648345947 seconds ---\n",
  67. "\n",
  68. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 3.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  69. "\n",
  70. "\n",
  71. "getting paths: 183it [00:00, 10054.46it/s]\n",
  72. "calculating kernels: 16836it [00:00, 70713.10it/s]\n",
  73. "\n",
  74. " --- kernel matrix of path kernel up to 4 of size 183 built in 0.48105573654174805 seconds ---\n",
  75. "\n",
  76. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 4.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  77. "\n",
  78. "\n",
  79. "getting paths: 183it [00:00, 1418.94it/s]\n",
  80. "calculating kernels: 16836it [00:00, 144898.57it/s]\n",
  81. "\n",
  82. " --- kernel matrix of path kernel up to 4 of size 183 built in 0.5477819442749023 seconds ---\n",
  83. "\n",
  84. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 4.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  85. "\n",
  86. "\n",
  87. "getting paths: 183it [00:00, 15604.25it/s]\n",
  88. "calculating kernels: 16836it [00:00, 103300.82it/s]\n",
  89. "\n",
  90. " --- kernel matrix of path kernel up to 5 of size 183 built in 0.3788299560546875 seconds ---\n",
  91. "\n",
  92. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 5.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  93. "\n",
  94. "\n",
  95. "getting paths: 183it [00:00, 9795.27it/s]\n",
  96. "calculating kernels: 16836it [00:00, 121689.68it/s]\n",
  97. "\n",
  98. " --- kernel matrix of path kernel up to 5 of size 183 built in 0.3888108730316162 seconds ---\n",
  99. "\n",
  100. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 5.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  101. "\n",
  102. "\n",
  103. "getting paths: 183it [00:00, 7163.19it/s]\n",
  104. "calculating kernels: 16836it [00:00, 89262.17it/s]\n",
  105. "\n",
  106. " --- kernel matrix of path kernel up to 6 of size 183 built in 0.39624905586242676 seconds ---\n",
  107. "\n",
  108. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 6.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  109. "\n",
  110. "\n",
  111. "getting paths: 183it [00:00, 16751.59it/s]\n",
  112. "calculating kernels: 16836it [00:00, 100004.39it/s]\n",
  113. "\n",
  114. " --- kernel matrix of path kernel up to 6 of size 183 built in 0.388913631439209 seconds ---\n",
  115. "\n",
  116. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 6.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  117. "\n",
  118. "\n",
  119. "getting paths: 183it [00:00, 10090.81it/s]\n",
  120. "calculating kernels: 16836it [00:00, 91172.28it/s] \n",
  121. "\n",
  122. " --- kernel matrix of path kernel up to 7 of size 183 built in 0.4908461570739746 seconds ---\n",
  123. "\n",
  124. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 7.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  125. "\n",
  126. "\n",
  127. "getting paths: 183it [00:00, 2997.78it/s]\n",
  128. "calculating kernels: 16836it [00:00, 104945.65it/s]\n",
  129. "\n",
  130. " --- kernel matrix of path kernel up to 7 of size 183 built in 0.36611366271972656 seconds ---\n",
  131. "\n",
  132. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 7.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  133. "\n",
  134. "\n",
  135. "getting paths: 183it [00:00, 6353.90it/s]\n",
  136. "calculating kernels: 16836it [00:00, 80425.25it/s]\n",
  137. "\n",
  138. " --- kernel matrix of path kernel up to 8 of size 183 built in 0.5061323642730713 seconds ---\n",
  139. "\n",
  140. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 8.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  141. "\n",
  142. "\n",
  143. "getting paths: 183it [00:00, 9427.60it/s]\n",
  144. "calculating kernels: 16836it [00:00, 93863.88it/s] \n",
  145. "\n",
  146. " --- kernel matrix of path kernel up to 8 of size 183 built in 0.3872077465057373 seconds ---\n",
  147. "\n",
  148. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 8.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  149. "\n",
  150. "\n",
  151. "getting paths: 183it [00:00, 7575.20it/s]\n",
  152. "calculating kernels: 16836it [00:00, 82517.07it/s]\n",
  153. "\n",
  154. " --- kernel matrix of path kernel up to 9 of size 183 built in 0.48129963874816895 seconds ---\n",
  155. "\n",
  156. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 9.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  157. "\n",
  158. "\n",
  159. "getting paths: 183it [00:00, 6563.74it/s]\n",
  160. "calculating kernels: 16836it [00:00, 94045.02it/s] \n",
  161. "\n",
  162. " --- kernel matrix of path kernel up to 9 of size 183 built in 0.39592933654785156 seconds ---\n",
  163. "\n",
  164. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 9.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  165. "\n",
  166. "\n",
  167. "getting paths: 183it [00:00, 6069.81it/s]\n",
  168. "calculating kernels: 16836it [00:00, 77447.83it/s]\n",
  169. "\n",
  170. " --- kernel matrix of path kernel up to 10 of size 183 built in 0.47420382499694824 seconds ---\n",
  171. "\n",
  172. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 10.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  173. "\n",
  174. "\n",
  175. "getting paths: 183it [00:00, 9481.17it/s]\n",
  176. "calculating kernels: 16836it [00:00, 58253.60it/s]\n",
  177. "\n",
  178. " --- kernel matrix of path kernel up to 10 of size 183 built in 0.4869115352630615 seconds ---\n",
  179. "\n",
  180. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 10.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  181. "\n",
  182. "\n",
  183. "\n",
  184. "20 gram matrices are calculated, 0 of which are ignored.\n",
  185. "\n",
  186. "3. Fitting and predicting using nested cross validation. This could really take a while...\n",
  187. "cross validation: 30it [01:07, 1.10s/it]\n",
  188. "\n",
  189. "4. Getting final performance...\n",
  190. "best_params_out: [{'compute_method': 'trie', 'depth': 2.0, 'k_func': 'MinMax', 'n_jobs': 8}]\n",
  191. "best_params_in: [{'alpha': 0.01}]\n",
  192. "\n",
  193. "best_val_perf: 6.8347760734601675\n",
  194. "best_val_std: 0.26187601855914455\n",
  195. "final_performance: [6.844597847292873]\n",
  196. "final_confidence: [1.3282917788841784]\n",
  197. "train_performance: [2.2886614412566524]\n",
  198. "train_std: [0.11697823620293107]\n",
  199. "\n",
  200. "time to calculate gram matrix with different hyper-params: 0.41±0.07s\n",
  201. "time to calculate best gram matrix: 0.39±nans\n",
  202. "total training time with all hyper-param choices: 82.00s\n",
  203. "\n"
  204. ]
  205. },
  206. {
  207. "name": "stderr",
  208. "output_type": "stream",
  209. "text": [
  210. "/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py:140: RuntimeWarning: Degrees of freedom <= 0 for slice\n",
  211. " keepdims=keepdims)\n",
  212. "/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py:132: RuntimeWarning: invalid value encountered in double_scalars\n",
  213. " ret = ret.dtype.type(ret / rcount)\n"
  214. ]
  215. },
  216. {
  217. "name": "stdout",
  218. "output_type": "stream",
  219. "text": [
  220. "\n",
  221. "\n",
  222. "Alkane\n",
  223. "\n",
  224. "--- This is a regression problem ---\n",
  225. "\n",
  226. "\n",
  227. "1. Loading dataset from file...\n",
  228. "\n",
  229. "2. Calculating gram matrices. This could take a while...\n",
  230. "getting paths: 150it [00:00, 38060.83it/s]\n",
  231. "calculating kernels: 11325it [00:00, 447307.64it/s]\n",
  232. "\n",
  233. " --- kernel matrix of path kernel up to 1 of size 150 built in 0.29852986335754395 seconds ---\n",
  234. "\n",
  235. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 1.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  236. "\n",
  237. "\n",
  238. "getting paths: 150it [00:00, 16860.39it/s]\n",
  239. "calculating kernels: 11325it [00:00, 522115.40it/s]\n",
  240. "\n",
  241. " --- kernel matrix of path kernel up to 1 of size 150 built in 0.29816317558288574 seconds ---\n",
  242. "\n",
  243. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 1.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  244. "\n",
  245. "\n",
  246. "getting paths: 150it [00:00, 18149.30it/s]\n",
  247. "calculating kernels: 11325it [00:00, 383173.55it/s]\n",
  248. "\n",
  249. " --- kernel matrix of path kernel up to 2 of size 150 built in 0.29796385765075684 seconds ---\n",
  250. "\n",
  251. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 2.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  252. "\n",
  253. "\n",
  254. "getting paths: 150it [00:00, 23172.10it/s]\n",
  255. "calculating kernels: 11325it [00:00, 427074.37it/s]\n",
  256. "\n",
  257. " --- kernel matrix of path kernel up to 2 of size 150 built in 0.3109288215637207 seconds ---\n",
  258. "\n",
  259. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 2.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  260. "\n",
  261. "\n",
  262. "getting paths: 150it [00:00, 13243.78it/s]\n",
  263. "calculating kernels: 11325it [00:00, 269283.28it/s]\n",
  264. "\n",
  265. " --- kernel matrix of path kernel up to 3 of size 150 built in 0.29997825622558594 seconds ---\n",
  266. "\n",
  267. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 3.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  268. "\n",
  269. "\n",
  270. "getting paths: 150it [00:00, 20671.78it/s]\n",
  271. "calculating kernels: 11325it [00:00, 312080.29it/s]\n",
  272. "\n",
  273. " --- kernel matrix of path kernel up to 3 of size 150 built in 0.29572534561157227 seconds ---\n",
  274. "\n",
  275. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 3.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  276. "\n",
  277. "\n",
  278. "getting paths: 150it [00:00, 15393.45it/s]\n",
  279. "calculating kernels: 11325it [00:00, 362928.87it/s]\n",
  280. "\n",
  281. " --- kernel matrix of path kernel up to 4 of size 150 built in 0.30132484436035156 seconds ---\n",
  282. "\n",
  283. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 4.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  284. "\n",
  285. "\n",
  286. "getting paths: 150it [00:00, 16957.65it/s]\n",
  287. "calculating kernels: 11325it [00:00, 84503.61it/s]\n",
  288. "\n",
  289. " --- kernel matrix of path kernel up to 4 of size 150 built in 0.4178507328033447 seconds ---\n",
  290. "\n",
  291. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 4.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  292. "\n",
  293. "\n",
  294. "getting paths: 150it [00:00, 14440.54it/s]\n",
  295. "calculating kernels: 11325it [00:00, 276894.92it/s]\n",
  296. "\n",
  297. " --- kernel matrix of path kernel up to 5 of size 150 built in 0.29338693618774414 seconds ---\n",
  298. "\n",
  299. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 5.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  300. "\n",
  301. "\n",
  302. "getting paths: 150it [00:00, 15619.30it/s]\n",
  303. "calculating kernels: 11325it [00:00, 254676.58it/s]\n",
  304. "\n",
  305. " --- kernel matrix of path kernel up to 5 of size 150 built in 0.29663729667663574 seconds ---\n",
  306. "\n",
  307. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 5.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  308. "\n",
  309. "\n",
  310. "getting paths: 150it [00:00, 14585.84it/s]\n",
  311. "calculating kernels: 11325it [00:00, 242964.30it/s]\n",
  312. "\n",
  313. " --- kernel matrix of path kernel up to 6 of size 150 built in 0.29677391052246094 seconds ---\n",
  314. "\n",
  315. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 6.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  316. "\n",
  317. "\n",
  318. "getting paths: 150it [00:00, 11555.83it/s]\n",
  319. "calculating kernels: 11325it [00:00, 330949.31it/s]\n",
  320. "\n",
  321. " --- kernel matrix of path kernel up to 6 of size 150 built in 0.2948622703552246 seconds ---\n",
  322. "\n",
  323. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 6.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  324. "\n",
  325. "\n",
  326. "getting paths: 150it [00:00, 10424.60it/s]\n",
  327. "calculating kernels: 11325it [00:00, 238514.96it/s]\n",
  328. "\n",
  329. " --- kernel matrix of path kernel up to 7 of size 150 built in 0.3041496276855469 seconds ---\n",
  330. "\n",
  331. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 7.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  332. "\n",
  333. "\n",
  334. "getting paths: 150it [00:00, 12318.80it/s]\n",
  335. "calculating kernels: 11325it [00:00, 251979.97it/s]\n",
  336. "\n",
  337. " --- kernel matrix of path kernel up to 7 of size 150 built in 0.3013496398925781 seconds ---\n",
  338. "\n",
  339. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 7.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  340. "\n",
  341. "\n",
  342. "getting paths: 150it [00:00, 10722.00it/s]\n",
  343. "calculating kernels: 11325it [00:00, 232363.74it/s]\n",
  344. "\n",
  345. " --- kernel matrix of path kernel up to 8 of size 150 built in 0.294144868850708 seconds ---\n",
  346. "\n",
  347. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 8.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  348. "\n",
  349. "\n",
  350. "getting paths: 150it [00:00, 18965.59it/s]\n",
  351. "calculating kernels: 11325it [00:00, 424638.55it/s]\n",
  352. "\n",
  353. " --- kernel matrix of path kernel up to 8 of size 150 built in 0.2961091995239258 seconds ---\n",
  354. "\n",
  355. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 8.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  356. "\n",
  357. "\n",
  358. "getting paths: 150it [00:00, 13945.38it/s]\n",
  359. "calculating kernels: 11325it [00:00, 286344.19it/s]\n",
  360. "\n",
  361. " --- kernel matrix of path kernel up to 9 of size 150 built in 0.30029296875 seconds ---\n",
  362. "\n",
  363. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 9.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  364. "\n",
  365. "\n",
  366. "getting paths: 150it [00:00, 9525.87it/s]\n",
  367. "calculating kernels: 11325it [00:00, 231776.43it/s]\n",
  368. "\n",
  369. " --- kernel matrix of path kernel up to 9 of size 150 built in 0.29835057258605957 seconds ---\n",
  370. "\n",
  371. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 9.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  372. "\n",
  373. "\n",
  374. "getting paths: 150it [00:00, 16916.15it/s]\n",
  375. "calculating kernels: 11325it [00:00, 85396.60it/s]\n",
  376. "\n",
  377. " --- kernel matrix of path kernel up to 10 of size 150 built in 0.42621588706970215 seconds ---\n",
  378. "\n",
  379. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 10.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
  380. "\n",
  381. "\n",
  382. "getting paths: 150it [00:00, 16108.40it/s]\n",
  383. "calculating kernels: 11325it [00:00, 328896.12it/s]\n",
  384. "\n",
  385. " --- kernel matrix of path kernel up to 10 of size 150 built in 0.301084041595459 seconds ---\n",
  386. "\n",
  387. "the gram matrix with parameters {'compute_method': 'trie', 'depth': 10.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
  388. "\n",
  389. "\n",
  390. "\n",
  391. "20 gram matrices are calculated, 0 of which are ignored.\n",
  392. "\n",
  393. "3. Fitting and predicting using nested cross validation. This could really take a while...\n",
  394. "cross validation: 0it [00:00, ?it/s]"
  395. ]
  396. }
  397. ],
  398. "source": [
  399. "# %load_ext line_profiler\n",
  400. "# %matplotlib inline\n",
  401. "from libs import *\n",
  402. "import multiprocessing\n",
  403. "\n",
  404. "from pygraph.kernels.untilHPathKernel import untilhpathkernel\n",
  405. "from pygraph.utils.kernels import deltakernel, kernelproduct\n",
  406. "\n",
  407. "dslist = [\n",
  408. " {'name': 'Acyclic', 'dataset': '../datasets/acyclic/dataset_bps.ds',\n",
  409. " 'task': 'regression'}, # node symb\n",
  410. " {'name': 'Alkane', 'dataset': '../datasets/Alkane/dataset.ds', 'task': 'regression',\n",
  411. " 'dataset_y': '../datasets/Alkane/dataset_boiling_point_names.txt', }, \n",
  412. " # contains single node graph, node symb\n",
  413. " {'name': 'MAO', 'dataset': '../datasets/MAO/dataset.ds', }, # node/edge symb\n",
  414. " {'name': 'PAH', 'dataset': '../datasets/PAH/dataset.ds', }, # unlabeled\n",
  415. " {'name': 'MUTAG', 'dataset': '../datasets/MUTAG/MUTAG.mat',\n",
  416. " 'extra_params': {'am_sp_al_nl_el': [0, 0, 3, 1, 2]}}, # node/edge symb\n",
  417. " {'name': 'Letter-med', 'dataset': '../datasets/Letter-med/Letter-med_A.txt'},\n",
  418. " # node nsymb\n",
  419. " {'name': 'ENZYMES', 'dataset': '../datasets/ENZYMES_txt/ENZYMES_A_sparse.txt'},\n",
  420. " # node symb/nsymb\n",
  421. "# {'name': 'Mutagenicity', 'dataset': '../datasets/Mutagenicity/Mutagenicity_A.txt'},\n",
  422. "# # node/edge symb\n",
  423. "# {'name': 'D&D', 'dataset': '../datasets/D&D/DD.mat',\n",
  424. "# 'extra_params': {'am_sp_al_nl_el': [0, 1, 2, 1, -1]}}, # node symb\n",
  425. "\n",
  426. " # {'name': 'COIL-DEL', 'dataset': '../datasets/COIL-DEL/COIL-DEL_A.txt'}, # edge symb, node nsymb\n",
  427. " # # # {'name': 'BZR', 'dataset': '../datasets/BZR_txt/BZR_A_sparse.txt'}, # node symb/nsymb\n",
  428. " # # # {'name': 'COX2', 'dataset': '../datasets/COX2_txt/COX2_A_sparse.txt'}, # node symb/nsymb\n",
  429. " # {'name': 'Fingerprint', 'dataset': '../datasets/Fingerprint/Fingerprint_A.txt'},\n",
  430. " #\n",
  431. " # # {'name': 'DHFR', 'dataset': '../datasets/DHFR_txt/DHFR_A_sparse.txt'}, # node symb/nsymb\n",
  432. " # # {'name': 'SYNTHETIC', 'dataset': '../datasets/SYNTHETIC_txt/SYNTHETIC_A_sparse.txt'}, # node symb/nsymb\n",
  433. " # # {'name': 'MSRC9', 'dataset': '../datasets/MSRC_9_txt/MSRC_9_A.txt'}, # node symb\n",
  434. " # # {'name': 'MSRC21', 'dataset': '../datasets/MSRC_21_txt/MSRC_21_A.txt'}, # node symb\n",
  435. " # # {'name': 'FIRSTMM_DB', 'dataset': '../datasets/FIRSTMM_DB/FIRSTMM_DB_A.txt'}, # node symb/nsymb ,edge nsymb\n",
  436. "\n",
  437. " # # {'name': 'PROTEINS', 'dataset': '../datasets/PROTEINS_txt/PROTEINS_A_sparse.txt'}, # node symb/nsymb\n",
  438. " # # {'name': 'PROTEINS_full', 'dataset': '../datasets/PROTEINS_full_txt/PROTEINS_full_A_sparse.txt'}, # node symb/nsymb\n",
  439. " # # {'name': 'AIDS', 'dataset': '../datasets/AIDS/AIDS_A.txt'}, # node symb/nsymb, edge symb\n",
  440. " # {'name': 'NCI1', 'dataset': '../datasets/NCI1/NCI1.mat',\n",
  441. " # 'extra_params': {'am_sp_al_nl_el': [1, 1, 2, 0, -1]}}, # node symb\n",
  442. " # {'name': 'NCI109', 'dataset': '../datasets/NCI109/NCI109.mat',\n",
  443. " # 'extra_params': {'am_sp_al_nl_el': [1, 1, 2, 0, -1]}}, # node symb\n",
  444. " # {'name': 'NCI-HIV', 'dataset': '../datasets/NCI-HIV/AIDO99SD.sdf',\n",
  445. " # 'dataset_y': '../datasets/NCI-HIV/aids_conc_may04.txt',}, # node/edge symb\n",
  446. "\n",
  447. " # # not working below\n",
  448. " # {'name': 'PTC_FM', 'dataset': '../datasets/PTC/Train/FM.ds',},\n",
  449. " # {'name': 'PTC_FR', 'dataset': '../datasets/PTC/Train/FR.ds',},\n",
  450. " # {'name': 'PTC_MM', 'dataset': '../datasets/PTC/Train/MM.ds',},\n",
  451. " # {'name': 'PTC_MR', 'dataset': '../datasets/PTC/Train/MR.ds',},\n",
  452. "]\n",
  453. "estimator = untilhpathkernel\n",
  454. "param_grid_precomputed = {'depth': np.linspace(1, 10, 10), # [2], \n",
  455. " 'k_func': ['MinMax', 'tanimoto'],\n",
  456. " 'compute_method': ['trie']} # ['MinMax']}\n",
  457. "param_grid = [{'C': np.logspace(-10, 10, num=41, base=10)},\n",
  458. " {'alpha': np.logspace(-10, 10, num=41, base=10)}]\n",
  459. "\n",
  460. "for ds in dslist:\n",
  461. " print()\n",
  462. " print(ds['name'])\n",
  463. " model_selection_for_precomputed_kernel(\n",
  464. " ds['dataset'],\n",
  465. " estimator,\n",
  466. " param_grid_precomputed,\n",
  467. " (param_grid[1] if ('task' in ds and ds['task']\n",
  468. " == 'regression') else param_grid[0]),\n",
  469. " (ds['task'] if 'task' in ds else 'classification'),\n",
  470. " NUM_TRIALS=30,\n",
  471. " datafile_y=(ds['dataset_y'] if 'dataset_y' in ds else None),\n",
  472. " extra_params=(ds['extra_params'] if 'extra_params' in ds else None),\n",
  473. " ds_name=ds['name'],\n",
  474. " n_jobs=multiprocessing.cpu_count(),\n",
  475. " read_gm_from_file=False)\n",
  476. " print()"
  477. ]
  478. },
  479. {
  480. "cell_type": "code",
  481. "execution_count": 2,
  482. "metadata": {},
  483. "outputs": [
  484. {
  485. "ename": "ModuleNotFoundError",
  486. "evalue": "No module named 'line_profiler'",
  487. "output_type": "error",
  488. "traceback": [
  489. "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
  490. "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
  491. "\u001b[0;32m<ipython-input-2-cf4da93eeb50>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_line_magic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'load_ext'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'line_profiler'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minsert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"../\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mpygraph\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mutils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mutils\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mkernel_train_test\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  492. "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py\u001b[0m in \u001b[0;36mrun_line_magic\u001b[0;34m(self, magic_name, line, _stack_depth)\u001b[0m\n\u001b[1;32m 2283\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'local_ns'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_getframe\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstack_depth\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mf_locals\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2284\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbuiltin_trap\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2285\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2286\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2287\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
  493. "\u001b[0;32m<decorator-gen-65>\u001b[0m in \u001b[0;36mload_ext\u001b[0;34m(self, module_str)\u001b[0m\n",
  494. "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/IPython/core/magic.py\u001b[0m in \u001b[0;36m<lambda>\u001b[0;34m(f, *a, **k)\u001b[0m\n\u001b[1;32m 185\u001b[0m \u001b[0;31m# but it's overkill for just that one bit of state.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 186\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmagic_deco\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 187\u001b[0;31m \u001b[0mcall\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mlambda\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 188\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 189\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcallable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  495. "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/IPython/core/magics/extension.py\u001b[0m in \u001b[0;36mload_ext\u001b[0;34m(self, module_str)\u001b[0m\n\u001b[1;32m 31\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mmodule_str\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 32\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mUsageError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Missing module name.'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 33\u001b[0;31m \u001b[0mres\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshell\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mextension_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload_extension\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodule_str\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 34\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mres\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'already loaded'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  496. "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/IPython/core/extensions.py\u001b[0m in \u001b[0;36mload_extension\u001b[0;34m(self, module_str)\u001b[0m\n\u001b[1;32m 78\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mmodule_str\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodules\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 79\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mprepended_to_syspath\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mipython_extension_dir\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 80\u001b[0;31m \u001b[0mmod\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mimport_module\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodule_str\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 81\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mmod\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__file__\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstartswith\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mipython_extension_dir\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 82\u001b[0m print((\"Loading extensions from {dir} is deprecated. \"\n",
  497. "\u001b[0;32m/usr/lib/python3.6/importlib/__init__.py\u001b[0m in \u001b[0;36mimport_module\u001b[0;34m(name, package)\u001b[0m\n\u001b[1;32m 124\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 125\u001b[0m \u001b[0mlevel\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 126\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0m_bootstrap\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_gcd_import\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mlevel\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpackage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 127\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 128\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
  498. "\u001b[0;32m/usr/lib/python3.6/importlib/_bootstrap.py\u001b[0m in \u001b[0;36m_gcd_import\u001b[0;34m(name, package, level)\u001b[0m\n",
  499. "\u001b[0;32m/usr/lib/python3.6/importlib/_bootstrap.py\u001b[0m in \u001b[0;36m_find_and_load\u001b[0;34m(name, import_)\u001b[0m\n",
  500. "\u001b[0;32m/usr/lib/python3.6/importlib/_bootstrap.py\u001b[0m in \u001b[0;36m_find_and_load_unlocked\u001b[0;34m(name, import_)\u001b[0m\n",
  501. "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'line_profiler'"
  502. ]
  503. }
  504. ],
  505. "source": [
  506. "%load_ext line_profiler\n",
  507. "\n",
  508. "import sys\n",
  509. "sys.path.insert(0, \"../\")\n",
  510. "from pygraph.utils.utils import kernel_train_test\n",
  511. "from pygraph.kernels.untildPathKernel import untildpathkernel\n",
  512. "\n",
  513. "import numpy as np\n",
  514. "\n",
  515. "datafile = '../../datasets/acyclic/Acyclic/dataset_bps.ds'\n",
  516. "kernel_file_path = 'kernelmatrices_path_acyclic/'\n",
  517. "\n",
  518. "kernel_para = dict(node_label = 'atom', edge_label = 'bond_type', labeled = True, k_func = 'tanimoto')\n",
  519. "\n",
  520. "# kernel_train_test(datafile, kernel_file_path, treeletkernel, kernel_para, normalize = False)\n",
  521. "\n",
  522. "kernel_train_test(datafile, kernel_file_path, untildpathkernel, kernel_para, \\\n",
  523. " hyper_name = 'depth', hyper_range = np.linspace(0, 20, 21), normalize = True)\n",
  524. "kernel_train_test(datafile, kernel_file_path, untildpathkernel, kernel_para, \\\n",
  525. " hyper_name = 'depth', hyper_range = np.linspace(0, 20, 21), normalize = False)\n",
  526. "\n",
  527. "kernel_para['k_func'] = 'minmax'\n",
  528. "kernel_train_test(datafile, kernel_file_path, untildpathkernel, kernel_para, \\\n",
  529. " hyper_name = 'depth', hyper_range = np.linspace(0, 10, 11), normalize = True)\n",
  530. "kernel_train_test(datafile, kernel_file_path, untildpathkernel, kernel_para, \\\n",
  531. " hyper_name = 'depth', hyper_range = np.linspace(0, 10, 11), normalize = False)\n",
  532. "\n",
  533. "# # kernel_train_test(datafile, kernel_file_path, untildpathkernel, kernel_para, normalize = False)\n",
  534. "\n",
  535. "# kernel_para['depth'] = 10\n",
  536. "# %lprun -f untildpathkernel \\\n",
  537. "# kernel_train_test(datafile, kernel_file_path, untildpathkernel, kernel_para, normalize = False)"
  538. ]
  539. }
  540. ],
  541. "metadata": {
  542. "kernelspec": {
  543. "display_name": "Python 3",
  544. "language": "python",
  545. "name": "python3"
  546. },
  547. "language_info": {
  548. "codemirror_mode": {
  549. "name": "ipython",
  550. "version": 3
  551. },
  552. "file_extension": ".py",
  553. "mimetype": "text/x-python",
  554. "name": "python",
  555. "nbconvert_exporter": "python",
  556. "pygments_lexer": "ipython3",
  557. "version": "3.6.7"
  558. }
  559. },
  560. "nbformat": 4,
  561. "nbformat_minor": 2
  562. }

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