{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import statsmodels.api as sm\n",
    "import statsmodels.formula.api as smf\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv(\"r2vals.csv\").sort_values(\"r2 \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>r2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>133.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.677843</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.229390</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.135144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.474227</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.734562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.878335</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>0.968964</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              r2 \n",
       "count  133.000000\n",
       "mean     0.677843\n",
       "std      0.229390\n",
       "min      0.135144\n",
       "25%      0.474227\n",
       "50%      0.734562\n",
       "75%      0.878335\n",
       "max      0.968964"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv(\"new_repr_no_outlier.csv\")\n",
    "data[\"SQRSIZE\"] = data[\"SIZE\"].apply(np.sqrt)\n",
    "data[\"LNSIZE\"] = data[\"SIZE\"].apply(np.log)\n",
    "data[\"LOG2SIZE\"] = data[\"SIZE\"].apply(np.log2)\n",
    "maps = data[\"MAP\"].unique()\n",
    "tests = data[\"TEST\"].unique()\n",
    "groups = data.groupby([\"MAP\", \"TEST\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {},
   "outputs": [],
   "source": [
    "size = pd.Series(range(1, 50000000, 100000))\n",
    "predictors = pd.DataFrame([size, np.sqrt(size), np.log(size), np.log2(size)]).T\n",
    "predictors.columns = [\"SIZE\",\"SQRSIZE\",\"LNSIZE\",\"LOG2SIZE\" ]\n",
    "regression_results = pd.DataFrame([[],[], [], []]).T\n",
    "rvals = []\n",
    "\n",
    "for i, group in groups:\n",
    "    results = smf.ols('TIME~SIZE+SQRSIZE+LNSIZE+LOG2SIZE', data=group).fit()\n",
    "    pred = results.predict(predictors)\n",
    "    rvals.append(results.rsquared)\n",
    "    regression_results = regression_results.append([[i[1], i[0], size[a], pred[a]] for a in range(len(test))])  \n",
    "regression_results.rename(columns={0: \"test\", 1: \"map\", 2:\"size\", 3: \"time\"})\n",
    "regression_results.columns = [\"test\", \"map\", \"size\", \"time\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [],
   "source": [
    "regroup = regression_results.groupby([\"test\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 218624 characters]\n",
      "text/plain": [
       "<Figure size 1728x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams[\"figure.figsize\"] = (24,5)\n",
    "sns.set()\n",
    "sns.set(font_scale=1.75)\n",
    "ticks = [50000, 100000, 150000, 200000, 250000, 300000, 350000, 400000, 500000,\n",
    "600000, 700000, 800000, 900000, 1000000,\n",
    "2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000,\n",
    "15000000, 20000000, 25000000, 30000000, 35000000, 40000000, 45000000, 50000000]\n",
    "ticklabels = ['50 K', '100 K',\n",
    " '150 K', '200 K', '250 K', '300 K',\n",
    " '350 K', '400 K', '0.5 M', '0.6 M',\n",
    " '0.7 M', '0.8 M', '0.9 M', '1 M',\n",
    " '2 M', '3 M', '4 M', '5 M',\n",
    " '6 M', '7 M', '8 M', '9 M',\n",
    " '10 M', '15 M', '20 M', '25 M',\n",
    " '30 M', '35 M', '40 M', '45 M', '50 M']\n",
    "labels = {\n",
    "    'int_delete' : [\"mean int deletion time\", \"deletion time (ns)\"],\n",
    "    'int_insert' : [\"mean int insertion time\", \"insertion time(ns)\"],\n",
    "    'int_nosucc_lookup' : [\"mean int unsucessful lookup time\", \"unsucessful lookup time (ns)\"],\n",
    "    'int_succ_lookup' : [\"mean int succesful lookup time\", \"succesful lookup time (ns)\"],\n",
    "    'string_delete' : [\"mean string deletion time\", \"deletion time (ns)\"],\n",
    "    'string_insert' : [\"mean string insertion time\", \"insertion time(ns)\"], \n",
    "    'string_nosucc_lookup' : [\"mean string unsucessful lookup time\", \"unsucessful lookup time (ns)\"],\n",
    "    'string_succ_lookup' : [\"mean string succesful lookup time\", \"succesful lookup time (ns)\"]\n",
    "}\n",
    "\n",
    "for i, group in regroup:\n",
    "    plot = sns.lineplot(x=\"size\", y=\"time\", hue=\"map\", data=group)\n",
    "    plt.xscale(\"log\")\n",
    "    plt.xticks(ticks, ticklabels)\n",
    "    plot.set_xticklabels(\n",
    "        plot.get_xticklabels(), \n",
    "        rotation=55, \n",
    "        horizontalalignment='center',\n",
    "        fontweight='light',\n",
    "        )\n",
    "    plt.ylabel(labels[i][1])\n",
    "    plt.legend()\n",
    "    plt.title(labels[i][0])\n",
    "    plt.show()\n",
    "    break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>test</th>\n",
       "      <th>map</th>\n",
       "      <th>size</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>int_delete</td>\n",
       "      <td>absl::flat_hash_map</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.516393</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>int_delete</td>\n",
       "      <td>absl::flat_hash_map</td>\n",
       "      <td>100001.0</td>\n",
       "      <td>11.352983</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>int_delete</td>\n",
       "      <td>absl::flat_hash_map</td>\n",
       "      <td>200001.0</td>\n",
       "      <td>12.227014</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>int_delete</td>\n",
       "      <td>absl::flat_hash_map</td>\n",
       "      <td>300001.0</td>\n",
       "      <td>12.806459</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>int_delete</td>\n",
       "      <td>absl::flat_hash_map</td>\n",
       "      <td>400001.0</td>\n",
       "      <td>13.254607</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>495</th>\n",
       "      <td>string_succ_lookup</td>\n",
       "      <td>tsl::sparse_map</td>\n",
       "      <td>49500001.0</td>\n",
       "      <td>267.156427</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>496</th>\n",
       "      <td>string_succ_lookup</td>\n",
       "      <td>tsl::sparse_map</td>\n",
       "      <td>49600001.0</td>\n",
       "      <td>267.172009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>497</th>\n",
       "      <td>string_succ_lookup</td>\n",
       "      <td>tsl::sparse_map</td>\n",
       "      <td>49700001.0</td>\n",
       "      <td>267.187371</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>498</th>\n",
       "      <td>string_succ_lookup</td>\n",
       "      <td>tsl::sparse_map</td>\n",
       "      <td>49800001.0</td>\n",
       "      <td>267.202512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499</th>\n",
       "      <td>string_succ_lookup</td>\n",
       "      <td>tsl::sparse_map</td>\n",
       "      <td>49900001.0</td>\n",
       "      <td>267.217433</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>68000 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                   test                  map        size        time\n",
       "0            int_delete  absl::flat_hash_map         1.0    2.516393\n",
       "1            int_delete  absl::flat_hash_map    100001.0   11.352983\n",
       "2            int_delete  absl::flat_hash_map    200001.0   12.227014\n",
       "3            int_delete  absl::flat_hash_map    300001.0   12.806459\n",
       "4            int_delete  absl::flat_hash_map    400001.0   13.254607\n",
       "..                  ...                  ...         ...         ...\n",
       "495  string_succ_lookup      tsl::sparse_map  49500001.0  267.156427\n",
       "496  string_succ_lookup      tsl::sparse_map  49600001.0  267.172009\n",
       "497  string_succ_lookup      tsl::sparse_map  49700001.0  267.187371\n",
       "498  string_succ_lookup      tsl::sparse_map  49800001.0  267.202512\n",
       "499  string_succ_lookup      tsl::sparse_map  49900001.0  267.217433\n",
       "\n",
       "[68000 rows x 4 columns]"
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "regression_results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
