|
@@ -0,0 +1,264 @@ |
|
|
|
|
|
{ |
|
|
|
|
|
"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", |
|
|
|
|
|
"\n", |
|
|
|
|
|
" None edge weight specified. Set all weight to 1.\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"getting sp graphs: 183it [00:00, 11704.68it/s]\n", |
|
|
|
|
|
"calculating kernels: 16836it [00:00, 17085.14it/s]\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
" --- shortest path kernel matrix of size 183 built in 1.2640743255615234 seconds ---\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"the gram matrix with parameters {'node_kernels': {'symb': <function deltakernel at 0x7fe84734e598>, 'nsymb': <function gaussiankernel at 0x7fe84734e620>, 'mix': functools.partial(<function kernelproduct at 0x7fe84734e730>, <function deltakernel at 0x7fe84734e598>, <function gaussiankernel at 0x7fe84734e620>)}, 'n_jobs': 8, 'verbose': True} is: \n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"1 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 [00:03, 8.84it/s]\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"4. Getting final performance...\n", |
|
|
|
|
|
"best_params_out: [{'node_kernels': {'symb': <function deltakernel at 0x7fe84734e598>, 'nsymb': <function gaussiankernel at 0x7fe84734e620>, 'mix': functools.partial(<function kernelproduct at 0x7fe84734e730>, <function deltakernel at 0x7fe84734e598>, <function gaussiankernel at 0x7fe84734e620>)}, 'n_jobs': 8, 'verbose': True}]\n", |
|
|
|
|
|
"best_params_in: [{'alpha': 1e-10}]\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"best_val_perf: 9.687399048018559\n", |
|
|
|
|
|
"best_val_std: 0.654180946161292\n", |
|
|
|
|
|
"final_performance: [9.411656660355659]\n", |
|
|
|
|
|
"final_confidence: [2.500437167823725]\n", |
|
|
|
|
|
"train_performance: [6.168480355249007]\n", |
|
|
|
|
|
"train_std: [0.2541557651056269]\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"time to calculate gram matrix with different hyper-params: 1.26±0.00s\n", |
|
|
|
|
|
"time to calculate best gram matrix: 1.26±0.00s\n", |
|
|
|
|
|
"total training time with all hyper-param choices: 5.09s\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\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", |
|
|
|
|
|
"\n", |
|
|
|
|
|
" None edge weight specified. Set all weight to 1.\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
" 1 graphs are removed as they don't contain edges.\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"getting sp graphs: 149it [00:00, 7096.72it/s]\n", |
|
|
|
|
|
"calculating kernels: 11175it [00:00, 19504.73it/s]\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
" --- shortest path kernel matrix of size 149 built in 0.7957959175109863 seconds ---\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"the gram matrix with parameters {'node_kernels': {'symb': <function deltakernel at 0x7fe84734e598>, 'nsymb': <function gaussiankernel at 0x7fe84734e620>, 'mix': functools.partial(<function kernelproduct at 0x7fe84734e730>, <function deltakernel at 0x7fe84734e598>, <function gaussiankernel at 0x7fe84734e620>)}, 'n_jobs': 8, 'verbose': True} is: \n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"1 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 [00:02, 10.74it/s]\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"4. Getting final performance...\n", |
|
|
|
|
|
"best_params_out: [{'node_kernels': {'symb': <function deltakernel at 0x7fe84734e598>, 'nsymb': <function gaussiankernel at 0x7fe84734e620>, 'mix': functools.partial(<function kernelproduct at 0x7fe84734e730>, <function deltakernel at 0x7fe84734e598>, <function gaussiankernel at 0x7fe84734e620>)}, 'n_jobs': 8, 'verbose': True}]\n", |
|
|
|
|
|
"best_params_in: [{'alpha': 1e-05}]\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"best_val_perf: 8.745832519261795\n", |
|
|
|
|
|
"best_val_std: 0.26293501071192543\n", |
|
|
|
|
|
"final_performance: [7.942686332248635]\n", |
|
|
|
|
|
"final_confidence: [1.617779657027359]\n", |
|
|
|
|
|
"train_performance: [7.860965083396337]\n", |
|
|
|
|
|
"train_std: [0.16888913664254188]\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"time to calculate gram matrix with different hyper-params: 0.80±0.00s\n", |
|
|
|
|
|
"time to calculate best gram matrix: 0.80±0.00s\n", |
|
|
|
|
|
"total training time with all hyper-param choices: 3.90s\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"MAO\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"--- This is a classification problem ---\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"1. Loading dataset from file...\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"2. Calculating gram matrices. This could take a while...\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
" None edge weight specified. Set all weight to 1.\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"getting sp graphs: 68it [00:00, 2292.58it/s]\n", |
|
|
|
|
|
"calculating kernels: 2346it [00:02, 873.39it/s]\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
" --- shortest path kernel matrix of size 68 built in 2.986046075820923 seconds ---\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"the gram matrix with parameters {'node_kernels': {'symb': <function deltakernel at 0x7fe84734e598>, 'nsymb': <function gaussiankernel at 0x7fe84734e620>, 'mix': functools.partial(<function kernelproduct at 0x7fe84734e730>, <function deltakernel at 0x7fe84734e598>, <function gaussiankernel at 0x7fe84734e620>)}, 'n_jobs': 8, 'verbose': True} is: \n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"1 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 [00:02, 11.85it/s]\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"4. Getting final performance...\n", |
|
|
|
|
|
"best_params_out: [{'node_kernels': {'symb': <function deltakernel at 0x7fe84734e598>, 'nsymb': <function gaussiankernel at 0x7fe84734e620>, 'mix': functools.partial(<function kernelproduct at 0x7fe84734e730>, <function deltakernel at 0x7fe84734e598>, <function gaussiankernel at 0x7fe84734e620>)}, 'n_jobs': 8, 'verbose': True}]\n", |
|
|
|
|
|
"best_params_in: [{'C': 3162.2776601683795}]\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"best_val_perf: 0.8780158730158729\n", |
|
|
|
|
|
"best_val_std: 0.028162670831398482\n", |
|
|
|
|
|
"final_performance: [0.8714285714285714]\n", |
|
|
|
|
|
"final_confidence: [0.09446318571439967]\n", |
|
|
|
|
|
"train_performance: [0.9740729517396185]\n", |
|
|
|
|
|
"train_std: [0.007872630412568218]\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"time to calculate gram matrix with different hyper-params: 2.99±0.00s\n", |
|
|
|
|
|
"time to calculate best gram matrix: 2.99±0.00s\n", |
|
|
|
|
|
"total training time with all hyper-param choices: 5.93s\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"PAH\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"--- This is a classification problem ---\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"1. Loading dataset from file...\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"2. Calculating gram matrices. This could take a while...\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
" None edge weight specified. Set all weight to 1.\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"getting sp graphs: 94it [00:00, 2131.93it/s]\n", |
|
|
|
|
|
"calculating kernels: 1501it [00:01, 78.00it/s]" |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
], |
|
|
|
|
|
"source": [ |
|
|
|
|
|
"import functools\n", |
|
|
|
|
|
"from libs import *\n", |
|
|
|
|
|
"import multiprocessing\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"from gklearn.kernels.spKernel import spkernel\n", |
|
|
|
|
|
"from gklearn.utils.kernels import deltakernel, gaussiankernel, kernelproduct\n", |
|
|
|
|
|
"#from gklearn.utils.model_selection_precomputed import trial_do\n", |
|
|
|
|
|
"\n", |
|
|
|
|
|
"# datasets\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_A.txt'}, # 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/DD/DD_A.txt'}, # 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", |
|
|
|
|
|
"# {'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 = spkernel\n", |
|
|
|
|
|
"# hyper-parameters\n", |
|
|
|
|
|
"mixkernel = functools.partial(kernelproduct, deltakernel, gaussiankernel)\n", |
|
|
|
|
|
"param_grid_precomputed = {'node_kernels': [\n", |
|
|
|
|
|
" {'symb': deltakernel, 'nsymb': gaussiankernel, 'mix': mixkernel}]}\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 each dataset, do model selection.\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", |
|
|
|
|
|
" verbose=True)\n", |
|
|
|
|
|
" print()" |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
], |
|
|
|
|
|
"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 |
|
|
|
|
|
} |