{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "67afdff9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "325a01fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "datalist = [\n",
    "    22, 54, 1063, 1067, 12, 18, 23, 59, 188, 307, 1043, 1459, 1475, 1489, 1492, 1497, 1503, 4153, 40499, 44125,\n",
    "    44131, 45062, 44157, 1462, 44160, 29, 37, 53, 49, 1504, 1494, 41143, 44126, 40981, 41168, 44091, 44158, 44123, 44090,\n",
    "    40922, 44161, 45714]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "34db94b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv(\"/home/SemiTab/motivation/correlation.csv\", index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "4f72b376",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Test', 'masking', 'shuffling', 'noisemasking', 'rq',\n",
       "       'binshuffling-2', 'binsampling-2', 'binshuffling-3',\n",
       "       'binsampling-3', 'binshuffling-4', 'binsampling-4',\n",
       "       'binshuffling-5', 'binsampling-5', 'binshuffling-6',\n",
       "       'binsampling-6', 'binshuffling-7', 'binsampling-7',\n",
       "       'binshuffling-8', 'binsampling-8', 'binshuffling-9',\n",
       "       'binsampling-9', 'binshuffling-10', 'binsampling-10', 'scarf',\n",
       "       'cutmix'], dtype=object)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"transform\"].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "157185f5",
   "metadata": {},
   "outputs": [],
   "source": [
    "p = data.groupby(\"transform\").mean(\"correlation\").reset_index()\n",
    "p = p[p[\"transform\"].isin([\n",
    "    \"Test\", \"masking\", \"scarf\", \"shuffling\", \"noisemasking\", \"rq\", \"cutmix\",\n",
    "    \"binshuffling-4\", \"binsampling-4\"])].reset_index(drop=True)\n",
    "p = p.set_index(\"transform\").loc[[\n",
    "    \"Test\", \"masking\", \"scarf\", \"shuffling\", \"noisemasking\", \"rq\", \"cutmix\",\n",
    "    \"binshuffling-4\", \"binsampling-4\"]].reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "2320b150",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 15944 characters]\n",
      "text/plain": [
       "<Figure size 360x216 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(5, 3))\n",
    "plt.gca().set_axisbelow(True)\n",
    "plt.grid(axis='y')\n",
    "plt.bar(p[\"transform\"], p[\"correlation\"])\n",
    "plt.yscale('log')\n",
    "plt.xticks(ticks=[0, 1, 2, 3, 4, 5, 6, 7, 8], \n",
    "           labels=[\n",
    "               'No aug.(Test)', 'Masking', 'Sampling', 'Shuffling',\n",
    "               'Noise', 'RQ', 'CutMix', 'Ours(Shuffling)', 'Ours(Sampling)'], \n",
    "           rotation=90, fontsize=12)\n",
    "plt.ylabel(\"Inter-feature correlation\\nchanges (log scale)\", fontsize=11.5)\n",
    "plt.savefig(\"figs/correlation.png\", dpi=300, bbox_inches=\"tight\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "de88becf",
   "metadata": {},
   "outputs": [],
   "source": [
    "p = data.groupby(\"transform\").mean(\"correlation\").reset_index()\n",
    "p = p[p[\"transform\"].str.startswith(\"bin\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "efb2969c",
   "metadata": {},
   "outputs": [],
   "source": [
    "q1, q2 = [], []\n",
    "for nb in range(2, 11):\n",
    "    q1.append(p[p[\"transform\"] == f'binsampling-{nb}'][\"correlation\"].values)\n",
    "    q2.append(p[p[\"transform\"] == f'binshuffling-{nb}'][\"correlation\"].values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "6535f9a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 19908 characters]\n",
      "text/plain": [
       "<Figure size 288x216 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.figure(figsize=(4, 3))\n",
    "plt.gca().set_axisbelow(True)\n",
    "plt.grid()\n",
    "plt.plot(range(2, 11), q2, marker=\"o\", label=\"Range-limited shuffling\")\n",
    "plt.plot(range(2, 11), q1, marker=\"o\", label=\"Range-limited sampling\")\n",
    "plt.legend()\n",
    "plt.xlabel(\"Number of Ranges\")\n",
    "plt.ylabel(\"Inter-feature correlation changes\")\n",
    "plt.savefig(\"figs/numbins_corr.png\", dpi=300, bbox_inches=\"tight\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f5cc579",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
