{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Predicting DWPC Query runtime ahead of time"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import json\n",
"\n",
"import matplotlib.pyplot\n",
"import pandas\n",
"import numpy\n",
"import seaborn\n",
"import mpld3\n",
"\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"path = '../all-features/data/metapaths.json'\n",
"with open(path) as fp:\n",
" metapaths = json.load(fp)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"
\n",
" \n",
" \n",
" | \n",
" hetnet | \n",
" compound_id | \n",
" disease_id | \n",
" metapath | \n",
" PC | \n",
" w | \n",
" DWPC | \n",
" seconds | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" rephetio-v2.0 | \n",
" DB00014 | \n",
" DOID:0050741 | \n",
" CpDpCpD | \n",
" 0 | \n",
" 0.4 | \n",
" 0.0 | \n",
" 0.7353 | \n",
"
\n",
" \n",
" 1 | \n",
" rephetio-v2.0 | \n",
" DB00014 | \n",
" DOID:10283 | \n",
" CpDpCpD | \n",
" 0 | \n",
" 0.4 | \n",
" 0.0 | \n",
" 0.7317 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" hetnet compound_id disease_id metapath PC w DWPC seconds\n",
"0 rephetio-v2.0 DB00014 DOID:0050741 CpDpCpD 0 0.4 0.0 0.7353\n",
"1 rephetio-v2.0 DB00014 DOID:10283 CpDpCpD 0 0.4 0.0 0.7317"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dwpc_df = pandas.read_table('../all-features/data/dwpc.tsv.bz2')\n",
"dwpc_df.head(2)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"27308958"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Number of queries\n",
"len(dwpc_df)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"1206"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"time_df = dwpc_df.groupby('metapath').seconds.mean().reset_index()\n",
"len(time_df)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"cols = ['sequential_complexity', 'optimal_join_complexity', 'midpoint_join_complexity']\n",
"\n",
"rows = [[\n",
" item['abbreviation'], \n",
" item['join_complexities'][item['midpoint_index']], \n",
" item['join_complexities'][item['optimal_join_index']],\n",
" item['join_complexities'][-1],\n",
" item['join_complexities'][0],\n",
" ] for item in metapaths]\n",
"complexity_df = pandas.DataFrame(rows, columns=\n",
" ['metapath', 'midpoint_complexity', 'optimal_complexity', 'forward_complexity', 'backward_complexity'])\n",
"complexity_df = time_df.merge(complexity_df)\n",
"complexity_df['log10_seconds_per_query'] = numpy.log10(complexity_df['seconds'])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\n",
" \n",
" \n",
" | \n",
" metapath | \n",
" seconds | \n",
" midpoint_complexity | \n",
" optimal_complexity | \n",
" forward_complexity | \n",
" backward_complexity | \n",
" log10_seconds_per_query | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" CbG<rG<rGaD | \n",
" 0.035545 | \n",
" 3.10150 | \n",
" 2.859092 | \n",
" 2.859092 | \n",
" 3.913263 | \n",
" -1.449222 | \n",
"
\n",
" \n",
" 1 | \n",
" CbG<rG<rGdD | \n",
" 0.023686 | \n",
" 2.90328 | \n",
" 2.640056 | \n",
" 2.640056 | \n",
" 3.694227 | \n",
" -1.625503 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" metapath seconds midpoint_complexity optimal_complexity \\\n",
"0 CbG\n",
"\n",
"\n",
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"matplotlib.pyplot.figure(figsize=(10, 7))\n",
"ax = seaborn.regplot('forward_complexity', 'log10_seconds_per_query', data=complexity_df,\n",
" lowess=True, scatter_kws={'alpha': 0.5}, line_kws={'color': 'black'}, ci=False)\n",
"points = ax.collections[0]\n",
"labels = complexity_df.metapath.tolist()\n",
"tooltip = mpld3.plugins.PointLabelTooltip(points, labels)\n",
"mpld3.plugins.connect(ax.figure, tooltip)\n",
"mpld3.display()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## optimal join complexity"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"matplotlib.pyplot.figure(figsize=(10, 7))\n",
"ax = seaborn.regplot('optimal_complexity', 'log10_seconds_per_query', data=complexity_df,\n",
" lowess=True, scatter_kws={'alpha': 0.5}, line_kws={'color': 'black'}, ci=False)\n",
"points = ax.collections[0]\n",
"labels = complexity_df.metapath.tolist()\n",
"tooltip = mpld3.plugins.PointLabelTooltip(points, labels)\n",
"mpld3.plugins.connect(ax.figure, tooltip)\n",
"mpld3.display()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## midpoint_join_complexity"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"matplotlib.pyplot.figure(figsize=(10, 7))\n",
"ax = seaborn.regplot('midpoint_complexity', 'log10_seconds_per_query', data=complexity_df,\n",
" lowess=True, scatter_kws={'alpha': 0.5}, line_kws={'color': 'black'}, ci=False)\n",
"points = ax.collections[0]\n",
"labels = complexity_df.metapath.tolist()\n",
"tooltip = mpld3.plugins.PointLabelTooltip(points, labels)\n",
"mpld3.plugins.connect(ax.figure, tooltip)\n",
"mpld3.display()"
]
}
],
"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.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}