{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d69d2abf",
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "import numpy as np\n",
    "import library.analysis as A \n",
    "from library.exercise import plotCloud\n",
    "from library.generators import *\n",
    "from library.dataset import DataSet\n",
    "from library.timing import timing\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f3364eda",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataSetName = \"imblearn_ozone_level\"\n",
    "dataSetName = \"folding_abalone_17_vs_7_8_9_10\"\n",
    "dataSetName = \"folding_abalone9-18\"\n",
    "#dataSetName = \"folding_yeast4\"\n",
    "#dataSetName = \"folding_car_good\"\n",
    "data = A.loadDataset(dataSetName)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d0ea209e",
   "metadata": {},
   "outputs": [],
   "source": [
    "def avg(x):\n",
    "    return sum(x) / len(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a11a121e",
   "metadata": {},
   "outputs": [],
   "source": [
    "def testHisto(descTrainCount):\n",
    "    print(f\"======[ {descTrainCount} ]======\")\n",
    "    t = timing(f\"train with {descTrainCount} extra rounds\")\n",
    "    t.start()\n",
    "    g = ConvGeN(data.data1.shape[1], neb_epochs=10, maj_proximal=True)\n",
    "    g.reset(data)\n",
    "    g.train(data, descTrainCount)\n",
    "    t.stop()\n",
    "    print(t)\n",
    "    t0 = g.predictReal(data.data0)\n",
    "    print(\"majority \" + str((min(t0), avg(t0), max(t0))))\n",
    "    t1 = g.predictReal(data.data1)\n",
    "    print(\"minority \" + str((min(t1), avg(t1), max(t1))))\n",
    "    t2 = g.predictReal(g.generateData(data.data0.shape[0]))\n",
    "    print(\"synthetic \" + str((min(t2), avg(t2), max(t2))))\n",
    "    plt.hist(t0, label=\"majority\")\n",
    "    #plt.hist(t1, label=\"minority\")\n",
    "    plt.hist(t2, label=\"synthetic\")\n",
    "    plt.show()\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "662817c4",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "for n in range(10):\n",
    "    testHisto(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19babca7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "05929c92",
   "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.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
