|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562 |
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "scrolled": false
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\n",
- "Acyclic\n",
- "\n",
- "--- This is a regression problem ---\n",
- "\n",
- "\n",
- "1. Loading dataset from file...\n",
- "\n",
- "2. Calculating gram matrices. This could take a while...\n",
- "getting paths: 183it [00:00, 33583.79it/s]\n",
- "calculating kernels: 16836it [00:00, 382919.33it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 1 of size 183 built in 0.28138017654418945 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 1.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 49932.19it/s]\n",
- "calculating kernels: 16836it [00:00, 339040.24it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 1 of size 183 built in 0.2915959358215332 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 1.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 13100.71it/s]\n",
- "calculating kernels: 16836it [00:00, 195915.25it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 2 of size 183 built in 0.39291882514953613 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 2.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 15186.23it/s]\n",
- "calculating kernels: 16836it [00:00, 216679.82it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 2 of size 183 built in 0.2922053337097168 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 2.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 8410.48it/s]\n",
- "calculating kernels: 16836it [00:00, 146690.73it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 3 of size 183 built in 0.3915746212005615 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 3.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 13951.28it/s]\n",
- "calculating kernels: 16836it [00:00, 201673.88it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 3 of size 183 built in 0.3854410648345947 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 3.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 10054.46it/s]\n",
- "calculating kernels: 16836it [00:00, 70713.10it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 4 of size 183 built in 0.48105573654174805 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 4.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 1418.94it/s]\n",
- "calculating kernels: 16836it [00:00, 144898.57it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 4 of size 183 built in 0.5477819442749023 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 4.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 15604.25it/s]\n",
- "calculating kernels: 16836it [00:00, 103300.82it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 5 of size 183 built in 0.3788299560546875 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 5.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 9795.27it/s]\n",
- "calculating kernels: 16836it [00:00, 121689.68it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 5 of size 183 built in 0.3888108730316162 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 5.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 7163.19it/s]\n",
- "calculating kernels: 16836it [00:00, 89262.17it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 6 of size 183 built in 0.39624905586242676 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 6.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 16751.59it/s]\n",
- "calculating kernels: 16836it [00:00, 100004.39it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 6 of size 183 built in 0.388913631439209 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 6.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 10090.81it/s]\n",
- "calculating kernels: 16836it [00:00, 91172.28it/s] \n",
- "\n",
- " --- kernel matrix of path kernel up to 7 of size 183 built in 0.4908461570739746 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 7.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 2997.78it/s]\n",
- "calculating kernels: 16836it [00:00, 104945.65it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 7 of size 183 built in 0.36611366271972656 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 7.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 6353.90it/s]\n",
- "calculating kernels: 16836it [00:00, 80425.25it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 8 of size 183 built in 0.5061323642730713 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 8.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 9427.60it/s]\n",
- "calculating kernels: 16836it [00:00, 93863.88it/s] \n",
- "\n",
- " --- kernel matrix of path kernel up to 8 of size 183 built in 0.3872077465057373 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 8.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 7575.20it/s]\n",
- "calculating kernels: 16836it [00:00, 82517.07it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 9 of size 183 built in 0.48129963874816895 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 9.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 6563.74it/s]\n",
- "calculating kernels: 16836it [00:00, 94045.02it/s] \n",
- "\n",
- " --- kernel matrix of path kernel up to 9 of size 183 built in 0.39592933654785156 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 9.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 6069.81it/s]\n",
- "calculating kernels: 16836it [00:00, 77447.83it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 10 of size 183 built in 0.47420382499694824 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 10.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 183it [00:00, 9481.17it/s]\n",
- "calculating kernels: 16836it [00:00, 58253.60it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 10 of size 183 built in 0.4869115352630615 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 10.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "\n",
- "20 gram matrices are calculated, 0 of which are ignored.\n",
- "\n",
- "3. Fitting and predicting using nested cross validation. This could really take a while...\n",
- "cross validation: 30it [01:07, 1.10s/it]\n",
- "\n",
- "4. Getting final performance...\n",
- "best_params_out: [{'compute_method': 'trie', 'depth': 2.0, 'k_func': 'MinMax', 'n_jobs': 8}]\n",
- "best_params_in: [{'alpha': 0.01}]\n",
- "\n",
- "best_val_perf: 6.8347760734601675\n",
- "best_val_std: 0.26187601855914455\n",
- "final_performance: [6.844597847292873]\n",
- "final_confidence: [1.3282917788841784]\n",
- "train_performance: [2.2886614412566524]\n",
- "train_std: [0.11697823620293107]\n",
- "\n",
- "time to calculate gram matrix with different hyper-params: 0.41±0.07s\n",
- "time to calculate best gram matrix: 0.39±nans\n",
- "total training time with all hyper-param choices: 82.00s\n",
- "\n"
- ]
- },
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py:140: RuntimeWarning: Degrees of freedom <= 0 for slice\n",
- " keepdims=keepdims)\n",
- "/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py:132: RuntimeWarning: invalid value encountered in double_scalars\n",
- " ret = ret.dtype.type(ret / rcount)\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\n",
- "\n",
- "Alkane\n",
- "\n",
- "--- This is a regression problem ---\n",
- "\n",
- "\n",
- "1. Loading dataset from file...\n",
- "\n",
- "2. Calculating gram matrices. This could take a while...\n",
- "getting paths: 150it [00:00, 38060.83it/s]\n",
- "calculating kernels: 11325it [00:00, 447307.64it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 1 of size 150 built in 0.29852986335754395 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 1.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 16860.39it/s]\n",
- "calculating kernels: 11325it [00:00, 522115.40it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 1 of size 150 built in 0.29816317558288574 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 1.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 18149.30it/s]\n",
- "calculating kernels: 11325it [00:00, 383173.55it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 2 of size 150 built in 0.29796385765075684 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 2.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 23172.10it/s]\n",
- "calculating kernels: 11325it [00:00, 427074.37it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 2 of size 150 built in 0.3109288215637207 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 2.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 13243.78it/s]\n",
- "calculating kernels: 11325it [00:00, 269283.28it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 3 of size 150 built in 0.29997825622558594 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 3.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 20671.78it/s]\n",
- "calculating kernels: 11325it [00:00, 312080.29it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 3 of size 150 built in 0.29572534561157227 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 3.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 15393.45it/s]\n",
- "calculating kernels: 11325it [00:00, 362928.87it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 4 of size 150 built in 0.30132484436035156 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 4.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 16957.65it/s]\n",
- "calculating kernels: 11325it [00:00, 84503.61it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 4 of size 150 built in 0.4178507328033447 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 4.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 14440.54it/s]\n",
- "calculating kernels: 11325it [00:00, 276894.92it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 5 of size 150 built in 0.29338693618774414 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 5.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 15619.30it/s]\n",
- "calculating kernels: 11325it [00:00, 254676.58it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 5 of size 150 built in 0.29663729667663574 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 5.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 14585.84it/s]\n",
- "calculating kernels: 11325it [00:00, 242964.30it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 6 of size 150 built in 0.29677391052246094 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 6.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 11555.83it/s]\n",
- "calculating kernels: 11325it [00:00, 330949.31it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 6 of size 150 built in 0.2948622703552246 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 6.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 10424.60it/s]\n",
- "calculating kernels: 11325it [00:00, 238514.96it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 7 of size 150 built in 0.3041496276855469 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 7.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 12318.80it/s]\n",
- "calculating kernels: 11325it [00:00, 251979.97it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 7 of size 150 built in 0.3013496398925781 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 7.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 10722.00it/s]\n",
- "calculating kernels: 11325it [00:00, 232363.74it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 8 of size 150 built in 0.294144868850708 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 8.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 18965.59it/s]\n",
- "calculating kernels: 11325it [00:00, 424638.55it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 8 of size 150 built in 0.2961091995239258 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 8.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 13945.38it/s]\n",
- "calculating kernels: 11325it [00:00, 286344.19it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 9 of size 150 built in 0.30029296875 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 9.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 9525.87it/s]\n",
- "calculating kernels: 11325it [00:00, 231776.43it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 9 of size 150 built in 0.29835057258605957 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 9.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 16916.15it/s]\n",
- "calculating kernels: 11325it [00:00, 85396.60it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 10 of size 150 built in 0.42621588706970215 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 10.0, 'k_func': 'MinMax', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "getting paths: 150it [00:00, 16108.40it/s]\n",
- "calculating kernels: 11325it [00:00, 328896.12it/s]\n",
- "\n",
- " --- kernel matrix of path kernel up to 10 of size 150 built in 0.301084041595459 seconds ---\n",
- "\n",
- "the gram matrix with parameters {'compute_method': 'trie', 'depth': 10.0, 'k_func': 'tanimoto', 'n_jobs': 8} is: \n",
- "\n",
- "\n",
- "\n",
- "20 gram matrices are calculated, 0 of which are ignored.\n",
- "\n",
- "3. Fitting and predicting using nested cross validation. This could really take a while...\n",
- "cross validation: 0it [00:00, ?it/s]"
- ]
- }
- ],
- "source": [
- "# %load_ext line_profiler\n",
- "# %matplotlib inline\n",
- "from libs import *\n",
- "import multiprocessing\n",
- "\n",
- "from pygraph.kernels.untilHPathKernel import untilhpathkernel\n",
- "from pygraph.utils.kernels import deltakernel, kernelproduct\n",
- "\n",
- "dslist = [\n",
- " {'name': 'Acyclic', 'dataset': '../datasets/acyclic/dataset_bps.ds',\n",
- " 'task': 'regression'}, # node symb\n",
- " {'name': 'Alkane', 'dataset': '../datasets/Alkane/dataset.ds', 'task': 'regression',\n",
- " 'dataset_y': '../datasets/Alkane/dataset_boiling_point_names.txt', }, \n",
- " # contains single node graph, node symb\n",
- " {'name': 'MAO', 'dataset': '../datasets/MAO/dataset.ds', }, # node/edge symb\n",
- " {'name': 'PAH', 'dataset': '../datasets/PAH/dataset.ds', }, # unlabeled\n",
- " {'name': 'MUTAG', 'dataset': '../datasets/MUTAG/MUTAG.mat',\n",
- " 'extra_params': {'am_sp_al_nl_el': [0, 0, 3, 1, 2]}}, # node/edge symb\n",
- " {'name': 'Letter-med', 'dataset': '../datasets/Letter-med/Letter-med_A.txt'},\n",
- " # node nsymb\n",
- " {'name': 'ENZYMES', 'dataset': '../datasets/ENZYMES_txt/ENZYMES_A_sparse.txt'},\n",
- " # node symb/nsymb\n",
- "# {'name': 'Mutagenicity', 'dataset': '../datasets/Mutagenicity/Mutagenicity_A.txt'},\n",
- "# # node/edge symb\n",
- "# {'name': 'D&D', 'dataset': '../datasets/D&D/DD.mat',\n",
- "# 'extra_params': {'am_sp_al_nl_el': [0, 1, 2, 1, -1]}}, # node symb\n",
- "\n",
- " # {'name': 'COIL-DEL', 'dataset': '../datasets/COIL-DEL/COIL-DEL_A.txt'}, # edge symb, node nsymb\n",
- " # # # {'name': 'BZR', 'dataset': '../datasets/BZR_txt/BZR_A_sparse.txt'}, # node symb/nsymb\n",
- " # # # {'name': 'COX2', 'dataset': '../datasets/COX2_txt/COX2_A_sparse.txt'}, # node symb/nsymb\n",
- " # {'name': 'Fingerprint', 'dataset': '../datasets/Fingerprint/Fingerprint_A.txt'},\n",
- " #\n",
- " # # {'name': 'DHFR', 'dataset': '../datasets/DHFR_txt/DHFR_A_sparse.txt'}, # node symb/nsymb\n",
- " # # {'name': 'SYNTHETIC', 'dataset': '../datasets/SYNTHETIC_txt/SYNTHETIC_A_sparse.txt'}, # node symb/nsymb\n",
- " # # {'name': 'MSRC9', 'dataset': '../datasets/MSRC_9_txt/MSRC_9_A.txt'}, # node symb\n",
- " # # {'name': 'MSRC21', 'dataset': '../datasets/MSRC_21_txt/MSRC_21_A.txt'}, # node symb\n",
- " # # {'name': 'FIRSTMM_DB', 'dataset': '../datasets/FIRSTMM_DB/FIRSTMM_DB_A.txt'}, # node symb/nsymb ,edge nsymb\n",
- "\n",
- " # # {'name': 'PROTEINS', 'dataset': '../datasets/PROTEINS_txt/PROTEINS_A_sparse.txt'}, # node symb/nsymb\n",
- " # # {'name': 'PROTEINS_full', 'dataset': '../datasets/PROTEINS_full_txt/PROTEINS_full_A_sparse.txt'}, # node symb/nsymb\n",
- " # # {'name': 'AIDS', 'dataset': '../datasets/AIDS/AIDS_A.txt'}, # node symb/nsymb, edge symb\n",
- " # {'name': 'NCI1', 'dataset': '../datasets/NCI1/NCI1.mat',\n",
- " # 'extra_params': {'am_sp_al_nl_el': [1, 1, 2, 0, -1]}}, # node symb\n",
- " # {'name': 'NCI109', 'dataset': '../datasets/NCI109/NCI109.mat',\n",
- " # 'extra_params': {'am_sp_al_nl_el': [1, 1, 2, 0, -1]}}, # node symb\n",
- " # {'name': 'NCI-HIV', 'dataset': '../datasets/NCI-HIV/AIDO99SD.sdf',\n",
- " # 'dataset_y': '../datasets/NCI-HIV/aids_conc_may04.txt',}, # node/edge symb\n",
- "\n",
- " # # not working below\n",
- " # {'name': 'PTC_FM', 'dataset': '../datasets/PTC/Train/FM.ds',},\n",
- " # {'name': 'PTC_FR', 'dataset': '../datasets/PTC/Train/FR.ds',},\n",
- " # {'name': 'PTC_MM', 'dataset': '../datasets/PTC/Train/MM.ds',},\n",
- " # {'name': 'PTC_MR', 'dataset': '../datasets/PTC/Train/MR.ds',},\n",
- "]\n",
- "estimator = untilhpathkernel\n",
- "param_grid_precomputed = {'depth': np.linspace(1, 10, 10), # [2], \n",
- " 'k_func': ['MinMax', 'tanimoto'],\n",
- " 'compute_method': ['trie']} # ['MinMax']}\n",
- "param_grid = [{'C': np.logspace(-10, 10, num=41, base=10)},\n",
- " {'alpha': np.logspace(-10, 10, num=41, base=10)}]\n",
- "\n",
- "for ds in dslist:\n",
- " print()\n",
- " print(ds['name'])\n",
- " model_selection_for_precomputed_kernel(\n",
- " ds['dataset'],\n",
- " estimator,\n",
- " param_grid_precomputed,\n",
- " (param_grid[1] if ('task' in ds and ds['task']\n",
- " == 'regression') else param_grid[0]),\n",
- " (ds['task'] if 'task' in ds else 'classification'),\n",
- " NUM_TRIALS=30,\n",
- " datafile_y=(ds['dataset_y'] if 'dataset_y' in ds else None),\n",
- " extra_params=(ds['extra_params'] if 'extra_params' in ds else None),\n",
- " ds_name=ds['name'],\n",
- " n_jobs=multiprocessing.cpu_count(),\n",
- " read_gm_from_file=False)\n",
- " print()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "ename": "ModuleNotFoundError",
- "evalue": "No module named 'line_profiler'",
- "output_type": "error",
- "traceback": [
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
- "\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",
- "\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",
- "\u001b[0;32m<decorator-gen-65>\u001b[0m in \u001b[0;36mload_ext\u001b[0;34m(self, module_str)\u001b[0m\n",
- "\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",
- "\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",
- "\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",
- "\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",
- "\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",
- "\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",
- "\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",
- "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'line_profiler'"
- ]
- }
- ],
- "source": [
- "%load_ext line_profiler\n",
- "\n",
- "import sys\n",
- "sys.path.insert(0, \"../\")\n",
- "from pygraph.utils.utils import kernel_train_test\n",
- "from pygraph.kernels.untildPathKernel import untildpathkernel\n",
- "\n",
- "import numpy as np\n",
- "\n",
- "datafile = '../../datasets/acyclic/Acyclic/dataset_bps.ds'\n",
- "kernel_file_path = 'kernelmatrices_path_acyclic/'\n",
- "\n",
- "kernel_para = dict(node_label = 'atom', edge_label = 'bond_type', labeled = True, k_func = 'tanimoto')\n",
- "\n",
- "# kernel_train_test(datafile, kernel_file_path, treeletkernel, kernel_para, normalize = False)\n",
- "\n",
- "kernel_train_test(datafile, kernel_file_path, untildpathkernel, kernel_para, \\\n",
- " hyper_name = 'depth', hyper_range = np.linspace(0, 20, 21), normalize = True)\n",
- "kernel_train_test(datafile, kernel_file_path, untildpathkernel, kernel_para, \\\n",
- " hyper_name = 'depth', hyper_range = np.linspace(0, 20, 21), normalize = False)\n",
- "\n",
- "kernel_para['k_func'] = 'minmax'\n",
- "kernel_train_test(datafile, kernel_file_path, untildpathkernel, kernel_para, \\\n",
- " hyper_name = 'depth', hyper_range = np.linspace(0, 10, 11), normalize = True)\n",
- "kernel_train_test(datafile, kernel_file_path, untildpathkernel, kernel_para, \\\n",
- " hyper_name = 'depth', hyper_range = np.linspace(0, 10, 11), normalize = False)\n",
- "\n",
- "# # kernel_train_test(datafile, kernel_file_path, untildpathkernel, kernel_para, normalize = False)\n",
- "\n",
- "# kernel_para['depth'] = 10\n",
- "# %lprun -f untildpathkernel \\\n",
- "# kernel_train_test(datafile, kernel_file_path, untildpathkernel, kernel_para, normalize = False)"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.6.7"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
|