{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Plotting Figures for 16-bit vs 32-bit comparisons"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pickle\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# ===== MNIST MLP IID ===== \n",
    "datamodelset = \"MNIST_MLP_IID FP16 and FP32 Comparison\"\n",
    "filename1 = \"FL_mnist_mlp_468_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]_FP16\"\n",
    "filename2 = \"HFL2_mnist_mlp_100_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]_FP16\"\n",
    "filename3 = \"HFL4_mnist_mlp_100_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]_FP16\"\n",
    "filename4 = \"HFL4_mnist_mlp_30_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]_FP16\"\n",
    "\n",
    "filename5 = \"[1]FL_mnist_mlp_468_C[0.1]_iid[1]_E[1]_B[10]\"\n",
    "filename6 = \"[3]HFL2_mnist_mlp_100_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]\"\n",
    "filename7 = \"[5]HFL4_mnist_mlp_100_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]\"\n",
    "filename8 = \"[7]HFL4_mnist_mlp_30_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]\"\n",
    "\n",
    "with open(r\"../save/objects_fp16/\" + filename1 + \".pkl\", \"rb\") as input_file: data1 = pickle.load(input_file)\n",
    "with open(r\"../save/objects_fp16/\" + filename2 + \".pkl\", \"rb\") as input_file: data2 = pickle.load(input_file)\n",
    "with open(r\"../save/objects_fp16/\" + filename3 + \".pkl\", \"rb\") as input_file: data3 = pickle.load(input_file)\n",
    "with open(r\"../save/objects_fp16/\" + filename4 + \".pkl\", \"rb\") as input_file: data4 = pickle.load(input_file)    \n",
    "\n",
    "with open(r\"../save/objects/\" + filename5 + \".pkl\", \"rb\") as input_file: data5 = pickle.load(input_file)\n",
    "with open(r\"../save/objects/\" + filename6 + \".pkl\", \"rb\") as input_file: data6 = pickle.load(input_file)\n",
    "with open(r\"../save/objects/\" + filename7 + \".pkl\", \"rb\") as input_file: data7 = pickle.load(input_file)\n",
    "with open(r\"../save/objects/\" + filename8 + \".pkl\", \"rb\") as input_file: data8 = pickle.load(input_file)    \n",
    "\n",
    "trloss1 = data1[0]    \n",
    "trloss2 = data2[0]    \n",
    "trloss3 = data3[0]    \n",
    "trloss4 = data4[0]    \n",
    "\n",
    "trloss5 = data5[0]    \n",
    "trloss6 = data6[0]    \n",
    "trloss7 = data7[0]    \n",
    "trloss8 = data8[0] \n",
    "\n",
    "tracc1 = data1[1]\n",
    "tracc2 = data2[1]\n",
    "tracc3 = data3[1]\n",
    "tracc4 = data4[1]\n",
    "\n",
    "tracc5 = data5[1]\n",
    "tracc6 = data6[1]\n",
    "tracc7 = data7[1]\n",
    "tracc8 = data8[1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 28912 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 32952 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# PLOTTING \n",
    "\n",
    "# Plot Average Accuracy vs Communication rounds\n",
    "plt.figure()\n",
    "plt.title(datamodelset)\n",
    "\n",
    "plt.plot(range(len(tracc1)), tracc1, ':', label=\"FL-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc2)), tracc2, ':', label=\"HFL2-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc3)), tracc3, ':', label=\"HFL4-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc4)), tracc4, ':', label=\"HFL8-FP16\")\n",
    "\n",
    "plt.plot(range(len(tracc5)), tracc5, label=\"FL\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc6)), tracc6, label=\"HFL2\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc7)), tracc7, label=\"HFL4\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc8)), tracc8, label=\"HFL8\")\n",
    "plt.legend(loc=\"lower right\")\n",
    "\n",
    "plt.ylabel('Average Accuracy')\n",
    "plt.xlabel('Communication Rounds')\n",
    "plt.savefig('../save/' + datamodelset + '_acc_FP16_32.png')\n",
    "\n",
    "# Plot Loss curve\n",
    "plt.figure()\n",
    "plt.title(datamodelset)\n",
    "\n",
    "plt.plot(range(len(trloss1)), trloss1, ':', label=\"FP-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss2)), trloss2, ':', label=\"HFL2-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss3)), trloss3, ':', label=\"HFL4-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss4)), trloss4, ':', label=\"HFL8-FP16\")\n",
    "\n",
    "plt.plot(range(len(trloss5)), trloss5, label=\"FL\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss6)), trloss6, label=\"HFL2\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss7)), trloss7, label=\"HFL4\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss8)), trloss8, label=\"HFL8\")\n",
    "plt.legend(loc=\"upper right\")\n",
    "\n",
    "plt.ylabel('Training loss')\n",
    "plt.xlabel('Communication Rounds')\n",
    "plt.savefig('../save/' + datamodelset + '_loss_FP16_32.png')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# ===== MNIST MLP NON-IID ===== \n",
    "datamodelset = \"MNIST_MLP_NONIID FP16 and FP32 Comparison\"\n",
    "filename1 = \"FL_mnist_mlp_1196_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]_FP16\"\n",
    "filename2 = \"HFL2_mnist_mlp_100_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]_FP16\"\n",
    "filename3 = \"HFL4_mnist_mlp_150_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]_FP16\"\n",
    "# filename4 = \"\"\n",
    "\n",
    "filename5 = \"[2]FL_mnist_mlp_1196_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]\"\n",
    "filename6 = \"[4]HFL2_mnist_mlp_100_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]\"\n",
    "filename7 = \"[6]HFL4_mnist_mlp_150_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]\"\n",
    "# filename8 = \"\"\n",
    "\n",
    "with open(r\"../save/objects_fp16/\" + filename1 + \".pkl\", \"rb\") as input_file: data1 = pickle.load(input_file)\n",
    "with open(r\"../save/objects_fp16/\" + filename2 + \".pkl\", \"rb\") as input_file: data2 = pickle.load(input_file)\n",
    "with open(r\"../save/objects_fp16/\" + filename3 + \".pkl\", \"rb\") as input_file: data3 = pickle.load(input_file)\n",
    "#with open(r\"../save/objects_fp16/\" + filename4 + \".pkl\", \"rb\") as input_file: data4 = pickle.load(input_file)    \n",
    "\n",
    "with open(r\"../save/objects/\" + filename5 + \".pkl\", \"rb\") as input_file: data5 = pickle.load(input_file)\n",
    "with open(r\"../save/objects/\" + filename6 + \".pkl\", \"rb\") as input_file: data6 = pickle.load(input_file)\n",
    "with open(r\"../save/objects/\" + filename7 + \".pkl\", \"rb\") as input_file: data7 = pickle.load(input_file)\n",
    "#with open(r\"../save/objects/\" + filename8 + \".pkl\", \"rb\") as input_file: data8 = pickle.load(input_file)    \n",
    "\n",
    "trloss1 = data1[0]    \n",
    "trloss2 = data2[0]    \n",
    "trloss3 = data3[0]    \n",
    "#trloss4 = data4[0]    \n",
    "\n",
    "trloss5 = data5[0]    \n",
    "trloss6 = data6[0]    \n",
    "trloss7 = data7[0]    \n",
    "#trloss8 = data8[0] \n",
    "\n",
    "tracc1 = data1[1]\n",
    "tracc2 = data2[1]\n",
    "tracc3 = data3[1]\n",
    "#tracc4 = data4[1]\n",
    "\n",
    "tracc5 = data5[1]\n",
    "tracc6 = data6[1]\n",
    "tracc7 = data7[1]\n",
    "#tracc8 = data8[1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 45336 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 73660 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# PLOTTING \n",
    "\n",
    "# Plot Average Accuracy vs Communication rounds\n",
    "plt.figure()\n",
    "plt.title(datamodelset)\n",
    "\n",
    "plt.plot(range(len(tracc1)), tracc1, ':', label=\"FL-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc2)), tracc2, ':', label=\"HFL2-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc3)), tracc3, ':', label=\"HFL4-FP16\", linewidth=0.9)\n",
    "#plt.plot(range(len(tracc4)), tracc4, ':', label=\"HFL8-FP16\")\n",
    "\n",
    "plt.plot(range(len(tracc5)), tracc5, label=\"FL\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc6)), tracc6, label=\"HFL2\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc7)), tracc7, label=\"HFL4\", linewidth=0.9)\n",
    "#plt.plot(range(len(tracc8)), tracc8, label=\"HFL8\")\n",
    "plt.legend(loc=\"lower right\")\n",
    "\n",
    "plt.ylabel('Average Accuracy')\n",
    "plt.xlabel('Communication Rounds')\n",
    "plt.savefig('../save/' + datamodelset + '_acc_FP16_32.png')\n",
    "\n",
    "# Plot Loss curve\n",
    "plt.figure()\n",
    "plt.title(datamodelset)\n",
    "\n",
    "plt.plot(range(len(trloss1)), trloss1, ':', label=\"FP-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss2)), trloss2, ':', label=\"HFL2-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss3)), trloss3, ':', label=\"HFL4-FP16\", linewidth=0.9)\n",
    "#plt.plot(range(len(trloss4)), trloss4, ':', label=\"HFL8-FP16\")\n",
    "\n",
    "plt.plot(range(len(trloss5)), trloss5, label=\"FL\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss6)), trloss6, label=\"HFL2\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss7)), trloss7, label=\"HFL4\", linewidth=0.9)\n",
    "#plt.plot(range(len(trloss8)), trloss8, label=\"HFL8\")\n",
    "plt.legend(loc=\"upper right\")\n",
    "\n",
    "plt.ylabel('Training loss')\n",
    "plt.xlabel('Communication Rounds')\n",
    "plt.savefig('../save/' + datamodelset + '_loss_FP16_32.png')\n",
    "\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# ===== MNIST CNN IID ===== \n",
    "datamodelset = \"MNIST_CNN_IID FP16 and FP32 Comparison\"\n",
    "filename1 = \"FL_mnist_cnn_100_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]_FP16\"\n",
    "filename2 = \"HFL2_mnist_cnn_100_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]_FP16\"\n",
    "filename3 = \"HFL4_mnist_cnn_100_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]_FP16\"\n",
    "filename4 = \"HFL8_mnist_cnn_30_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]_FP16\"\n",
    "\n",
    "filename5 = \"[9]FL_mnist_cnn_100_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]\"\n",
    "filename6 = \"[11]HFL2_mnist_cnn_100_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]\"\n",
    "filename7 = \"[13]HFL4_mnist_cnn_100_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]\"\n",
    "filename8 = \"[15]HFL8_mnist_cnn_30_lr[0.01]_C[0.1]_iid[1]_E[1]_B[10]\"\n",
    "\n",
    "with open(r\"../save/objects_fp16/\" + filename1 + \".pkl\", \"rb\") as input_file: data1 = pickle.load(input_file)\n",
    "with open(r\"../save/objects_fp16/\" + filename2 + \".pkl\", \"rb\") as input_file: data2 = pickle.load(input_file)\n",
    "with open(r\"../save/objects_fp16/\" + filename3 + \".pkl\", \"rb\") as input_file: data3 = pickle.load(input_file)\n",
    "with open(r\"../save/objects_fp16/\" + filename4 + \".pkl\", \"rb\") as input_file: data4 = pickle.load(input_file)    \n",
    "\n",
    "with open(r\"../save/objects/\" + filename5 + \".pkl\", \"rb\") as input_file: data5 = pickle.load(input_file)\n",
    "with open(r\"../save/objects/\" + filename6 + \".pkl\", \"rb\") as input_file: data6 = pickle.load(input_file)\n",
    "with open(r\"../save/objects/\" + filename7 + \".pkl\", \"rb\") as input_file: data7 = pickle.load(input_file)\n",
    "with open(r\"../save/objects/\" + filename8 + \".pkl\", \"rb\") as input_file: data8 = pickle.load(input_file)    \n",
    "\n",
    "trloss1 = data1[0]    \n",
    "trloss2 = data2[0]    \n",
    "trloss3 = data3[0]    \n",
    "trloss4 = data4[0]    \n",
    "\n",
    "trloss5 = data5[0]    \n",
    "trloss6 = data6[0]    \n",
    "trloss7 = data7[0]    \n",
    "trloss8 = data8[0] \n",
    "\n",
    "tracc1 = data1[1]\n",
    "tracc2 = data2[1]\n",
    "tracc3 = data3[1]\n",
    "tracc4 = data4[1]\n",
    "\n",
    "tracc5 = data5[1]\n",
    "tracc6 = data6[1]\n",
    "tracc7 = data7[1]\n",
    "tracc8 = data8[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 27060 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 31660 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# PLOTTING \n",
    "\n",
    "# Plot Average Accuracy vs Communication rounds\n",
    "plt.figure()\n",
    "plt.title(datamodelset)\n",
    "\n",
    "plt.plot(range(len(tracc1)), tracc1, ':', label=\"FL-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc2)), tracc2, ':', label=\"HFL2-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc3)), tracc3, ':', label=\"HFL4-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc4)), tracc4, ':', label=\"HFL8-FP16\")\n",
    "\n",
    "plt.plot(range(len(tracc5)), tracc5, label=\"FL\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc6)), tracc6, label=\"HFL2\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc7)), tracc7, label=\"HFL4\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc8)), tracc8, label=\"HFL8\")\n",
    "plt.legend(loc=\"lower right\")\n",
    "\n",
    "plt.ylabel('Average Accuracy')\n",
    "plt.xlabel('Communication Rounds')\n",
    "plt.savefig('../save/' + datamodelset + '_acc_FP16_32.png')\n",
    "\n",
    "# Plot Loss curve\n",
    "plt.figure()\n",
    "plt.title(datamodelset)\n",
    "\n",
    "plt.plot(range(len(trloss1)), trloss1, ':', label=\"FP-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss2)), trloss2, ':', label=\"HFL2-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss3)), trloss3, ':', label=\"HFL4-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss4)), trloss4, ':', label=\"HFL8-FP16\")\n",
    "\n",
    "plt.plot(range(len(trloss5)), trloss5, label=\"FL\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss6)), trloss6, label=\"HFL2\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss7)), trloss7, label=\"HFL4\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss8)), trloss8, label=\"HFL8\")\n",
    "plt.legend(loc=\"upper right\")\n",
    "\n",
    "plt.ylabel('Training loss')\n",
    "plt.xlabel('Communication Rounds')\n",
    "plt.savefig('../save/' + datamodelset + '_loss_FP16_32.png')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# ===== MNIST CNN NON-IID ===== \n",
    "datamodelset = \"MNIST_CNN_NONIID FP16 and FP32 Comparison\"\n",
    "filename1 = \"FL_mnist_cnn_261_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]_FP16\"\n",
    "filename2 = \"HFL2_mnist_cnn_100_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]_FP16\"\n",
    "filename3 = \"HFL4_mnist_cnn_100_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]_FP16\"\n",
    "filename4 = \"HFL8_mnist_cnn_30_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]_FP16\"\n",
    "\n",
    "filename5 = \"[10]FL_mnist_cnn_261_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]\"\n",
    "filename6 = \"[12]HFL2_mnist_cnn_100_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]\"\n",
    "filename7 = \"[14]HFL4_mnist_cnn_100_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]\"\n",
    "filename8 = \"[16]HFL8_mnist_cnn_30_lr[0.01]_C[0.1]_iid[0]_E[1]_B[10]\"\n",
    "\n",
    "with open(r\"../save/objects_fp16/\" + filename1 + \".pkl\", \"rb\") as input_file: data1 = pickle.load(input_file)\n",
    "with open(r\"../save/objects_fp16/\" + filename2 + \".pkl\", \"rb\") as input_file: data2 = pickle.load(input_file)\n",
    "with open(r\"../save/objects_fp16/\" + filename3 + \".pkl\", \"rb\") as input_file: data3 = pickle.load(input_file)\n",
    "with open(r\"../save/objects_fp16/\" + filename4 + \".pkl\", \"rb\") as input_file: data4 = pickle.load(input_file)    \n",
    "\n",
    "with open(r\"../save/objects/\" + filename5 + \".pkl\", \"rb\") as input_file: data5 = pickle.load(input_file)\n",
    "with open(r\"../save/objects/\" + filename6 + \".pkl\", \"rb\") as input_file: data6 = pickle.load(input_file)\n",
    "with open(r\"../save/objects/\" + filename7 + \".pkl\", \"rb\") as input_file: data7 = pickle.load(input_file)\n",
    "with open(r\"../save/objects/\" + filename8 + \".pkl\", \"rb\") as input_file: data8 = pickle.load(input_file)    \n",
    "\n",
    "trloss1 = data1[0]    \n",
    "trloss2 = data2[0]    \n",
    "trloss3 = data3[0]    \n",
    "trloss4 = data4[0]    \n",
    "\n",
    "trloss5 = data5[0]    \n",
    "trloss6 = data6[0]    \n",
    "trloss7 = data7[0]    \n",
    "trloss8 = data8[0] \n",
    "\n",
    "tracc1 = data1[1]\n",
    "tracc2 = data2[1]\n",
    "tracc3 = data3[1]\n",
    "tracc4 = data4[1]\n",
    "\n",
    "tracc5 = data5[1]\n",
    "tracc6 = data6[1]\n",
    "tracc7 = data7[1]\n",
    "tracc8 = data8[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 34780 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 36112 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# PLOTTING \n",
    "\n",
    "# Plot Average Accuracy vs Communication rounds\n",
    "plt.figure()\n",
    "plt.title(datamodelset)\n",
    "\n",
    "plt.plot(range(len(tracc1)), tracc1, ':', label=\"FL-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc2)), tracc2, ':', label=\"HFL2-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc3)), tracc3, ':', label=\"HFL4-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc4)), tracc4, ':', label=\"HFL8-FP16\")\n",
    "\n",
    "plt.plot(range(len(tracc5)), tracc5, label=\"FL\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc6)), tracc6, label=\"HFL2\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc7)), tracc7, label=\"HFL4\", linewidth=0.9)\n",
    "plt.plot(range(len(tracc8)), tracc8, label=\"HFL8\")\n",
    "plt.legend(loc=\"lower right\")\n",
    "\n",
    "plt.ylabel('Average Accuracy')\n",
    "plt.xlabel('Communication Rounds')\n",
    "plt.savefig('../save/' + datamodelset + '_acc_FP16_32.png')\n",
    "\n",
    "\n",
    "# Plot Loss curve\n",
    "plt.figure()\n",
    "plt.title(datamodelset)\n",
    "\n",
    "plt.plot(range(len(trloss1)), trloss1, ':', label=\"FP-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss2)), trloss2, ':', label=\"HFL2-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss3)), trloss3, ':', label=\"HFL4-FP16\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss4)), trloss4, ':', label=\"HFL8-FP16\")\n",
    "\n",
    "plt.plot(range(len(trloss5)), trloss5, label=\"FL\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss6)), trloss6, label=\"HFL2\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss7)), trloss7, label=\"HFL4\", linewidth=0.9)\n",
    "plt.plot(range(len(trloss8)), trloss8, label=\"HFL8\")\n",
    "plt.legend(loc=\"upper right\")\n",
    "\n",
    "plt.ylabel('Training loss')\n",
    "plt.xlabel('Communication Rounds')\n",
    "plt.savefig('../save/' + datamodelset + '_loss_FP16_32.png')\n",
    "\n",
    "plt.show()"
   ]
  }
 ],
 "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.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
