{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "753d084e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.insert(0, '../Results')\n",
    "sys.path.insert(0, '../../src')\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import pickle\n",
    "import os\n",
    "from visualization_utils import perc, SetPlotRC, ApplyFont"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "43109ad5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# if not os.path.exists(\"Figures\"):\n",
    "#     os.mkdir(\"Figures\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aeb49514",
   "metadata": {},
   "source": [
    "# 5 dimensional Polytope with 40 dB Mixture SNR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "05cc7f4a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "250\n"
     ]
    },
    {
     "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>Model</th>\n",
       "      <th>SINR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>CorInfoMax</td>\n",
       "      <td>27.063502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>CorInfoMax2</td>\n",
       "      <td>30.939944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>CorInfoMaxCanonical</td>\n",
       "      <td>26.197065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>LDMI</td>\n",
       "      <td>38.504896</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>PMF</td>\n",
       "      <td>31.483125</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Model       SINR\n",
       "0           CorInfoMax  27.063502\n",
       "1          CorInfoMax2  30.939944\n",
       "2  CorInfoMaxCanonical  26.197065\n",
       "3                 LDMI  38.504896\n",
       "4                  PMF  31.483125"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_general_poly5dim_results = pd.read_pickle(r\"../Results/simulation_results_general_polytope_5dimV2.pkl\").iloc[:250]\n",
    "print(df_general_poly5dim_results.shape[0])\n",
    "results = df_general_poly5dim_results[['Model', 'SINR']].groupby(['Model']).agg({ 'SINR':'mean'}).rename(columns={'SINR':'SINR'}).reset_index()\n",
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "984ca8ef",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "findfont: Font family ['Times New Roman'] not found. Falling back to DejaVu Sans.\n",
      "findfont: Font family ['Times New Roman'] not found. Falling back to DejaVu Sans.\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 48796 characters]\n",
      "text/plain": [
       "<Figure size 800x480 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data = np.stack(df_general_poly5dim_results.loc[ (df_general_poly5dim_results['Model'] == \"CorInfoMax2\")]['SINRlist'].apply(lambda row: np.array(row)).to_numpy(), axis = 0)\n",
    "\n",
    "# compute the medians and 25/75 percentiles\n",
    "med, perc_25, perc_75, std_data = perc(data)\n",
    "\n",
    "x = np.arange(0, med.shape[0])\n",
    "fh2=plt.figure(figsize=(10, 6), dpi=80)\n",
    "plt.plot(x, med, linewidth=4, color='#006BB2')\n",
    "plt.fill_between(x, med + std_data, med - std_data, alpha=0.25, linewidth=0, color='#006BB2')\n",
    "\n",
    "\n",
    "gh=plt.grid(linewidth=2)\n",
    "plt.xticks(fontsize=20)\n",
    "plt.yticks(fontsize=20)\n",
    "plt.ylabel('SINR (dB)',fontsize=25)\n",
    "plt.xlabel(r\"Number of Iterations / 25000\",fontsize=25)\n",
    "plt.title(\"Online CorInfoMax Special Polytope SINR Convergence \")\n",
    "plt.axis([0.0,20.0,-0,35.5])\n",
    "ApplyFont(plt.gca())\n",
    "# plt.savefig('Figures/CorInfoMax_5dimGeneralPolytope_Convergence_40dBSNR.pdf', format='pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a0e41e9b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 53600 characters]\n",
      "text/plain": [
       "<Figure size 800x480 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data = np.stack(df_general_poly5dim_results.loc[ (df_general_poly5dim_results['Model'] == \"CorInfoMaxCanonical\")]['SINRlist'].apply(lambda row: np.array(row)).to_numpy(), axis = 0)\n",
    "\n",
    "# compute the medians and 25/75 percentiles\n",
    "med, perc_25, perc_75, std_data = perc(data)\n",
    "\n",
    "x = np.arange(0, med.shape[0])\n",
    "fh2=plt.figure(figsize=(10, 6), dpi=80)\n",
    "plt.plot(x, med, linewidth=4, color='#006BB2')\n",
    "plt.fill_between(x, med + std_data, med - std_data, alpha=0.25, linewidth=0, color='#006BB2')\n",
    "\n",
    "\n",
    "gh=plt.grid(linewidth=2)\n",
    "plt.xticks(fontsize=20)\n",
    "plt.yticks(fontsize=20)\n",
    "plt.ylabel('SINR (dB)',fontsize=25)\n",
    "plt.xlabel(r\"Number of Iterations / 25000\",fontsize=25)\n",
    "plt.title(\"Online CorInfoMax-Canonical Special Polytope \\nSINR Convergence \")\n",
    "plt.axis([0.0,20.0,-0,35.5])\n",
    "ApplyFont(plt.gca())\n",
    "# plt.savefig('Figures/CorInfoMaxCanonical_5dimGeneralPolytope_Convergence_40dBSNR.pdf', format='pdf')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1f815fee",
   "metadata": {},
   "source": [
    "# 5 dimensional Polytope with 30 dB Mixture SNR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6912e147",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "250\n"
     ]
    },
    {
     "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>Model</th>\n",
       "      <th>SINR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>CorInfoMax</td>\n",
       "      <td>24.821231</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>CorInfoMax2</td>\n",
       "      <td>26.552054</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>CorInfoMaxCanonical</td>\n",
       "      <td>24.850103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>LDMI</td>\n",
       "      <td>30.287287</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>PMF</td>\n",
       "      <td>27.683568</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Model       SINR\n",
       "0           CorInfoMax  24.821231\n",
       "1          CorInfoMax2  26.552054\n",
       "2  CorInfoMaxCanonical  24.850103\n",
       "3                 LDMI  30.287287\n",
       "4                  PMF  27.683568"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_general_poly5dim_results = pd.read_pickle(r\"../Results/simulation_results_general_polytope_5dimV3.pkl\").iloc[:250]\n",
    "print(df_general_poly5dim_results.shape[0])\n",
    "results = df_general_poly5dim_results[['Model', 'SINR']].groupby(['Model']).agg({ 'SINR':'mean'}).rename(columns={'SINR':'SINR'}).reset_index()\n",
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "5af92c74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 46972 characters]\n",
      "text/plain": [
       "<Figure size 800x480 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data = np.stack(df_general_poly5dim_results.loc[ (df_general_poly5dim_results['Model'] == \"CorInfoMax2\")]['SINRlist'].apply(lambda row: np.array(row)).to_numpy(), axis = 0)\n",
    "\n",
    "# compute the medians and 25/75 percentiles\n",
    "med, perc_25, perc_75, std_data = perc(data)\n",
    "\n",
    "x = np.arange(0, med.shape[0])\n",
    "fh2=plt.figure(figsize=(10, 6), dpi=80)\n",
    "plt.plot(x, med, linewidth=4, color='#006BB2')\n",
    "plt.fill_between(x, med + std_data, med - std_data, alpha=0.25, linewidth=0, color='#006BB2')\n",
    "\n",
    "\n",
    "gh=plt.grid(linewidth=2)\n",
    "plt.xticks(fontsize=20)\n",
    "plt.yticks(fontsize=20)\n",
    "plt.ylabel('SINR (dB)',fontsize=25)\n",
    "plt.xlabel(r\"Number of Iterations / 25000\",fontsize=25)\n",
    "plt.title(\"Online CorInfoMax Special Polytope SINR Convergence \")\n",
    "plt.axis([0.0,20.0,-0,30.5])\n",
    "ApplyFont(plt.gca())\n",
    "# plt.savefig('Figures/CorInfoMax_5dimGeneralPolytope_Convergence_30dBSNR.pdf', format='pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5de3c0d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 47088 characters]\n",
      "text/plain": [
       "<Figure size 800x480 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data = np.stack(df_general_poly5dim_results.loc[ (df_general_poly5dim_results['Model'] == \"CorInfoMaxCanonical\")]['SINRlist'].apply(lambda row: np.array(row)).to_numpy(), axis = 0)\n",
    "\n",
    "# compute the medians and 25/75 percentiles\n",
    "med, perc_25, perc_75, std_data = perc(data)\n",
    "\n",
    "x = np.arange(0, med.shape[0])\n",
    "fh2=plt.figure(figsize=(10, 6), dpi=80)\n",
    "plt.plot(x, med, linewidth=4, color='#006BB2')\n",
    "plt.fill_between(x, med + std_data, med - std_data, alpha=0.25, linewidth=0, color='#006BB2')\n",
    "\n",
    "\n",
    "gh=plt.grid(linewidth=2)\n",
    "plt.xticks(fontsize=20)\n",
    "plt.yticks(fontsize=20)\n",
    "plt.ylabel('SINR (dB)',fontsize=25)\n",
    "plt.xlabel(r\"Number of Iterations / 25000\",fontsize=25)\n",
    "plt.title(\"Online CorInfoMax-Canonical Special Polytope \\nSINR Convergence \")\n",
    "plt.axis([0.0,20.0,-0,30.5])\n",
    "ApplyFont(plt.gca())\n",
    "# plt.savefig('Figures/CorInfoMaxCanonical_5dimGeneralPolytope_Convergence_30dBSNR.pdf', format='pdf')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
