{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import seaborn as sns\n",
    "from matplotlib import pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 720x720 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# pd.set_option(\"plotting.backend\", \"hvplot\")\n",
    "# pd.options.mode.chained_assignment = None\n",
    "plt.figure(figsize = (10, 10))\n",
    "\n",
    "sns.set(style=\"whitegrid\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.97101247, 1.97101247, 1.97101247, ..., 3.82874012, 3.22839284,\n",
       "        3.22839284],\n",
       "       [1.81053269, 1.81053269, 1.81053269, ..., 3.68756509, 3.08106327,\n",
       "        3.08106327],\n",
       "       [1.96924293, 1.96924293, 1.96924293, ..., 3.81185722, 3.21250081,\n",
       "        3.21250081],\n",
       "       ...,\n",
       "       [2.0985353 , 2.0985353 , 2.0985353 , ..., 4.03281069, 3.44671941,\n",
       "        3.44671941],\n",
       "       [2.15873027, 2.15873027, 2.15873027, ..., 4.12976789, 3.61444998,\n",
       "        3.61444998],\n",
       "       [2.01221871, 2.01221871, 2.01221871, ..., 3.95901155, 3.37213564,\n",
       "        3.37213564]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "without_similarities = pd.read_csv('results/without_similarity_matrix.csv')\n",
    "without_similarities.drop(columns=['Unnamed: 0'], inplace=True)\n",
    "without_similarities = without_similarities.values\n",
    "without_similarities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6.12840986, 6.12840986, 6.12840986, ..., 6.03129101, 4.83788919,\n",
       "        4.83788919],\n",
       "       [6.2183466 , 6.2183466 , 6.2183466 , ..., 6.07799053, 4.91855526,\n",
       "        4.91855526],\n",
       "       [6.12499952, 6.12499952, 6.12499952, ..., 6.01277018, 4.83294678,\n",
       "        4.83294678],\n",
       "       ...,\n",
       "       [6.0795517 , 6.0795517 , 6.0795517 , ..., 5.98538017, 4.78033018,\n",
       "        4.78033018],\n",
       "       [6.29605341, 6.29605341, 6.29605341, ..., 6.11987877, 4.99074888,\n",
       "        4.99074888],\n",
       "       [6.32037067, 6.32037067, 6.32037067, ..., 6.1486578 , 5.01822042,\n",
       "        5.01822042]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with_similarities = pd.read_csv('results/batch 0.csv')\n",
    "with_similarities.drop(columns=['Unnamed: 0'], inplace=True)\n",
    "with_similarities = with_similarities.values\n",
    "with_similarities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# similarities = pd.read_csv('results/batch 0.csv')\n",
    "# similarities.drop(columns=['Unnamed: 0'], inplace=True)\n",
    "# similarities = similarities.values\n",
    "# similarities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "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>Unnamed: 0</th>\n",
       "      <th>id</th>\n",
       "      <th>text</th>\n",
       "      <th>image</th>\n",
       "      <th>label</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12738</td>\n",
       "      <td>665333038944002048</td>\n",
       "      <td>sadness # bataclan sold out musicians public i...</td>\n",
       "      <td>attacks_paris_1.jpg</td>\n",
       "      <td>fake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>12739</td>\n",
       "      <td>665324167785410560</td>\n",
       "      <td>rt user # last hour spectacular photograph tak...</td>\n",
       "      <td>attacks_paris_1.jpg</td>\n",
       "      <td>fake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>12740</td>\n",
       "      <td>665333370205765632</td>\n",
       "      <td>rt user # bataclan tonight before the url attacks</td>\n",
       "      <td>attacks_paris_1.jpg</td>\n",
       "      <td>fake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12741</td>\n",
       "      <td>665326188735295489</td>\n",
       "      <td>rt user man has to establish an end for the wa...</td>\n",
       "      <td>attacks_paris_1.jpg</td>\n",
       "      <td>fake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>12742</td>\n",
       "      <td>665389341141659648</td>\n",
       "      <td># paris url</td>\n",
       "      <td>attacks_paris_1.jpg</td>\n",
       "      <td>fake</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Unnamed: 0                  id  \\\n",
       "0       12738  665333038944002048   \n",
       "1       12739  665324167785410560   \n",
       "2       12740  665333370205765632   \n",
       "3       12741  665326188735295489   \n",
       "4       12742  665389341141659648   \n",
       "\n",
       "                                                text                image  \\\n",
       "0  sadness # bataclan sold out musicians public i...  attacks_paris_1.jpg   \n",
       "1  rt user # last hour spectacular photograph tak...  attacks_paris_1.jpg   \n",
       "2  rt user # bataclan tonight before the url attacks  attacks_paris_1.jpg   \n",
       "3  rt user man has to establish an end for the wa...  attacks_paris_1.jpg   \n",
       "4                                        # paris url  attacks_paris_1.jpg   \n",
       "\n",
       "  label  \n",
       "0  fake  \n",
       "1  fake  \n",
       "2  fake  \n",
       "3  fake  \n",
       "4  fake  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train = pd.read_csv('data/twitter_train_translated.csv')\n",
    "test = pd.read_csv('data/twitter_test_translated.csv')\n",
    "test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = test"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Without similarity calculation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(9.631244659423828, -10.282122611999512, 0.22026454079786126)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.max(without_similarities), np.min(without_similarities), np.mean(without_similarities)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "without_normalized = (without_similarities - np.min(without_similarities)) / (np.max(without_similarities) - np.min(without_similarities))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1.0, 0.0, 0.5274038794970056)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.max(without_normalized), np.min(without_normalized), np.mean(without_normalized)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "without_diameter = np.diagonal(without_normalized)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5272736055433571"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "without_diameter.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.40070086539821037"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "without_diameter[data['label']=='real'].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6303897461386694"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "without_diameter[data['label']=='fake'].mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### With similarity calculation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(7.957752704620361, 4.0716896057128915, 5.324145657606938)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.max(with_similarities), np.min(with_similarities), np.mean(with_similarities)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "with_normalized = (with_similarities - np.min(with_similarities)) / (np.max(with_similarities) - np.min(with_similarities))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1.0, 0.0, 0.32229431690035176)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.max(with_normalized), np.min(with_normalized), np.mean(with_normalized)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "with_diameter = np.diagonal(with_normalized)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3254251913685233"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with_diameter.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3067557027146469"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with_diameter[data['label']=='real'].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3406348298314979"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with_diameter[data['label']=='fake'].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "# data = pd.concat((train, test))\n",
    "data = test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 34600 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "data['event'] = data.image.apply(lambda x: \" \".join(x.split('.')[0].split('_')[:-1]).replace('fake', '').replace('real', '').strip())\n",
    "data.event.value_counts().plot.bar()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 44616 characters]\n",
      "text/plain": [
       "<Figure size 720x720 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize = (10, 10))\n",
    "sns.countplot(x='event', data=data, order=data.event.value_counts().index)\n",
    "plt.xticks(rotation=90)\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 1440x1440 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cross_tab = pd.crosstab(index=data['event'], columns=data['label'])\n",
    "# cross_tab['sum'] = cross_tab.apply(lambda x: x.fake+x.real, axis=1)\n",
    "# cross_tab['fake'] = cross_tab.apply(lambda x: x.fake/x['sum'], axis=1)\n",
    "# cross_tab['real'] = cross_tab.apply(lambda x: x.real/x['sum'], axis=1)\n",
    "\n",
    "# cross_tab['fake'] = cross_tab.apply(lambda x: int(x.fake), axis=1)\n",
    "# cross_tab['real'] = cross_tab.apply(lambda x: int(x.real), axis=1)\n",
    "cross_tab = cross_tab[['fake', 'real']]\n",
    "plt.figure(figsize=(20, 20))\n",
    "sns.set(rc={'figure.figsize':(11.7,8.27)})\n",
    "sns.set(font_scale=2)\n",
    "# heatmap = sns.heatmap(cross_tab, annot=True)\n",
    "# # heatmap.set_title('Correlation Heatmap', fontdict={'fontsize':12}, pad=12)\n",
    "# plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 98708 characters]\n",
      "text/plain": [
       "<Figure size 842.4x595.44 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "c = cross_tab.plot(kind='bar', stacked=True)\n",
    "c.set(xlabel=None)\n",
    "c.set(ylabel=None)\n",
    "c.legend_.set_title(None)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['attacks paris', 'black lion', 'bowie david',\n",
       "       'brussels explosions', 'burst kfc', 'bush book',\n",
       "       'five headed snake', 'fuji lenticular', 'gandhi dancing',\n",
       "       'hubble telescope', 'john guevara', 'mc donalds fee',\n",
       "       'nazi submarine', 'north korea', 'not afraid',\n",
       "       'pakistan explosion', 'protest', 'refugees', 'rio moon',\n",
       "       'soldier stealing', 'syrian children', 'ukrainian nazi',\n",
       "       'woman 14 children'], dtype=object)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "events = data.event.unique()\n",
    "events"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# names = ['Only image', 'Only text', 'Text & Image without Similarity', 'Text & Image with Similarity']\n",
    "# accuracies = [0.68, 0.81, 0.869, 0.879]\n",
    "# f1s = [0.68, 0.81, 0.869, 0.879]\n",
    "# aus = [0.72, 0.83, 0.898, 0.938]\n",
    "\n",
    "# twitter = pd.DataFrame({'name':names, 'accuracy': accuracies, 'f1-score micro':f1s, 'AUC':aus})\n",
    "# twitter = pd.melt(twitter, id_vars=\"name\", var_name=\"metric\", value_name=\"number\")\n",
    "# twitter\n",
    "\n",
    "# # g = sns.barplot(x, hue='name', data=twitter)\n",
    "# # sns.set(rc={'figure.figsize':(11,8)})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# p = sns.barplot(x=\"metric\", y=\"number\", hue=\"name\", ci=None, data=twitter)\n",
    "# p.set(xlabel=None)\n",
    "# p.set(ylabel=None)\n",
    "# p.legend_.set_title(None)\n",
    "# sns.set_palette(\"tab20\")\n",
    "# plt.legend(loc='lower right')\n",
    "# plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(23, 23)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "without_means = list()\n",
    "\n",
    "for event in events:\n",
    "    d1 = data.event == event\n",
    "    m = list()\n",
    "    for event_ in events:\n",
    "        d2 = data.event == event_\n",
    "        m.append(np.mean(without_normalized[d1,:][:,d2]))\n",
    "    without_means.append(np.array(m))\n",
    "without_means = np.array(without_means)\n",
    "without_means.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 939240 characters]\n",
      "text/plain": [
       "<Figure size 1440x1440 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "plt.figure(figsize=(20, 20))\n",
    "heatmap = sns.heatmap(without_means, annot=True, xticklabels=events, yticklabels=events)\n",
    "# heatmap.set_title('Correlation Heatmap', fontdict={'fontsize':12}, pad=12)\n",
    "sns.set(font_scale=1.25)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6070646237133083"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "without_means.diagonal().mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.02667994976560363"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "without_means.diagonal().var()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6077117139290742"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "without_means.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.02755410530676937"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "without_means.var()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "253.0"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n = (without_means.shape[0]*without_means.shape[1] - without_means.diagonal().shape[0])/2\n",
    "n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "def distance_calculator(m):\n",
    "    distance = 0\n",
    "    length = 0\n",
    "    for i, row in enumerate(m):\n",
    "#         print(row)\n",
    "        for j, column in enumerate(m[i+1:]):\n",
    "#             print(column)\n",
    "            distance += column - row if column - row > 0 else row - column\n",
    "            length += 1\n",
    "    return distance / length\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.18582239973717557"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distance_calculator(without_means[np.triu_indices(23, k = 1)])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### With similarity"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(23, 23)"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with_means = list()\n",
    "\n",
    "for event in events:\n",
    "    d1 = data.event == event\n",
    "    m = list()\n",
    "    for event_ in events:\n",
    "        d2 = data.event == event_\n",
    "        m.append(np.mean(with_normalized[d1,:][:,d2]))\n",
    "    with_means.append(np.array(m))\n",
    "with_means = np.array(with_means)\n",
    "with_means.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 548944 characters]\n",
      "text/plain": [
       "<Figure size 1440x1440 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "plt.figure(figsize=(20, 20))\n",
    "heatmap = sns.heatmap(with_means, annot=True, xticklabels=events, yticklabels=events)\n",
    "# heatmap.set_title('Correlation Heatmap', fontdict={'fontsize':12}, pad=12)\n",
    "sns.set(font_scale=1.25)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3505192691173016"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with_means.diagonal().mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.026153930777233107"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with_means.diagonal().var()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3463002924636721"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with_means.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.02562625887231725"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with_means.var()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.20782937582052868"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distance_calculator(with_means[np.triu_indices(23, k = 1)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "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.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
