The Algorithms logo
The Algorithms
关于捐赠

A-Simple-GAN

H
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# G.A.N\n",
    "> Generative Adversial Network:\n",
    "> -  The main focus for GAN is to generate data from scratch.\n",
    "> -  It brings us closer to understanding intelligence.\n",
    "- It trains two deep networks, called Generator and Discriminator, that compete and cooperate with each other. In the course of training, both networks eventually learn how to perform their tasks.\n",
    "> > - The generator never actually sees examples from the domain and is adapted based on how well the discriminator performs."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[Original Article: How to Develop a 1D GAN](https://machinelearningmastery.com/how-to-develop-a-generative-adversarial-network-for-a-1-dimensional-function-from-scratch-in-keras/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "# The Import Statements:\n",
    "from matplotlib import pyplot\n",
    "import numpy as np\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Dense\n",
    "from keras.utils.vis_utils import plot_model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Defining a 1 D function:\n",
    "> y=f(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def function_1D(x):\n",
    "    return x*x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "inputs=np.arange(-0.5,0.6,0.1)\n",
    "outputs=[function_1D(x) for x in inputs]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJz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//3cTtmP3uZAHDfrWmAtcKyL7gNH2+4hIhoj8xdLK3MeZY/4xcCUwXUS22b8GWVPuxbGfc58FrAF2A8vtg+4fF5Hx9t3+CsSKSB5wPxfuuvJqTh7v09h+K11h/zdt/IPPpzh5zH5Dl0BQSik/p+/olVLKz2nQK6WUn9OgV0opP6dBr5RSfk6DXiml/JwGvVJK+TkNeqWU8nP/D0oL1tHXguspAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot the result\n",
    "pyplot.plot(inputs, outputs)\n",
    "pyplot.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Defining random values\n",
    "def generate_samples(n=100):\n",
    "    x1=np.random.rand(n)-0.5\n",
    "    x2=x1*x1\n",
    "    x1=x1.reshape(n,1)\n",
    "    x2=x2.reshape(n,1)\n",
    "    return np.hstack((x1,x2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAbVklEQVR4nO3df4xd5X3n8ffHw0CHpokNeNvmYmOSeNna64TZ3IIj1GSXEGy2wswSEnCwlkioKNui3UBqyRSrNsQrnFgpXamsFtogpYWACXVmB5HIywLZlVBsedwxWAN1Y9zE9k1248ZMpK2nYI+/+8c9176+vj/OzNy5P879vKQRM+ecO34O9nzmuc/zPc+jiMDMzLJrXrsbYGZmc8tBb2aWcQ56M7OMc9CbmWWcg97MLOMuaHcDKl122WWxZMmSdjfDzKy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zIs09I+kGir/0PxUR77aobXOp0X3/GvAvgR8kHbbfAEYkrYmI0Za1chY8dDNzI8Bdyed3Af+98oKIuDMiFkfEEorDN3/Z6SGfQsP7lnQh8F2K9/t8C9vWTHuApZKuTO7nDor3Xq78/8VtwCvR3U8gNrxnSYPA48CaiKj6S74L1b3viPhlRFwWEUuSn+VdFO+/K0IeHPSzsRX4jKQfATckXyMpL+kv2tqyuZXmvj8PfBL4oqR9ycfV7WnuzCRj7vcCO4G3gOciYlzSw5LWJJd9E7hU0kHgfupXXnW8lPe8jeK70+8kf6+Vv/y6Tsr77mpeAsHMLOPcozczyzgHvZlZxjnozcwyzkFvZpZxDnozs4xz0JuZZZyD3sws4/4/YCNZFSD5BhwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# generate samples and plotting them\n",
    "data = generate_samples()\n",
    "\n",
    "pyplot.scatter(data[:, 0], data[:, 1])\n",
    "pyplot.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Note:\n",
    "> *a sample is comprised of a vector with two elements, one for the input and one for the output of our one-dimensional function.*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### The Discriminator\n",
    "- The difference from a typical CNN is the absence of max-pooling in between layers.\n",
    "- will have 1 hidden layer with 25 nodes.\n",
    "- will use the ReLU activation function\n",
    "- The output layer will have 1 node for the binary classification using the sigmoid activation function.\n",
    "- Loss Function: Binary Cross Entropy\n",
    "- Optimizer : Adam version of stochastic Gradient Descent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Code for the Discriminator Unit:\n",
    "def define_discriminator(n_inputs=2):\n",
    "\tmodel = Sequential()\n",
    "\tmodel.add(Dense(25, activation='relu', kernel_initializer='he_uniform', input_dim=n_inputs))\n",
    "\tmodel.add(Dense(1, activation='sigmoid'))\n",
    "\t# compile model\n",
    "\tmodel.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n",
    "\treturn model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"sequential_1\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "dense_1 (Dense)              (None, 25)                75        \n",
      "_________________________________________________________________\n",
      "dense_2 (Dense)              (None, 1)                 26        \n",
      "=================================================================\n",
      "Total params: 101\n",
      "Trainable params: 101\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "# define the discriminator model\n",
    "model = define_discriminator()\n",
    "# summarize the model\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def generate_real_samples(n):\n",
    "    x1=np.random.rand(n)-0.5\n",
    "    x2=x1*x1\n",
    "    x1=x1.reshape(n,1)\n",
    "    x2=x2.reshape(n,1)\n",
    "    X= np.hstack((x1,x2))\n",
    "    y=np.ones((n,1))\n",
    "    return X,y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def generate_fake_samples(n):\n",
    "\t# generate inputs in [-1, 1]\n",
    "\tX1 = -1 + np.random.rand(n) * 2\n",
    "\t# generate outputs in [-1, 1]\n",
    "\tX2 = -1 + np.random.rand(n) * 2\n",
    "\t# stack arrays\n",
    "\tX1 = X1.reshape(n, 1)\n",
    "\tX2 = X2.reshape(n, 1)\n",
    "\tX = np.hstack((X1, X2))\n",
    "\t# generate class labels\n",
    "\ty = np.zeros((n, 1))\n",
    "\treturn X, y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "#training the discriminator model\n",
    "def train_discriminator(model, n_epochs=1000, n_batch=128):\n",
    "\thalf_batch = int(n_batch / 2)\n",
    "\t# run epochs manually\n",
    "\tfor i in range(n_epochs):\n",
    "\t\t# generate real examples\n",
    "\t\tX_real, y_real = generate_real_samples(half_batch)\n",
    "\t\t# update model\n",
    "\t\tmodel.train_on_batch(X_real, y_real)\n",
    "\t\t# generate fake examples\n",
    "\t\tX_fake, y_fake = generate_fake_samples(half_batch)\n",
    "\t\t# update model\n",
    "\t\tmodel.train_on_batch(X_fake, y_fake)\n",
    "\t\t# evaluate the model\n",
    "\t\t_, acc_real = model.evaluate(X_real, y_real, verbose=0)\n",
    "\t\t_, acc_fake = model.evaluate(X_fake, y_fake, verbose=0)\n",
    "\t\tprint(i, acc_real, acc_fake)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 0.5 0.15625\n",
      "1 0.546875 0.25\n",
      "2 0.578125 0.21875\n",
      "3 0.5625 0.21875\n",
      "4 0.640625 0.234375\n",
      "5 0.515625 0.40625\n",
      "6 0.515625 0.46875\n",
      "7 0.59375 0.390625\n",
      "8 0.5625 0.46875\n",
      "9 0.53125 0.4375\n",
      "10 0.46875 0.484375\n",
      "11 0.421875 0.53125\n",
      "12 0.46875 0.484375\n",
      "13 0.515625 0.5625\n",
      "14 0.46875 0.6875\n",
      "15 0.5625 0.515625\n",
      "16 0.515625 0.53125\n",
      "17 0.53125 0.5\n",
      "18 0.484375 0.609375\n",
      "19 0.40625 0.5\n",
      "20 0.46875 0.671875\n",
      "21 0.484375 0.59375\n",
      "22 0.546875 0.609375\n",
      "23 0.375 0.53125\n",
      "24 0.421875 0.53125\n",
      "25 0.34375 0.65625\n",
      "26 0.421875 0.484375\n",
      "27 0.421875 0.578125\n",
      "28 0.328125 0.546875\n",
      "29 0.359375 0.640625\n",
      "30 0.4375 0.609375\n",
      "31 0.296875 0.484375\n",
      "32 0.296875 0.53125\n",
      "33 0.515625 0.625\n",
      "34 0.359375 0.59375\n",
      "35 0.40625 0.65625\n",
      "36 0.359375 0.6875\n",
      "37 0.28125 0.578125\n",
      "38 0.328125 0.578125\n",
      "39 0.328125 0.671875\n",
      "40 0.40625 0.671875\n",
      "41 0.296875 0.515625\n",
      "42 0.296875 0.578125\n",
      "43 0.296875 0.625\n",
      "44 0.34375 0.625\n",
      "45 0.390625 0.671875\n",
      "46 0.375 0.609375\n",
      "47 0.34375 0.59375\n",
      "48 0.359375 0.578125\n",
      "49 0.359375 0.6875\n",
      "50 0.34375 0.65625\n",
      "51 0.375 0.515625\n",
      "52 0.390625 0.609375\n",
      "53 0.234375 0.625\n",
      "54 0.359375 0.625\n",
      "55 0.234375 0.59375\n",
      "56 0.40625 0.6875\n",
      "57 0.34375 0.765625\n",
      "58 0.296875 0.609375\n",
      "59 0.265625 0.59375\n",
      "60 0.25 0.65625\n",
      "61 0.390625 0.65625\n",
      "62 0.265625 0.65625\n",
      "63 0.46875 0.703125\n",
      "64 0.40625 0.59375\n",
      "65 0.359375 0.625\n",
      "66 0.28125 0.625\n",
      "67 0.3125 0.625\n",
      "68 0.328125 0.640625\n",
      "69 0.390625 0.625\n",
      "70 0.28125 0.640625\n",
      "71 0.328125 0.609375\n",
      "72 0.296875 0.59375\n",
      "73 0.125 0.703125\n",
      "74 0.359375 0.765625\n",
      "75 0.359375 0.65625\n",
      "76 0.34375 0.5625\n",
      "77 0.234375 0.671875\n",
      "78 0.34375 0.6875\n",
      "79 0.21875 0.734375\n",
      "80 0.3125 0.78125\n",
      "81 0.28125 0.6875\n",
      "82 0.34375 0.640625\n",
      "83 0.375 0.765625\n",
      "84 0.34375 0.640625\n",
      "85 0.328125 0.703125\n",
      "86 0.21875 0.75\n",
      "87 0.25 0.65625\n",
      "88 0.28125 0.640625\n",
      "89 0.3125 0.78125\n",
      "90 0.234375 0.71875\n",
      "91 0.328125 0.71875\n",
      "92 0.25 0.671875\n",
      "93 0.25 0.703125\n",
      "94 0.265625 0.546875\n",
      "95 0.296875 0.546875\n",
      "96 0.328125 0.625\n",
      "97 0.265625 0.75\n",
      "98 0.296875 0.671875\n",
      "99 0.265625 0.703125\n",
      "100 0.15625 0.734375\n",
      "101 0.234375 0.796875\n",
      "102 0.25 0.71875\n",
      "103 0.21875 0.828125\n",
      "104 0.21875 0.828125\n",
      "105 0.328125 0.765625\n",
      "106 0.21875 0.671875\n",
      "107 0.28125 0.84375\n",
      "108 0.21875 0.796875\n",
      "109 0.21875 0.78125\n",
      "110 0.25 0.65625\n",
      "111 0.25 0.8125\n",
      "112 0.21875 0.859375\n",
      "113 0.28125 0.796875\n",
      "114 0.234375 0.625\n",
      "115 0.21875 0.671875\n",
      "116 0.234375 0.859375\n",
      "117 0.265625 0.71875\n",
      "118 0.21875 0.765625\n",
      "119 0.234375 0.765625\n",
      "120 0.234375 0.6875\n",
      "121 0.234375 0.8125\n",
      "122 0.296875 0.828125\n",
      "123 0.25 0.796875\n",
      "124 0.234375 0.890625\n",
      "125 0.359375 0.765625\n",
      "126 0.203125 0.75\n",
      "127 0.328125 0.703125\n",
      "128 0.203125 0.78125\n",
      "129 0.265625 0.796875\n",
      "130 0.3125 0.828125\n",
      "131 0.21875 0.828125\n",
      "132 0.25 0.828125\n",
      "133 0.296875 0.84375\n",
      "134 0.203125 0.875\n",
      "135 0.34375 0.734375\n",
      "136 0.421875 0.765625\n",
      "137 0.15625 0.796875\n",
      "138 0.359375 0.75\n",
      "139 0.234375 0.75\n",
      "140 0.421875 0.71875\n",
      "141 0.28125 0.703125\n",
      "142 0.1875 0.6875\n",
      "143 0.21875 0.828125\n",
      "144 0.25 0.890625\n",
      "145 0.265625 0.9375\n",
      "146 0.171875 0.8125\n",
      "147 0.265625 0.84375\n",
      "148 0.296875 0.90625\n",
      "149 0.171875 0.875\n",
      "150 0.21875 0.765625\n",
      "151 0.25 0.875\n",
      "152 0.25 0.90625\n",
      "153 0.25 0.90625\n",
      "154 0.328125 0.796875\n",
      "155 0.296875 0.921875\n",
      "156 0.234375 0.84375\n",
      "157 0.25 0.875\n",
      "158 0.1875 0.9375\n",
      "159 0.234375 0.859375\n",
      "160 0.234375 0.890625\n",
      "161 0.28125 0.984375\n",
      "162 0.21875 0.90625\n",
      "163 0.21875 0.90625\n",
      "164 0.265625 0.953125\n",
      "165 0.28125 0.953125\n",
      "166 0.328125 0.984375\n",
      "167 0.28125 0.96875\n",
      "168 0.25 0.953125\n",
      "169 0.359375 0.921875\n",
      "170 0.34375 1.0\n",
      "171 0.328125 0.953125\n",
      "172 0.296875 0.96875\n",
      "173 0.359375 0.921875\n",
      "174 0.28125 0.9375\n",
      "175 0.375 0.984375\n",
      "176 0.359375 0.96875\n",
      "177 0.265625 0.984375\n",
      "178 0.21875 0.96875\n",
      "179 0.28125 0.9375\n",
      "180 0.359375 1.0\n",
      "181 0.34375 0.984375\n",
      "182 0.40625 0.984375\n",
      "183 0.296875 0.953125\n",
      "184 0.34375 0.984375\n",
      "185 0.3125 0.984375\n",
      "186 0.359375 0.96875\n",
      "187 0.375 0.984375\n",
      "188 0.53125 0.953125\n",
      "189 0.40625 0.921875\n",
      "190 0.453125 0.953125\n",
      "191 0.375 0.96875\n",
      "192 0.609375 0.9375\n",
      "193 0.40625 0.96875\n",
      "194 0.4375 0.96875\n",
      "195 0.390625 0.96875\n",
      "196 0.40625 0.984375\n",
      "197 0.4375 1.0\n",
      "198 0.546875 0.953125\n",
      "199 0.328125 1.0\n",
      "200 0.328125 0.984375\n",
      "201 0.328125 0.984375\n",
      "202 0.453125 0.96875\n",
      "203 0.34375 0.96875\n",
      "204 0.34375 0.984375\n",
      "205 0.359375 0.96875\n",
      "206 0.359375 0.984375\n",
      "207 0.421875 0.96875\n",
      "208 0.5 0.984375\n",
      "209 0.40625 1.0\n",
      "210 0.390625 0.96875\n",
      "211 0.546875 0.96875\n",
      "212 0.390625 0.984375\n",
      "213 0.5 0.921875\n",
      "214 0.578125 0.96875\n",
      "215 0.671875 0.9375\n",
      "216 0.484375 0.984375\n",
      "217 0.4375 0.90625\n",
      "218 0.453125 0.96875\n",
      "219 0.421875 0.953125\n",
      "220 0.625 0.9375\n",
      "221 0.5 0.953125\n",
      "222 0.578125 0.984375\n",
      "223 0.53125 0.9375\n",
      "224 0.5625 0.984375\n",
      "225 0.546875 0.984375\n",
      "226 0.5625 0.96875\n",
      "227 0.578125 0.984375\n",
      "228 0.5625 0.953125\n",
      "229 0.546875 0.90625\n",
      "230 0.546875 0.921875\n",
      "231 0.75 1.0\n",
      "232 0.546875 1.0\n",
      "233 0.671875 1.0\n",
      "234 0.5625 0.96875\n",
      "235 0.640625 0.984375\n",
      "236 0.6875 0.921875\n",
      "237 0.59375 0.90625\n",
      "238 0.71875 0.921875\n",
      "239 0.609375 1.0\n",
      "240 0.59375 0.953125\n",
      "241 0.65625 0.953125\n",
      "242 0.640625 0.984375\n",
      "243 0.6875 0.984375\n",
      "244 0.546875 0.9375\n",
      "245 0.71875 1.0\n",
      "246 0.71875 0.953125\n",
      "247 0.609375 1.0\n",
      "248 0.671875 0.96875\n",
      "249 0.625 0.953125\n",
      "250 0.53125 0.921875\n",
      "251 0.6875 0.984375\n",
      "252 0.625 0.921875\n",
      "253 0.65625 0.984375\n",
      "254 0.625 0.9375\n",
      "255 0.75 0.96875\n",
      "256 0.609375 0.984375\n",
      "257 0.640625 0.921875\n",
      "258 0.6875 0.984375\n",
      "259 0.671875 1.0\n",
      "260 0.625 0.9375\n",
      "261 0.65625 0.984375\n",
      "262 0.703125 0.96875\n",
      "263 0.734375 1.0\n",
      "264 0.65625 0.984375\n",
      "265 0.578125 0.9375\n",
      "266 0.59375 0.96875\n",
      "267 0.703125 0.921875\n",
      "268 0.734375 1.0\n",
      "269 0.734375 1.0\n",
      "270 0.703125 0.984375\n",
      "271 0.734375 0.984375\n",
      "272 0.6875 0.953125\n",
      "273 0.703125 0.96875\n",
      "274 0.71875 1.0\n",
      "275 0.65625 0.953125\n",
      "276 0.75 0.921875\n",
      "277 0.609375 0.984375\n",
      "278 0.6875 1.0\n",
      "279 0.6875 0.953125\n",
      "280 0.765625 1.0\n",
      "281 0.796875 1.0\n",
      "282 0.734375 0.96875\n",
      "283 0.671875 0.984375\n",
      "284 0.578125 1.0\n",
      "285 0.671875 0.953125\n",
      "286 0.671875 0.984375\n",
      "287 0.75 0.9375\n",
      "288 0.734375 0.984375\n",
      "289 0.71875 0.96875\n",
      "290 0.75 0.96875\n",
      "291 0.6875 0.984375\n",
      "292 0.65625 0.9375\n",
      "293 0.734375 0.984375\n",
      "294 0.65625 0.953125\n",
      "295 0.703125 0.96875\n",
      "296 0.6875 0.984375\n",
      "297 0.71875 0.984375\n",
      "298 0.734375 0.953125\n",
      "299 0.71875 0.9375\n",
      "300 0.734375 0.984375\n",
      "301 0.78125 0.953125\n",
      "302 0.75 0.9375\n",
      "303 0.75 0.953125\n",
      "304 0.796875 0.96875\n",
      "305 0.734375 1.0\n",
      "306 0.71875 0.921875\n",
      "307 0.796875 0.953125\n",
      "308 0.84375 0.96875\n",
      "309 0.75 0.96875\n",
      "310 0.71875 1.0\n",
      "311 0.828125 0.96875\n",
      "312 0.8125 0.984375\n",
      "313 0.78125 0.9375\n",
      "314 0.84375 0.96875\n",
      "315 0.6875 0.984375\n",
      "316 0.84375 0.953125\n",
      "317 0.8125 0.984375\n",
      "318 0.765625 0.9375\n",
      "319 0.71875 0.9375\n",
      "320 0.703125 0.9375\n",
      "321 0.671875 0.96875\n",
      "322 0.703125 0.921875\n",
      "323 0.765625 0.96875\n",
      "324 0.703125 0.953125\n",
      "325 0.828125 0.96875\n",
      "326 0.828125 0.96875\n",
      "327 0.78125 0.984375\n",
      "328 0.8125 0.953125\n",
      "329 0.796875 0.984375\n",
      "330 0.765625 0.9375\n",
      "331 0.890625 0.90625\n",
      "332 0.8125 0.90625\n",
      "333 0.8125 1.0\n",
      "334 0.78125 0.96875\n",
      "335 0.875 0.96875\n",
      "336 0.84375 0.984375\n",
      "337 0.796875 1.0\n",
      "338 0.8125 0.984375\n",
      "339 0.78125 0.9375\n",
      "340 0.875 0.953125\n",
      "341 0.8125 0.921875\n",
      "342 0.796875 0.90625\n",
      "343 0.796875 0.953125\n",
      "344 0.8125 0.984375\n",
      "345 0.890625 0.9375\n",
      "346 0.828125 0.9375\n",
      "347 0.78125 0.96875\n",
      "348 0.90625 0.953125\n",
      "349 0.828125 0.96875\n",
      "350 0.796875 0.953125\n",
      "351 0.734375 0.921875\n",
      "352 0.796875 0.984375\n",
      "353 0.765625 0.921875\n",
      "354 0.8125 0.90625\n",
      "355 0.765625 0.96875\n",
      "356 0.84375 0.96875\n",
      "357 0.875 0.953125\n",
      "358 0.8125 0.90625\n",
      "359 0.828125 0.96875\n",
      "360 0.828125 0.953125\n",
      "361 0.84375 0.984375\n",
      "362 0.859375 0.9375\n",
      "363 0.859375 0.953125\n",
      "364 0.859375 0.9375\n",
      "365 0.875 0.96875\n",
      "366 0.875 0.953125\n",
      "367 0.8125 0.953125\n",
      "368 0.90625 0.9375\n",
      "369 0.875 0.984375\n",
      "370 0.9375 0.890625\n",
      "371 0.875 0.9375\n",
      "372 0.796875 0.921875\n",
      "373 0.828125 0.921875\n",
      "374 0.90625 0.921875\n",
      "375 0.8125 0.9375\n",
      "376 0.8125 0.90625\n",
      "377 0.90625 0.921875\n",
      "378 0.765625 1.0\n",
      "379 0.78125 0.953125\n",
      "380 0.78125 0.953125\n",
      "381 0.875 0.953125\n",
      "382 0.875 0.9375\n",
      "383 0.84375 0.890625\n",
      "384 0.796875 0.9375\n",
      "385 0.859375 0.96875\n",
      "386 0.8125 0.96875\n",
      "387 0.90625 0.953125\n",
      "388 0.921875 0.9375\n",
      "389 0.890625 0.953125\n",
      "390 0.96875 0.921875\n",
      "391 0.84375 0.875\n",
      "392 0.875 0.921875\n",
      "393 0.828125 0.9375\n",
      "394 0.921875 0.9375\n",
      "395 0.890625 0.9375\n",
      "396 0.921875 0.921875\n",
      "397 0.890625 1.0\n",
      "398 0.875 0.984375\n",
      "399 0.921875 0.9375\n",
      "400 0.828125 0.953125\n",
      "401 0.828125 0.90625\n",
      "402 0.9375 0.953125\n",
      "403 0.8125 0.890625\n",
      "404 0.953125 0.953125\n",
      "405 0.9375 0.890625\n",
      "406 0.90625 0.96875\n",
      "407 0.890625 0.984375\n",
      "408 0.875 0.9375\n",
      "409 0.921875 0.984375\n",
      "410 0.859375 0.96875\n",
      "411 0.890625 0.953125\n",
      "412 0.921875 0.96875\n",
      "413 0.921875 1.0\n",
      "414 0.921875 0.96875\n",
      "415 0.875 0.90625\n",
      "416 0.96875 0.96875\n",
      "417 0.890625 0.921875\n",
      "418 0.90625 0.953125\n",
      "419 0.875 0.9375\n",
      "420 0.875 0.921875\n",
      "421 0.96875 0.953125\n",
      "422 0.921875 0.96875\n",
      "423 0.890625 0.875\n",
      "424 0.84375 0.90625\n",
      "425 0.921875 0.984375\n",
      "426 0.953125 0.890625\n",
      "427 1.0 0.90625\n",
      "428 0.890625 0.9375\n",
      "429 0.921875 0.9375\n",
      "430 0.9375 0.953125\n",
      "431 0.96875 0.953125\n",
      "432 0.90625 0.9375\n",
      "433 0.953125 0.875\n",
      "434 0.953125 0.890625\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "435 0.96875 0.90625\n",
      "436 0.9375 0.953125\n",
      "437 0.96875 0.953125\n",
      "438 0.953125 0.890625\n",
      "439 0.921875 0.953125\n",
      "440 0.953125 0.90625\n",
      "441 0.90625 0.984375\n",
      "442 0.96875 0.96875\n",
      "443 0.984375 0.9375\n",
      "444 0.921875 0.9375\n",
      "445 0.96875 0.90625\n",
      "446 0.921875 0.96875\n",
      "447 0.890625 0.875\n",
      "448 0.953125 0.953125\n",
      "449 0.984375 0.953125\n",
      "450 0.921875 0.953125\n",
      "451 1.0 0.90625\n",
      "452 0.984375 0.96875\n",
      "453 1.0 0.90625\n",
      "454 0.953125 0.953125\n",
      "455 0.96875 0.9375\n",
      "456 0.953125 0.90625\n",
      "457 1.0 0.921875\n",
      "458 0.984375 0.96875\n",
      "459 0.984375 0.90625\n",
      "460 0.984375 0.984375\n",
      "461 1.0 0.921875\n",
      "462 0.984375 0.953125\n",
      "463 0.96875 0.921875\n",
      "464 1.0 0.921875\n",
      "465 0.984375 0.859375\n",
      "466 1.0 0.90625\n",
      "467 1.0 0.890625\n",
      "468 1.0 0.90625\n",
      "469 1.0 0.875\n",
      "470 1.0 0.84375\n",
      "471 1.0 0.875\n",
      "472 0.984375 0.859375\n",
      "473 1.0 0.859375\n",
      "474 1.0 0.921875\n",
      "475 0.984375 0.96875\n",
      "476 1.0 0.875\n",
      "477 1.0 0.890625\n",
      "478 1.0 0.921875\n",
      "479 1.0 0.890625\n",
      "480 1.0 0.953125\n",
      "481 1.0 0.90625\n",
      "482 1.0 0.890625\n",
      "483 1.0 0.90625\n",
      "484 1.0 0.90625\n",
      "485 1.0 0.890625\n",
      "486 1.0 0.921875\n",
      "487 1.0 0.96875\n",
      "488 1.0 0.9375\n",
      "489 1.0 0.921875\n",
      "490 1.0 0.890625\n",
      "491 1.0 0.890625\n",
      "492 1.0 0.9375\n",
      "493 1.0 0.90625\n",
      "494 0.984375 0.9375\n",
      "495 1.0 0.875\n",
      "496 1.0 0.890625\n",
      "497 1.0 0.9375\n",
      "498 1.0 0.921875\n",
      "499 0.984375 0.921875\n",
      "500 1.0 0.921875\n",
      "501 1.0 0.875\n",
      "502 1.0 0.90625\n",
      "503 1.0 0.953125\n",
      "504 1.0 0.921875\n",
      "505 1.0 0.96875\n",
      "506 1.0 0.953125\n",
      "507 1.0 0.921875\n",
      "508 1.0 0.921875\n",
      "509 1.0 0.890625\n",
      "510 1.0 0.96875\n",
      "511 1.0 0.921875\n",
      "512 1.0 0.921875\n",
      "513 1.0 0.859375\n",
      "514 1.0 0.875\n",
      "515 1.0 0.921875\n",
      "516 1.0 0.9375\n",
      "517 1.0 0.890625\n",
      "518 1.0 0.90625\n",
      "519 1.0 0.875\n",
      "520 1.0 0.90625\n",
      "521 1.0 0.9375\n",
      "522 1.0 0.921875\n",
      "523 1.0 0.875\n",
      "524 1.0 0.875\n",
      "525 1.0 0.921875\n",
      "526 1.0 0.953125\n",
      "527 1.0 0.90625\n",
      "528 1.0 0.90625\n",
      "529 1.0 0.90625\n",
      "530 1.0 0.890625\n",
      "531 1.0 0.90625\n",
      "532 1.0 0.921875\n",
      "533 1.0 0.921875\n",
      "534 1.0 0.953125\n",
      "535 1.0 0.875\n",
      "536 1.0 0.90625\n",
      "537 1.0 0.859375\n",
      "538 1.0 0.890625\n",
      "539 1.0 0.9375\n",
      "540 1.0 0.9375\n",
      "541 1.0 0.953125\n",
      "542 1.0 0.890625\n",
      "543 1.0 0.90625\n",
      "544 1.0 0.84375\n",
      "545 1.0 0.890625\n",
      "546 1.0 0.890625\n",
      "547 1.0 0.953125\n",
      "548 1.0 0.9375\n",
      "549 1.0 0.9375\n",
      "550 1.0 0.890625\n",
      "551 1.0 0.96875\n",
      "552 1.0 0.921875\n",
      "553 1.0 0.890625\n",
      "554 1.0 0.90625\n",
      "555 1.0 0.96875\n",
      "556 1.0 0.921875\n",
      "557 1.0 0.953125\n",
      "558 1.0 0.890625\n",
      "559 1.0 0.9375\n",
      "560 1.0 0.9375\n",
      "561 1.0 0.90625\n",
      "562 1.0 0.9375\n",
      "563 1.0 0.953125\n",
      "564 1.0 0.875\n",
      "565 1.0 0.90625\n",
      "566 1.0 0.859375\n",
      "567 1.0 0.875\n",
      "568 1.0 0.921875\n",
      "569 1.0 0.84375\n",
      "570 1.0 0.890625\n",
      "571 1.0 0.890625\n",
      "572 1.0 0.953125\n",
      "573 1.0 0.90625\n",
      "574 1.0 0.921875\n",
      "575 1.0 0.921875\n",
      "576 1.0 0.921875\n",
      "577 1.0 0.859375\n",
      "578 1.0 0.9375\n",
      "579 1.0 0.953125\n",
      "580 1.0 0.921875\n",
      "581 1.0 0.875\n",
      "582 1.0 0.875\n",
      "583 1.0 0.875\n",
      "584 1.0 0.921875\n",
      "585 1.0 0.890625\n",
      "586 1.0 0.890625\n",
      "587 1.0 0.890625\n",
      "588 1.0 0.90625\n",
      "589 1.0 0.875\n",
      "590 1.0 0.90625\n",
      "591 1.0 0.859375\n",
      "592 1.0 0.90625\n",
      "593 1.0 0.84375\n",
      "594 1.0 0.859375\n",
      "595 1.0 0.890625\n",
      "596 1.0 0.90625\n",
      "597 1.0 0.875\n",
      "598 1.0 0.953125\n",
      "599 1.0 0.875\n",
      "600 1.0 0.859375\n",
      "601 1.0 0.9375\n",
      "602 1.0 0.875\n",
      "603 1.0 0.859375\n",
      "604 1.0 0.90625\n",
      "605 1.0 0.90625\n",
      "606 1.0 0.78125\n",
      "607 1.0 0.828125\n",
      "608 1.0 0.9375\n",
      "609 1.0 0.921875\n",
      "610 1.0 0.90625\n",
      "611 1.0 0.953125\n",
      "612 1.0 0.890625\n",
      "613 1.0 0.9375\n",
      "614 1.0 0.921875\n",
      "615 1.0 0.796875\n",
      "616 1.0 0.890625\n",
      "617 1.0 0.921875\n",
      "618 1.0 0.90625\n",
      "619 1.0 0.890625\n",
      "620 1.0 0.859375\n",
      "621 1.0 0.921875\n",
      "622 1.0 0.828125\n",
      "623 1.0 0.875\n",
      "624 1.0 0.953125\n",
      "625 1.0 0.84375\n",
      "626 1.0 0.9375\n",
      "627 1.0 0.9375\n",
      "628 1.0 0.859375\n",
      "629 1.0 0.9375\n",
      "630 1.0 0.90625\n",
      "631 1.0 0.9375\n",
      "632 1.0 0.921875\n",
      "633 1.0 0.90625\n",
      "634 1.0 0.90625\n",
      "635 1.0 0.890625\n",
      "636 1.0 0.78125\n",
      "637 1.0 0.90625\n",
      "638 1.0 0.890625\n",
      "639 1.0 0.921875\n",
      "640 1.0 0.75\n",
      "641 1.0 0.875\n",
      "642 1.0 0.875\n",
      "643 1.0 0.90625\n",
      "644 1.0 0.953125\n",
      "645 1.0 0.921875\n",
      "646 1.0 0.890625\n",
      "647 1.0 0.859375\n",
      "648 1.0 0.84375\n",
      "649 1.0 0.90625\n",
      "650 1.0 0.84375\n",
      "651 1.0 0.84375\n",
      "652 1.0 0.921875\n",
      "653 1.0 0.90625\n",
      "654 1.0 0.921875\n",
      "655 1.0 0.921875\n",
      "656 1.0 0.921875\n",
      "657 1.0 0.84375\n",
      "658 1.0 0.84375\n",
      "659 1.0 0.90625\n",
      "660 1.0 0.953125\n",
      "661 1.0 0.890625\n",
      "662 1.0 0.875\n",
      "663 1.0 0.84375\n",
      "664 1.0 0.84375\n",
      "665 1.0 0.8125\n",
      "666 1.0 0.859375\n",
      "667 1.0 0.90625\n",
      "668 1.0 0.90625\n",
      "669 1.0 0.875\n",
      "670 1.0 0.921875\n",
      "671 1.0 0.84375\n",
      "672 1.0 0.953125\n",
      "673 1.0 0.84375\n",
      "674 1.0 0.8125\n",
      "675 1.0 0.84375\n",
      "676 1.0 0.921875\n",
      "677 1.0 0.953125\n",
      "678 1.0 0.84375\n",
      "679 1.0 0.859375\n",
      "680 1.0 0.859375\n",
      "681 1.0 0.90625\n",
      "682 1.0 0.90625\n",
      "683 1.0 0.90625\n",
      "684 1.0 0.828125\n",
      "685 1.0 0.875\n",
      "686 1.0 0.9375\n",
      "687 1.0 0.859375\n",
      "688 1.0 0.859375\n",
      "689 1.0 0.84375\n",
      "690 1.0 0.953125\n",
      "691 1.0 0.84375\n",
      "692 1.0 0.859375\n",
      "693 1.0 0.9375\n",
      "694 1.0 0.890625\n",
      "695 1.0 0.859375\n",
      "696 1.0 0.875\n",
      "697 1.0 0.875\n",
      "698 1.0 0.9375\n",
      "699 1.0 0.890625\n",
      "700 1.0 0.921875\n",
      "701 1.0 0.828125\n",
      "702 1.0 0.84375\n",
      "703 1.0 0.90625\n",
      "704 1.0 0.859375\n",
      "705 1.0 0.90625\n",
      "706 1.0 0.921875\n",
      "707 1.0 0.9375\n",
      "708 1.0 0.84375\n",
      "709 1.0 0.875\n",
      "710 1.0 0.90625\n",
      "711 1.0 0.90625\n",
      "712 1.0 0.890625\n",
      "713 1.0 0.921875\n",
      "714 1.0 0.90625\n",
      "715 1.0 0.890625\n",
      "716 1.0 0.8125\n",
      "717 1.0 0.875\n",
      "718 1.0 0.890625\n",
      "719 1.0 0.890625\n",
      "720 1.0 0.90625\n",
      "721 1.0 0.875\n",
      "722 1.0 0.84375\n",
      "723 1.0 0.9375\n",
      "724 1.0 0.90625\n",
      "725 1.0 0.84375\n",
      "726 1.0 0.9375\n",
      "727 1.0 0.875\n",
      "728 1.0 0.8125\n",
      "729 1.0 0.84375\n",
      "730 1.0 0.9375\n",
      "731 1.0 0.84375\n",
      "732 1.0 0.875\n",
      "733 1.0 0.921875\n",
      "734 1.0 0.78125\n",
      "735 1.0 0.78125\n",
      "736 1.0 0.859375\n",
      "737 1.0 0.84375\n",
      "738 1.0 0.90625\n",
      "739 1.0 0.859375\n",
      "740 1.0 0.875\n",
      "741 1.0 0.859375\n",
      "742 1.0 0.890625\n",
      "743 1.0 0.875\n",
      "744 1.0 0.890625\n",
      "745 1.0 0.859375\n",
      "746 1.0 0.8125\n",
      "747 1.0 0.859375\n",
      "748 1.0 0.953125\n",
      "749 1.0 0.84375\n",
      "750 1.0 0.890625\n",
      "751 1.0 0.796875\n",
      "752 1.0 0.890625\n",
      "753 1.0 0.796875\n",
      "754 1.0 0.84375\n",
      "755 1.0 0.890625\n",
      "756 1.0 0.875\n",
      "757 1.0 0.890625\n",
      "758 1.0 0.921875\n",
      "759 1.0 0.84375\n",
      "760 1.0 0.875\n",
      "761 1.0 0.859375\n",
      "762 1.0 0.953125\n",
      "763 1.0 0.890625\n",
      "764 1.0 0.859375\n",
      "765 1.0 0.84375\n",
      "766 1.0 0.828125\n",
      "767 1.0 0.8125\n",
      "768 1.0 0.84375\n",
      "769 1.0 0.859375\n",
      "770 1.0 0.875\n",
      "771 1.0 0.890625\n",
      "772 1.0 0.90625\n",
      "773 1.0 0.90625\n",
      "774 1.0 0.953125\n",
      "775 1.0 0.90625\n",
      "776 1.0 0.890625\n",
      "777 1.0 0.890625\n",
      "778 1.0 0.921875\n",
      "779 1.0 0.90625\n",
      "780 1.0 0.90625\n",
      "781 1.0 0.90625\n",
      "782 1.0 0.796875\n",
      "783 1.0 0.765625\n",
      "784 1.0 0.921875\n",
      "785 1.0 0.875\n",
      "786 1.0 0.890625\n",
      "787 1.0 0.90625\n",
      "788 1.0 0.90625\n",
      "789 1.0 0.890625\n",
      "790 1.0 0.859375\n",
      "791 1.0 0.890625\n",
      "792 1.0 0.875\n",
      "793 1.0 0.796875\n",
      "794 1.0 0.859375\n",
      "795 1.0 0.828125\n",
      "796 1.0 0.890625\n",
      "797 1.0 0.875\n",
      "798 1.0 0.890625\n",
      "799 1.0 0.8125\n",
      "800 1.0 0.875\n",
      "801 1.0 0.921875\n",
      "802 1.0 0.90625\n",
      "803 1.0 0.890625\n",
      "804 1.0 0.90625\n",
      "805 1.0 0.890625\n",
      "806 1.0 0.90625\n",
      "807 1.0 0.9375\n",
      "808 1.0 0.90625\n",
      "809 1.0 0.90625\n",
      "810 1.0 0.859375\n",
      "811 1.0 0.859375\n",
      "812 1.0 0.890625\n",
      "813 1.0 0.875\n",
      "814 1.0 0.8125\n",
      "815 1.0 0.875\n",
      "816 1.0 0.921875\n",
      "817 1.0 0.9375\n",
      "818 1.0 0.890625\n",
      "819 1.0 0.90625\n",
      "820 1.0 0.921875\n",
      "821 1.0 0.875\n",
      "822 1.0 0.9375\n",
      "823 1.0 0.90625\n",
      "824 1.0 0.875\n",
      "825 1.0 0.84375\n",
      "826 1.0 0.875\n",
      "827 1.0 0.8125\n",
      "828 1.0 0.8125\n",
      "829 1.0 0.890625\n",
      "830 1.0 0.78125\n",
      "831 1.0 0.890625\n",
      "832 1.0 0.890625\n",
      "833 1.0 0.84375\n",
      "834 1.0 0.859375\n",
      "835 1.0 0.875\n",
      "836 1.0 0.890625\n",
      "837 1.0 0.9375\n",
      "838 1.0 0.953125\n",
      "839 1.0 0.875\n",
      "840 1.0 0.890625\n",
      "841 1.0 0.78125\n",
      "842 1.0 0.921875\n",
      "843 1.0 0.875\n",
      "844 1.0 0.84375\n",
      "845 1.0 0.859375\n",
      "846 1.0 0.828125\n",
      "847 1.0 0.8125\n",
      "848 1.0 0.921875\n",
      "849 1.0 0.890625\n",
      "850 1.0 0.84375\n",
      "851 1.0 0.96875\n",
      "852 1.0 0.90625\n",
      "853 1.0 0.9375\n",
      "854 1.0 0.875\n",
      "855 1.0 0.890625\n",
      "856 1.0 0.859375\n",
      "857 1.0 0.890625\n",
      "858 1.0 0.8125\n",
      "859 1.0 0.875\n",
      "860 1.0 0.875\n",
      "861 1.0 0.875\n",
      "862 1.0 0.859375\n",
      "863 1.0 0.875\n",
      "864 1.0 0.9375\n",
      "865 1.0 0.796875\n",
      "866 1.0 0.84375\n",
      "867 1.0 0.90625\n",
      "868 1.0 0.875\n",
      "869 1.0 0.890625\n",
      "870 1.0 0.953125\n",
      "871 1.0 0.890625\n",
      "872 1.0 0.90625\n",
      "873 1.0 0.828125\n",
      "874 1.0 0.96875\n",
      "875 1.0 0.90625\n",
      "876 1.0 0.84375\n",
      "877 1.0 0.765625\n",
      "878 1.0 0.96875\n",
      "879 1.0 0.890625\n",
      "880 1.0 0.890625\n",
      "881 1.0 0.84375\n",
      "882 1.0 0.890625\n",
      "883 1.0 0.84375\n",
      "884 1.0 0.859375\n",
      "885 1.0 0.84375\n",
      "886 1.0 0.859375\n",
      "887 1.0 0.875\n",
      "888 1.0 0.921875\n",
      "889 1.0 0.90625\n",
      "890 1.0 0.90625\n",
      "891 1.0 0.859375\n",
      "892 1.0 0.859375\n",
      "893 1.0 0.9375\n",
      "894 1.0 0.84375\n",
      "895 1.0 0.859375\n",
      "896 1.0 0.90625\n",
      "897 1.0 0.9375\n",
      "898 1.0 0.84375\n",
      "899 1.0 0.890625\n",
      "900 1.0 0.828125\n",
      "901 1.0 0.90625\n",
      "902 1.0 0.90625\n",
      "903 1.0 0.859375\n",
      "904 1.0 0.875\n",
      "905 1.0 0.84375\n",
      "906 1.0 0.875\n",
      "907 1.0 0.875\n",
      "908 1.0 0.859375\n",
      "909 1.0 0.875\n",
      "910 1.0 0.9375\n",
      "911 1.0 0.796875\n",
      "912 1.0 0.90625\n",
      "913 1.0 0.859375\n",
      "914 1.0 0.9375\n",
      "915 1.0 0.875\n",
      "916 1.0 0.859375\n",
      "917 1.0 0.890625\n",
      "918 1.0 0.890625\n",
      "919 1.0 0.875\n",
      "920 1.0 0.953125\n",
      "921 1.0 0.921875\n",
      "922 1.0 0.921875\n",
      "923 1.0 0.890625\n",
      "924 1.0 0.9375\n",
      "925 1.0 0.859375\n",
      "926 1.0 0.90625\n",
      "927 1.0 0.921875\n",
      "928 1.0 0.859375\n",
      "929 1.0 0.859375\n",
      "930 1.0 0.875\n",
      "931 1.0 0.890625\n",
      "932 1.0 0.890625\n",
      "933 1.0 0.859375\n",
      "934 1.0 0.859375\n",
      "935 1.0 0.828125\n",
      "936 1.0 0.96875\n",
      "937 1.0 0.875\n",
      "938 1.0 0.75\n",
      "939 1.0 0.9375\n",
      "940 1.0 0.828125\n",
      "941 1.0 0.890625\n",
      "942 1.0 0.828125\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "943 1.0 0.859375\n",
      "944 1.0 0.875\n",
      "945 1.0 0.921875\n",
      "946 1.0 0.890625\n",
      "947 1.0 0.921875\n",
      "948 1.0 0.9375\n",
      "949 1.0 0.953125\n",
      "950 1.0 0.875\n",
      "951 1.0 0.859375\n",
      "952 1.0 0.890625\n",
      "953 1.0 0.84375\n",
      "954 1.0 0.875\n",
      "955 1.0 0.875\n",
      "956 1.0 0.90625\n",
      "957 1.0 0.84375\n",
      "958 1.0 0.828125\n",
      "959 1.0 0.75\n",
      "960 1.0 0.890625\n",
      "961 1.0 0.875\n",
      "962 1.0 0.921875\n",
      "963 1.0 0.796875\n",
      "964 1.0 0.875\n",
      "965 1.0 0.90625\n",
      "966 1.0 0.921875\n",
      "967 1.0 0.796875\n",
      "968 1.0 0.875\n",
      "969 1.0 0.921875\n",
      "970 1.0 0.828125\n",
      "971 1.0 0.9375\n",
      "972 1.0 0.890625\n",
      "973 1.0 0.921875\n",
      "974 1.0 0.875\n",
      "975 1.0 0.9375\n",
      "976 1.0 0.90625\n",
      "977 1.0 0.953125\n",
      "978 1.0 0.859375\n",
      "979 1.0 0.828125\n",
      "980 1.0 0.9375\n",
      "981 1.0 0.953125\n",
      "982 1.0 0.90625\n",
      "983 1.0 0.828125\n",
      "984 1.0 0.78125\n",
      "985 1.0 0.90625\n",
      "986 1.0 0.921875\n",
      "987 1.0 0.90625\n",
      "988 1.0 0.921875\n",
      "989 1.0 0.890625\n",
      "990 1.0 0.90625\n",
      "991 1.0 0.890625\n",
      "992 1.0 0.78125\n",
      "993 1.0 0.859375\n",
      "994 1.0 0.765625\n",
      "995 1.0 0.8125\n",
      "996 1.0 0.890625\n",
      "997 1.0 0.890625\n",
      "998 1.0 0.875\n",
      "999 1.0 0.84375\n"
     ]
    }
   ],
   "source": [
    "# define the discriminator model\n",
    "model = define_discriminator()\n",
    "# fit the model\n",
    "train_discriminator(model)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\"*The goal is to train a generator model, not a discriminator model, and that is where the complexity of GANs truly lies.*\" "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# The Generator Model\n",
    "*We will define a small latent space of five dimensions and use the standard approach in the GAN literature of using a Gaussian distribution for each variable in the latent space. We will generate new inputs by drawing random numbers from a standard Gaussian distribution, i.e. mean of zero and a standard deviation of one.*\n",
    "\n",
    "* Specs:\n",
    "> * Single Hidden Layer with 5 nodes\n",
    "> * ReLU activation Function\n",
    "> * He weight initialization\n",
    "> * Output layer will have 2 nodes+ will use linear activation function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# define the generator model unit\n",
    "def define_generator(latent_dim, n_outputs=2):\n",
    "\tmodel = Sequential()\n",
    "\tmodel.add(Dense(15, activation='relu', kernel_initializer='he_uniform', input_dim=latent_dim))\n",
    "\tmodel.add(Dense(n_outputs, activation='linear'))\n",
    "\treturn model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"sequential_3\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "dense_5 (Dense)              (None, 15)                90        \n",
      "_________________________________________________________________\n",
      "dense_6 (Dense)              (None, 2)                 32        \n",
      "=================================================================\n",
      "Total params: 122\n",
      "Trainable params: 122\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "# define the discriminator model\n",
    "model = define_generator(5)\n",
    "# summarize the model\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# generate points in latent space as input for the generator\n",
    "def generate_latent_points(latent_dim, n):\n",
    "\t# generate points in the latent space\n",
    "\tx_input = np.random.randn(latent_dim * n)\n",
    "\t# reshape into a batch of inputs for the network\n",
    "\tx_input = x_input.reshape(n, latent_dim)\n",
    "\treturn x_input"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# use the generator to generate n fake examples and plot the results\n",
    "def generate_fake_samples(generator, latent_dim, n):\n",
    "\t# generate points in latent space\n",
    "\tx_input = generate_latent_points(latent_dim, n)\n",
    "\t# predict outputs\n",
    "\tX = generator.predict(x_input)\n",
    "    # create class labels\n",
    "\ty = np.zeros((n, 1))\n",
    "\treturn X, y"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*When the discriminator is good at detecting fake samples, the generator is updated more, and when the discriminator model is relatively poor or confused when detecting fake samples, the generator model is updated less.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# define the combined generator and discriminator model, for updating the generator\n",
    "def define_gan(generator, discriminator):\n",
    "\t# make weights in the discriminator not trainable\n",
    "\tdiscriminator.trainable = False\n",
    "\t# connect them\n",
    "\tmodel = Sequential()\n",
    "\t# add generator\n",
    "\tmodel.add(generator)\n",
    "\t# add the discriminator\n",
    "\tmodel.add(discriminator)\n",
    "\t# compile model\n",
    "\tmodel.compile(loss='binary_crossentropy', optimizer='adam')\n",
    "\treturn model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# train the generator and discriminator\n",
    "def train(g_model, d_model, gan_model, latent_dim, n_epochs=10000, n_batch=128, n_eval=2000):\n",
    "\t# determine half the size of one batch, for updating the discriminator\n",
    "\thalf_batch = int(n_batch / 2)\n",
    "\t# manually enumerate epochs\n",
    "\tfor i in range(n_epochs):\n",
    "\t\t# prepare real samples\n",
    "\t\tx_real, y_real = generate_real_samples(half_batch)\n",
    "\t\t# prepare fake examples\n",
    "\t\tx_fake, y_fake = generate_fake_samples(g_model, latent_dim, half_batch)\n",
    "\t\t# update discriminator\n",
    "\t\td_model.train_on_batch(x_real, y_real)\n",
    "\t\td_model.train_on_batch(x_fake, y_fake)\n",
    "\t\t# prepare points in latent space as input for the generator\n",
    "\t\tx_gan = generate_latent_points(latent_dim, n_batch)\n",
    "\t\t# create inverted labels for the fake samples\n",
    "\t\ty_gan = np.ones((n_batch, 1))\n",
    "\t\t# update the generator via the discriminator's error\n",
    "\t\tgan_model.train_on_batch(x_gan, y_gan)\n",
    "\t\t# evaluate the model every n_eval epochs\n",
    "\t\tif (i+1) % n_eval == 0:\n",
    "\t\t\tsummarize_performance(i, g_model, d_model, latent_dim)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# evaluate the discriminator and plot real and fake points\n",
    "def summarize_performance(epoch, generator, discriminator, latent_dim, n=100):\n",
    "\t# prepare real samples\n",
    "\tx_real, y_real = generate_real_samples(n)\n",
    "\t# evaluate discriminator on real examples\n",
    "\t_, acc_real = discriminator.evaluate(x_real, y_real, verbose=0)\n",
    "\t# prepare fake examples\n",
    "\tx_fake, y_fake = generate_fake_samples(generator, latent_dim, n)\n",
    "\t# evaluate discriminator on fake examples\n",
    "\t_, acc_fake = discriminator.evaluate(x_fake, y_fake, verbose=0)\n",
    "\t# summarize discriminator performance\n",
    "\tprint(epoch, acc_real, acc_fake)\n",
    "\t# scatter plot real and fake data points\n",
    "\tpyplot.scatter(x_real[:, 0], x_real[:, 1], color='red')\n",
    "\tpyplot.scatter(x_fake[:, 0], x_fake[:, 1], color='blue')\n",
    "\tpyplot.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1999 0.7400000095367432 0.4399999976158142\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAfi0lEQVR4nO3df4wcZ53n8fd3xp6Qdthd0rZYiDPdZpXVytye4JiLTsfp9kesJXBSggS7F6fNml8xOBvWEne6zWZO6JTT5A5WYjW6g4SB82IyjQOb0+p8t0YRcUBaWOAyuQuwAQVMPOMkyxHHYSHOkDie+d4fVT1T3V01XT3TXV1d/XlJremuqu56XO7+9NNPPc9T5u6IiMjwGxt0AUREpDcU6CIiBaFAFxEpCAW6iEhBKNBFRApi26B2vHPnTq9Wq4PavYjIUHrkkUeedfddcesGFujVapWFhYVB7V5EZCiZ2VLSOjW5iIgUhAJdRKQgFOgiIgWhQBcRKQgFuohIQSjQRUQKQoEuIlIQQxno9TpUqzA2Fvyt1wddIhGRwRvYwKLNqtfh0CFYXg4eLy0FjwFqtcGVS0Rk0Iauhj49vR7mDcvLwXIRkVE2dIF+9m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PYRfLn+lru/1Fie8D7JImQ6ltvdz0cefobgXEzjub/d8tyv9ryE7br5P74J+KPoggEe61hFbHI5ATTOkB8E/scG27a1h4Xh1Gibfjvwd30oY6uOZTazVzWaJcxsJ/Bm4HsenJn5CsG5gMTn90GaMk8AfwV8zt3vb1mX1XF+GLjGgp5AEwQfytbeCNF/yzuBh8LjegK4KewFswe4BvjffSpnV2U2szcCnwJucPdnIstj3ycZlDltuV8TeXgD8P3w/gPA74XlfxXwezT/ch5YmQHM7DcITtZ+I7JskMc63qDPyvb6RtD2eQr4IfAgcGW4fAr4TGS7KsE38VjL8x8CvksQMPPAFXkoM/DPw3J9O/z7vsjzX0cQNKeBvwQuy0mZDwAvA49Gbm/I+jgDbwN+QFBzmg6X3UkQhgCvCI/b6fA4vi7y3OnweY8Db83wfdypzA8CP4kc1xOd3ic5Kfd/Ah4Ly/cV4Dciz31v+H9wGnhPXsocPv4PwH9ued5Aj3XcTUP/RUQKoohNLiIiI0mBLiJSEAp0EZGCUKCLiBSEAl1EpCAU6CIiBaFAFxEpiP8Ptu7cvVG/7NEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# size of the latent space\n",
    "latent_dim = 5\n",
    "# create the discriminator\n",
    "discriminator = define_discriminator()\n",
    "# create the generator\n",
    "generator = define_generator(latent_dim)\n",
    "# create the gan\n",
    "gan_model = define_gan(generator, discriminator)\n",
    "# train model\n",
    "train(generator, discriminator, gan_model, latent_dim)"
   ]
  },
  {
   "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.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
关于这个算法

G.A.N

Generative Adversial Network:

  • The main focus for GAN is to generate data from scratch.
  • It brings us closer to understanding intelligence.
  • It trains two deep networks, called Generator and Discriminator, that compete and cooperate with each other. In the course of training, both networks eventually learn how to perform their tasks.
    • The generator never actually sees examples from the domain and is adapted based on how well the discriminator performs.
# The Import Statements:
from matplotlib import pyplot
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
from keras.utils.vis_utils import plot_model
Using TensorFlow backend.

Defining a 1 D function:

y=f(x)

def function_1D(x):
    return x*x
inputs=np.arange(-0.5,0.6,0.1)
outputs=[function_1D(x) for x in inputs]
# plot the result
pyplot.plot(inputs, outputs)
pyplot.show()
#Defining random values
def generate_samples(n=100):
    x1=np.random.rand(n)-0.5
    x2=x1*x1
    x1=x1.reshape(n,1)
    x2=x2.reshape(n,1)
    return np.hstack((x1,x2))
# generate samples and plotting them
data = generate_samples()

pyplot.scatter(data[:, 0], data[:, 1])
pyplot.show()

Note:

a sample is comprised of a vector with two elements, one for the input and one for the output of our one-dimensional function.

The Discriminator

  • The difference from a typical CNN is the absence of max-pooling in between layers.
  • will have 1 hidden layer with 25 nodes.
  • will use the ReLU activation function
  • The output layer will have 1 node for the binary classification using the sigmoid activation function.
  • Loss Function: Binary Cross Entropy
  • Optimizer : Adam version of stochastic Gradient Descent
#Code for the Discriminator Unit:
def define_discriminator(n_inputs=2):
	model = Sequential()
	model.add(Dense(25, activation='relu', kernel_initializer='he_uniform', input_dim=n_inputs))
	model.add(Dense(1, activation='sigmoid'))
	# compile model
	model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
	return model
# define the discriminator model
model = define_discriminator()
# summarize the model
model.summary()
Model: &quot;sequential_1&quot;
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_1 (Dense)              (None, 25)                75        
_________________________________________________________________
dense_2 (Dense)              (None, 1)                 26        
=================================================================
Total params: 101
Trainable params: 101
Non-trainable params: 0
_________________________________________________________________
def generate_real_samples(n):
    x1=np.random.rand(n)-0.5
    x2=x1*x1
    x1=x1.reshape(n,1)
    x2=x2.reshape(n,1)
    X= np.hstack((x1,x2))
    y=np.ones((n,1))
    return X,y
def generate_fake_samples(n):
	# generate inputs in [-1, 1]
	X1 = -1 + np.random.rand(n) * 2
	# generate outputs in [-1, 1]
	X2 = -1 + np.random.rand(n) * 2
	# stack arrays
	X1 = X1.reshape(n, 1)
	X2 = X2.reshape(n, 1)
	X = np.hstack((X1, X2))
	# generate class labels
	y = np.zeros((n, 1))
	return X, y
#training the discriminator model
def train_discriminator(model, n_epochs=1000, n_batch=128):
	half_batch = int(n_batch / 2)
	# run epochs manually
	for i in range(n_epochs):
		# generate real examples
		X_real, y_real = generate_real_samples(half_batch)
		# update model
		model.train_on_batch(X_real, y_real)
		# generate fake examples
		X_fake, y_fake = generate_fake_samples(half_batch)
		# update model
		model.train_on_batch(X_fake, y_fake)
		# evaluate the model
		_, acc_real = model.evaluate(X_real, y_real, verbose=0)
		_, acc_fake = model.evaluate(X_fake, y_fake, verbose=0)
		print(i, acc_real, acc_fake)
# define the discriminator model
model = define_discriminator()
# fit the model
train_discriminator(model)
0 0.5 0.15625
1 0.546875 0.25
2 0.578125 0.21875
3 0.5625 0.21875
4 0.640625 0.234375
5 0.515625 0.40625
6 0.515625 0.46875
7 0.59375 0.390625
8 0.5625 0.46875
9 0.53125 0.4375
10 0.46875 0.484375
11 0.421875 0.53125
12 0.46875 0.484375
13 0.515625 0.5625
14 0.46875 0.6875
15 0.5625 0.515625
16 0.515625 0.53125
17 0.53125 0.5
18 0.484375 0.609375
19 0.40625 0.5
20 0.46875 0.671875
21 0.484375 0.59375
22 0.546875 0.609375
23 0.375 0.53125
24 0.421875 0.53125
25 0.34375 0.65625
26 0.421875 0.484375
27 0.421875 0.578125
28 0.328125 0.546875
29 0.359375 0.640625
30 0.4375 0.609375
31 0.296875 0.484375
32 0.296875 0.53125
33 0.515625 0.625
34 0.359375 0.59375
35 0.40625 0.65625
36 0.359375 0.6875
37 0.28125 0.578125
38 0.328125 0.578125
39 0.328125 0.671875
40 0.40625 0.671875
41 0.296875 0.515625
42 0.296875 0.578125
43 0.296875 0.625
44 0.34375 0.625
45 0.390625 0.671875
46 0.375 0.609375
47 0.34375 0.59375
48 0.359375 0.578125
49 0.359375 0.6875
50 0.34375 0.65625
51 0.375 0.515625
52 0.390625 0.609375
53 0.234375 0.625
54 0.359375 0.625
55 0.234375 0.59375
56 0.40625 0.6875
57 0.34375 0.765625
58 0.296875 0.609375
59 0.265625 0.59375
60 0.25 0.65625
61 0.390625 0.65625
62 0.265625 0.65625
63 0.46875 0.703125
64 0.40625 0.59375
65 0.359375 0.625
66 0.28125 0.625
67 0.3125 0.625
68 0.328125 0.640625
69 0.390625 0.625
70 0.28125 0.640625
71 0.328125 0.609375
72 0.296875 0.59375
73 0.125 0.703125
74 0.359375 0.765625
75 0.359375 0.65625
76 0.34375 0.5625
77 0.234375 0.671875
78 0.34375 0.6875
79 0.21875 0.734375
80 0.3125 0.78125
81 0.28125 0.6875
82 0.34375 0.640625
83 0.375 0.765625
84 0.34375 0.640625
85 0.328125 0.703125
86 0.21875 0.75
87 0.25 0.65625
88 0.28125 0.640625
89 0.3125 0.78125
90 0.234375 0.71875
91 0.328125 0.71875
92 0.25 0.671875
93 0.25 0.703125
94 0.265625 0.546875
95 0.296875 0.546875
96 0.328125 0.625
97 0.265625 0.75
98 0.296875 0.671875
99 0.265625 0.703125
100 0.15625 0.734375
101 0.234375 0.796875
102 0.25 0.71875
103 0.21875 0.828125
104 0.21875 0.828125
105 0.328125 0.765625
106 0.21875 0.671875
107 0.28125 0.84375
108 0.21875 0.796875
109 0.21875 0.78125
110 0.25 0.65625
111 0.25 0.8125
112 0.21875 0.859375
113 0.28125 0.796875
114 0.234375 0.625
115 0.21875 0.671875
116 0.234375 0.859375
117 0.265625 0.71875
118 0.21875 0.765625
119 0.234375 0.765625
120 0.234375 0.6875
121 0.234375 0.8125
122 0.296875 0.828125
123 0.25 0.796875
124 0.234375 0.890625
125 0.359375 0.765625
126 0.203125 0.75
127 0.328125 0.703125
128 0.203125 0.78125
129 0.265625 0.796875
130 0.3125 0.828125
131 0.21875 0.828125
132 0.25 0.828125
133 0.296875 0.84375
134 0.203125 0.875
135 0.34375 0.734375
136 0.421875 0.765625
137 0.15625 0.796875
138 0.359375 0.75
139 0.234375 0.75
140 0.421875 0.71875
141 0.28125 0.703125
142 0.1875 0.6875
143 0.21875 0.828125
144 0.25 0.890625
145 0.265625 0.9375
146 0.171875 0.8125
147 0.265625 0.84375
148 0.296875 0.90625
149 0.171875 0.875
150 0.21875 0.765625
151 0.25 0.875
152 0.25 0.90625
153 0.25 0.90625
154 0.328125 0.796875
155 0.296875 0.921875
156 0.234375 0.84375
157 0.25 0.875
158 0.1875 0.9375
159 0.234375 0.859375
160 0.234375 0.890625
161 0.28125 0.984375
162 0.21875 0.90625
163 0.21875 0.90625
164 0.265625 0.953125
165 0.28125 0.953125
166 0.328125 0.984375
167 0.28125 0.96875
168 0.25 0.953125
169 0.359375 0.921875
170 0.34375 1.0
171 0.328125 0.953125
172 0.296875 0.96875
173 0.359375 0.921875
174 0.28125 0.9375
175 0.375 0.984375
176 0.359375 0.96875
177 0.265625 0.984375
178 0.21875 0.96875
179 0.28125 0.9375
180 0.359375 1.0
181 0.34375 0.984375
182 0.40625 0.984375
183 0.296875 0.953125
184 0.34375 0.984375
185 0.3125 0.984375
186 0.359375 0.96875
187 0.375 0.984375
188 0.53125 0.953125
189 0.40625 0.921875
190 0.453125 0.953125
191 0.375 0.96875
192 0.609375 0.9375
193 0.40625 0.96875
194 0.4375 0.96875
195 0.390625 0.96875
196 0.40625 0.984375
197 0.4375 1.0
198 0.546875 0.953125
199 0.328125 1.0
200 0.328125 0.984375
201 0.328125 0.984375
202 0.453125 0.96875
203 0.34375 0.96875
204 0.34375 0.984375
205 0.359375 0.96875
206 0.359375 0.984375
207 0.421875 0.96875
208 0.5 0.984375
209 0.40625 1.0
210 0.390625 0.96875
211 0.546875 0.96875
212 0.390625 0.984375
213 0.5 0.921875
214 0.578125 0.96875
215 0.671875 0.9375
216 0.484375 0.984375
217 0.4375 0.90625
218 0.453125 0.96875
219 0.421875 0.953125
220 0.625 0.9375
221 0.5 0.953125
222 0.578125 0.984375
223 0.53125 0.9375
224 0.5625 0.984375
225 0.546875 0.984375
226 0.5625 0.96875
227 0.578125 0.984375
228 0.5625 0.953125
229 0.546875 0.90625
230 0.546875 0.921875
231 0.75 1.0
232 0.546875 1.0
233 0.671875 1.0
234 0.5625 0.96875
235 0.640625 0.984375
236 0.6875 0.921875
237 0.59375 0.90625
238 0.71875 0.921875
239 0.609375 1.0
240 0.59375 0.953125
241 0.65625 0.953125
242 0.640625 0.984375
243 0.6875 0.984375
244 0.546875 0.9375
245 0.71875 1.0
246 0.71875 0.953125
247 0.609375 1.0
248 0.671875 0.96875
249 0.625 0.953125
250 0.53125 0.921875
251 0.6875 0.984375
252 0.625 0.921875
253 0.65625 0.984375
254 0.625 0.9375
255 0.75 0.96875
256 0.609375 0.984375
257 0.640625 0.921875
258 0.6875 0.984375
259 0.671875 1.0
260 0.625 0.9375
261 0.65625 0.984375
262 0.703125 0.96875
263 0.734375 1.0
264 0.65625 0.984375
265 0.578125 0.9375
266 0.59375 0.96875
267 0.703125 0.921875
268 0.734375 1.0
269 0.734375 1.0
270 0.703125 0.984375
271 0.734375 0.984375
272 0.6875 0.953125
273 0.703125 0.96875
274 0.71875 1.0
275 0.65625 0.953125
276 0.75 0.921875
277 0.609375 0.984375
278 0.6875 1.0
279 0.6875 0.953125
280 0.765625 1.0
281 0.796875 1.0
282 0.734375 0.96875
283 0.671875 0.984375
284 0.578125 1.0
285 0.671875 0.953125
286 0.671875 0.984375
287 0.75 0.9375
288 0.734375 0.984375
289 0.71875 0.96875
290 0.75 0.96875
291 0.6875 0.984375
292 0.65625 0.9375
293 0.734375 0.984375
294 0.65625 0.953125
295 0.703125 0.96875
296 0.6875 0.984375
297 0.71875 0.984375
298 0.734375 0.953125
299 0.71875 0.9375
300 0.734375 0.984375
301 0.78125 0.953125
302 0.75 0.9375
303 0.75 0.953125
304 0.796875 0.96875
305 0.734375 1.0
306 0.71875 0.921875
307 0.796875 0.953125
308 0.84375 0.96875
309 0.75 0.96875
310 0.71875 1.0
311 0.828125 0.96875
312 0.8125 0.984375
313 0.78125 0.9375
314 0.84375 0.96875
315 0.6875 0.984375
316 0.84375 0.953125
317 0.8125 0.984375
318 0.765625 0.9375
319 0.71875 0.9375
320 0.703125 0.9375
321 0.671875 0.96875
322 0.703125 0.921875
323 0.765625 0.96875
324 0.703125 0.953125
325 0.828125 0.96875
326 0.828125 0.96875
327 0.78125 0.984375
328 0.8125 0.953125
329 0.796875 0.984375
330 0.765625 0.9375
331 0.890625 0.90625
332 0.8125 0.90625
333 0.8125 1.0
334 0.78125 0.96875
335 0.875 0.96875
336 0.84375 0.984375
337 0.796875 1.0
338 0.8125 0.984375
339 0.78125 0.9375
340 0.875 0.953125
341 0.8125 0.921875
342 0.796875 0.90625
343 0.796875 0.953125
344 0.8125 0.984375
345 0.890625 0.9375
346 0.828125 0.9375
347 0.78125 0.96875
348 0.90625 0.953125
349 0.828125 0.96875
350 0.796875 0.953125
351 0.734375 0.921875
352 0.796875 0.984375
353 0.765625 0.921875
354 0.8125 0.90625
355 0.765625 0.96875
356 0.84375 0.96875
357 0.875 0.953125
358 0.8125 0.90625
359 0.828125 0.96875
360 0.828125 0.953125
361 0.84375 0.984375
362 0.859375 0.9375
363 0.859375 0.953125
364 0.859375 0.9375
365 0.875 0.96875
366 0.875 0.953125
367 0.8125 0.953125
368 0.90625 0.9375
369 0.875 0.984375
370 0.9375 0.890625
371 0.875 0.9375
372 0.796875 0.921875
373 0.828125 0.921875
374 0.90625 0.921875
375 0.8125 0.9375
376 0.8125 0.90625
377 0.90625 0.921875
378 0.765625 1.0
379 0.78125 0.953125
380 0.78125 0.953125
381 0.875 0.953125
382 0.875 0.9375
383 0.84375 0.890625
384 0.796875 0.9375
385 0.859375 0.96875
386 0.8125 0.96875
387 0.90625 0.953125
388 0.921875 0.9375
389 0.890625 0.953125
390 0.96875 0.921875
391 0.84375 0.875
392 0.875 0.921875
393 0.828125 0.9375
394 0.921875 0.9375
395 0.890625 0.9375
396 0.921875 0.921875
397 0.890625 1.0
398 0.875 0.984375
399 0.921875 0.9375
400 0.828125 0.953125
401 0.828125 0.90625
402 0.9375 0.953125
403 0.8125 0.890625
404 0.953125 0.953125
405 0.9375 0.890625
406 0.90625 0.96875
407 0.890625 0.984375
408 0.875 0.9375
409 0.921875 0.984375
410 0.859375 0.96875
411 0.890625 0.953125
412 0.921875 0.96875
413 0.921875 1.0
414 0.921875 0.96875
415 0.875 0.90625
416 0.96875 0.96875
417 0.890625 0.921875
418 0.90625 0.953125
419 0.875 0.9375
420 0.875 0.921875
421 0.96875 0.953125
422 0.921875 0.96875
423 0.890625 0.875
424 0.84375 0.90625
425 0.921875 0.984375
426 0.953125 0.890625
427 1.0 0.90625
428 0.890625 0.9375
429 0.921875 0.9375
430 0.9375 0.953125
431 0.96875 0.953125
432 0.90625 0.9375
433 0.953125 0.875
434 0.953125 0.890625
435 0.96875 0.90625
436 0.9375 0.953125
437 0.96875 0.953125
438 0.953125 0.890625
439 0.921875 0.953125
440 0.953125 0.90625
441 0.90625 0.984375
442 0.96875 0.96875
443 0.984375 0.9375
444 0.921875 0.9375
445 0.96875 0.90625
446 0.921875 0.96875
447 0.890625 0.875
448 0.953125 0.953125
449 0.984375 0.953125
450 0.921875 0.953125
451 1.0 0.90625
452 0.984375 0.96875
453 1.0 0.90625
454 0.953125 0.953125
455 0.96875 0.9375
456 0.953125 0.90625
457 1.0 0.921875
458 0.984375 0.96875
459 0.984375 0.90625
460 0.984375 0.984375
461 1.0 0.921875
462 0.984375 0.953125
463 0.96875 0.921875
464 1.0 0.921875
465 0.984375 0.859375
466 1.0 0.90625
467 1.0 0.890625
468 1.0 0.90625
469 1.0 0.875
470 1.0 0.84375
471 1.0 0.875
472 0.984375 0.859375
473 1.0 0.859375
474 1.0 0.921875
475 0.984375 0.96875
476 1.0 0.875
477 1.0 0.890625
478 1.0 0.921875
479 1.0 0.890625
480 1.0 0.953125
481 1.0 0.90625
482 1.0 0.890625
483 1.0 0.90625
484 1.0 0.90625
485 1.0 0.890625
486 1.0 0.921875
487 1.0 0.96875
488 1.0 0.9375
489 1.0 0.921875
490 1.0 0.890625
491 1.0 0.890625
492 1.0 0.9375
493 1.0 0.90625
494 0.984375 0.9375
495 1.0 0.875
496 1.0 0.890625
497 1.0 0.9375
498 1.0 0.921875
499 0.984375 0.921875
500 1.0 0.921875
501 1.0 0.875
502 1.0 0.90625
503 1.0 0.953125
504 1.0 0.921875
505 1.0 0.96875
506 1.0 0.953125
507 1.0 0.921875
508 1.0 0.921875
509 1.0 0.890625
510 1.0 0.96875
511 1.0 0.921875
512 1.0 0.921875
513 1.0 0.859375
514 1.0 0.875
515 1.0 0.921875
516 1.0 0.9375
517 1.0 0.890625
518 1.0 0.90625
519 1.0 0.875
520 1.0 0.90625
521 1.0 0.9375
522 1.0 0.921875
523 1.0 0.875
524 1.0 0.875
525 1.0 0.921875
526 1.0 0.953125
527 1.0 0.90625
528 1.0 0.90625
529 1.0 0.90625
530 1.0 0.890625
531 1.0 0.90625
532 1.0 0.921875
533 1.0 0.921875
534 1.0 0.953125
535 1.0 0.875
536 1.0 0.90625
537 1.0 0.859375
538 1.0 0.890625
539 1.0 0.9375
540 1.0 0.9375
541 1.0 0.953125
542 1.0 0.890625
543 1.0 0.90625
544 1.0 0.84375
545 1.0 0.890625
546 1.0 0.890625
547 1.0 0.953125
548 1.0 0.9375
549 1.0 0.9375
550 1.0 0.890625
551 1.0 0.96875
552 1.0 0.921875
553 1.0 0.890625
554 1.0 0.90625
555 1.0 0.96875
556 1.0 0.921875
557 1.0 0.953125
558 1.0 0.890625
559 1.0 0.9375
560 1.0 0.9375
561 1.0 0.90625
562 1.0 0.9375
563 1.0 0.953125
564 1.0 0.875
565 1.0 0.90625
566 1.0 0.859375
567 1.0 0.875
568 1.0 0.921875
569 1.0 0.84375
570 1.0 0.890625
571 1.0 0.890625
572 1.0 0.953125
573 1.0 0.90625
574 1.0 0.921875
575 1.0 0.921875
576 1.0 0.921875
577 1.0 0.859375
578 1.0 0.9375
579 1.0 0.953125
580 1.0 0.921875
581 1.0 0.875
582 1.0 0.875
583 1.0 0.875
584 1.0 0.921875
585 1.0 0.890625
586 1.0 0.890625
587 1.0 0.890625
588 1.0 0.90625
589 1.0 0.875
590 1.0 0.90625
591 1.0 0.859375
592 1.0 0.90625
593 1.0 0.84375
594 1.0 0.859375
595 1.0 0.890625
596 1.0 0.90625
597 1.0 0.875
598 1.0 0.953125
599 1.0 0.875
600 1.0 0.859375
601 1.0 0.9375
602 1.0 0.875
603 1.0 0.859375
604 1.0 0.90625
605 1.0 0.90625
606 1.0 0.78125
607 1.0 0.828125
608 1.0 0.9375
609 1.0 0.921875
610 1.0 0.90625
611 1.0 0.953125
612 1.0 0.890625
613 1.0 0.9375
614 1.0 0.921875
615 1.0 0.796875
616 1.0 0.890625
617 1.0 0.921875
618 1.0 0.90625
619 1.0 0.890625
620 1.0 0.859375
621 1.0 0.921875
622 1.0 0.828125
623 1.0 0.875
624 1.0 0.953125
625 1.0 0.84375
626 1.0 0.9375
627 1.0 0.9375
628 1.0 0.859375
629 1.0 0.9375
630 1.0 0.90625
631 1.0 0.9375
632 1.0 0.921875
633 1.0 0.90625
634 1.0 0.90625
635 1.0 0.890625
636 1.0 0.78125
637 1.0 0.90625
638 1.0 0.890625
639 1.0 0.921875
640 1.0 0.75
641 1.0 0.875
642 1.0 0.875
643 1.0 0.90625
644 1.0 0.953125
645 1.0 0.921875
646 1.0 0.890625
647 1.0 0.859375
648 1.0 0.84375
649 1.0 0.90625
650 1.0 0.84375
651 1.0 0.84375
652 1.0 0.921875
653 1.0 0.90625
654 1.0 0.921875
655 1.0 0.921875
656 1.0 0.921875
657 1.0 0.84375
658 1.0 0.84375
659 1.0 0.90625
660 1.0 0.953125
661 1.0 0.890625
662 1.0 0.875
663 1.0 0.84375
664 1.0 0.84375
665 1.0 0.8125
666 1.0 0.859375
667 1.0 0.90625
668 1.0 0.90625
669 1.0 0.875
670 1.0 0.921875
671 1.0 0.84375
672 1.0 0.953125
673 1.0 0.84375
674 1.0 0.8125
675 1.0 0.84375
676 1.0 0.921875
677 1.0 0.953125
678 1.0 0.84375
679 1.0 0.859375
680 1.0 0.859375
681 1.0 0.90625
682 1.0 0.90625
683 1.0 0.90625
684 1.0 0.828125
685 1.0 0.875
686 1.0 0.9375
687 1.0 0.859375
688 1.0 0.859375
689 1.0 0.84375
690 1.0 0.953125
691 1.0 0.84375
692 1.0 0.859375
693 1.0 0.9375
694 1.0 0.890625
695 1.0 0.859375
696 1.0 0.875
697 1.0 0.875
698 1.0 0.9375
699 1.0 0.890625
700 1.0 0.921875
701 1.0 0.828125
702 1.0 0.84375
703 1.0 0.90625
704 1.0 0.859375
705 1.0 0.90625
706 1.0 0.921875
707 1.0 0.9375
708 1.0 0.84375
709 1.0 0.875
710 1.0 0.90625
711 1.0 0.90625
712 1.0 0.890625
713 1.0 0.921875
714 1.0 0.90625
715 1.0 0.890625
716 1.0 0.8125
717 1.0 0.875
718 1.0 0.890625
719 1.0 0.890625
720 1.0 0.90625
721 1.0 0.875
722 1.0 0.84375
723 1.0 0.9375
724 1.0 0.90625
725 1.0 0.84375
726 1.0 0.9375
727 1.0 0.875
728 1.0 0.8125
729 1.0 0.84375
730 1.0 0.9375
731 1.0 0.84375
732 1.0 0.875
733 1.0 0.921875
734 1.0 0.78125
735 1.0 0.78125
736 1.0 0.859375
737 1.0 0.84375
738 1.0 0.90625
739 1.0 0.859375
740 1.0 0.875
741 1.0 0.859375
742 1.0 0.890625
743 1.0 0.875
744 1.0 0.890625
745 1.0 0.859375
746 1.0 0.8125
747 1.0 0.859375
748 1.0 0.953125
749 1.0 0.84375
750 1.0 0.890625
751 1.0 0.796875
752 1.0 0.890625
753 1.0 0.796875
754 1.0 0.84375
755 1.0 0.890625
756 1.0 0.875
757 1.0 0.890625
758 1.0 0.921875
759 1.0 0.84375
760 1.0 0.875
761 1.0 0.859375
762 1.0 0.953125
763 1.0 0.890625
764 1.0 0.859375
765 1.0 0.84375
766 1.0 0.828125
767 1.0 0.8125
768 1.0 0.84375
769 1.0 0.859375
770 1.0 0.875
771 1.0 0.890625
772 1.0 0.90625
773 1.0 0.90625
774 1.0 0.953125
775 1.0 0.90625
776 1.0 0.890625
777 1.0 0.890625
778 1.0 0.921875
779 1.0 0.90625
780 1.0 0.90625
781 1.0 0.90625
782 1.0 0.796875
783 1.0 0.765625
784 1.0 0.921875
785 1.0 0.875
786 1.0 0.890625
787 1.0 0.90625
788 1.0 0.90625
789 1.0 0.890625
790 1.0 0.859375
791 1.0 0.890625
792 1.0 0.875
793 1.0 0.796875
794 1.0 0.859375
795 1.0 0.828125
796 1.0 0.890625
797 1.0 0.875
798 1.0 0.890625
799 1.0 0.8125
800 1.0 0.875
801 1.0 0.921875
802 1.0 0.90625
803 1.0 0.890625
804 1.0 0.90625
805 1.0 0.890625
806 1.0 0.90625
807 1.0 0.9375
808 1.0 0.90625
809 1.0 0.90625
810 1.0 0.859375
811 1.0 0.859375
812 1.0 0.890625
813 1.0 0.875
814 1.0 0.8125
815 1.0 0.875
816 1.0 0.921875
817 1.0 0.9375
818 1.0 0.890625
819 1.0 0.90625
820 1.0 0.921875
821 1.0 0.875
822 1.0 0.9375
823 1.0 0.90625
824 1.0 0.875
825 1.0 0.84375
826 1.0 0.875
827 1.0 0.8125
828 1.0 0.8125
829 1.0 0.890625
830 1.0 0.78125
831 1.0 0.890625
832 1.0 0.890625
833 1.0 0.84375
834 1.0 0.859375
835 1.0 0.875
836 1.0 0.890625
837 1.0 0.9375
838 1.0 0.953125
839 1.0 0.875
840 1.0 0.890625
841 1.0 0.78125
842 1.0 0.921875
843 1.0 0.875
844 1.0 0.84375
845 1.0 0.859375
846 1.0 0.828125
847 1.0 0.8125
848 1.0 0.921875
849 1.0 0.890625
850 1.0 0.84375
851 1.0 0.96875
852 1.0 0.90625
853 1.0 0.9375
854 1.0 0.875
855 1.0 0.890625
856 1.0 0.859375
857 1.0 0.890625
858 1.0 0.8125
859 1.0 0.875
860 1.0 0.875
861 1.0 0.875
862 1.0 0.859375
863 1.0 0.875
864 1.0 0.9375
865 1.0 0.796875
866 1.0 0.84375
867 1.0 0.90625
868 1.0 0.875
869 1.0 0.890625
870 1.0 0.953125
871 1.0 0.890625
872 1.0 0.90625
873 1.0 0.828125
874 1.0 0.96875
875 1.0 0.90625
876 1.0 0.84375
877 1.0 0.765625
878 1.0 0.96875
879 1.0 0.890625
880 1.0 0.890625
881 1.0 0.84375
882 1.0 0.890625
883 1.0 0.84375
884 1.0 0.859375
885 1.0 0.84375
886 1.0 0.859375
887 1.0 0.875
888 1.0 0.921875
889 1.0 0.90625
890 1.0 0.90625
891 1.0 0.859375
892 1.0 0.859375
893 1.0 0.9375
894 1.0 0.84375
895 1.0 0.859375
896 1.0 0.90625
897 1.0 0.9375
898 1.0 0.84375
899 1.0 0.890625
900 1.0 0.828125
901 1.0 0.90625
902 1.0 0.90625
903 1.0 0.859375
904 1.0 0.875
905 1.0 0.84375
906 1.0 0.875
907 1.0 0.875
908 1.0 0.859375
909 1.0 0.875
910 1.0 0.9375
911 1.0 0.796875
912 1.0 0.90625
913 1.0 0.859375
914 1.0 0.9375
915 1.0 0.875
916 1.0 0.859375
917 1.0 0.890625
918 1.0 0.890625
919 1.0 0.875
920 1.0 0.953125
921 1.0 0.921875
922 1.0 0.921875
923 1.0 0.890625
924 1.0 0.9375
925 1.0 0.859375
926 1.0 0.90625
927 1.0 0.921875
928 1.0 0.859375
929 1.0 0.859375
930 1.0 0.875
931 1.0 0.890625
932 1.0 0.890625
933 1.0 0.859375
934 1.0 0.859375
935 1.0 0.828125
936 1.0 0.96875
937 1.0 0.875
938 1.0 0.75
939 1.0 0.9375
940 1.0 0.828125
941 1.0 0.890625
942 1.0 0.828125
943 1.0 0.859375
944 1.0 0.875
945 1.0 0.921875
946 1.0 0.890625
947 1.0 0.921875
948 1.0 0.9375
949 1.0 0.953125
950 1.0 0.875
951 1.0 0.859375
952 1.0 0.890625
953 1.0 0.84375
954 1.0 0.875
955 1.0 0.875
956 1.0 0.90625
957 1.0 0.84375
958 1.0 0.828125
959 1.0 0.75
960 1.0 0.890625
961 1.0 0.875
962 1.0 0.921875
963 1.0 0.796875
964 1.0 0.875
965 1.0 0.90625
966 1.0 0.921875
967 1.0 0.796875
968 1.0 0.875
969 1.0 0.921875
970 1.0 0.828125
971 1.0 0.9375
972 1.0 0.890625
973 1.0 0.921875
974 1.0 0.875
975 1.0 0.9375
976 1.0 0.90625
977 1.0 0.953125
978 1.0 0.859375
979 1.0 0.828125
980 1.0 0.9375
981 1.0 0.953125
982 1.0 0.90625
983 1.0 0.828125
984 1.0 0.78125
985 1.0 0.90625
986 1.0 0.921875
987 1.0 0.90625
988 1.0 0.921875
989 1.0 0.890625
990 1.0 0.90625
991 1.0 0.890625
992 1.0 0.78125
993 1.0 0.859375
994 1.0 0.765625
995 1.0 0.8125
996 1.0 0.890625
997 1.0 0.890625
998 1.0 0.875
999 1.0 0.84375

"The goal is to train a generator model, not a discriminator model, and that is where the complexity of GANs truly lies."

The Generator Model

We will define a small latent space of five dimensions and use the standard approach in the GAN literature of using a Gaussian distribution for each variable in the latent space. We will generate new inputs by drawing random numbers from a standard Gaussian distribution, i.e. mean of zero and a standard deviation of one.

  • Specs:
    • Single Hidden Layer with 5 nodes
    • ReLU activation Function
    • He weight initialization
    • Output layer will have 2 nodes+ will use linear activation function
# define the generator model unit
def define_generator(latent_dim, n_outputs=2):
	model = Sequential()
	model.add(Dense(15, activation='relu', kernel_initializer='he_uniform', input_dim=latent_dim))
	model.add(Dense(n_outputs, activation='linear'))
	return model
# define the discriminator model
model = define_generator(5)
# summarize the model
model.summary()
Model: &quot;sequential_3&quot;
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_5 (Dense)              (None, 15)                90        
_________________________________________________________________
dense_6 (Dense)              (None, 2)                 32        
=================================================================
Total params: 122
Trainable params: 122
Non-trainable params: 0
_________________________________________________________________
# generate points in latent space as input for the generator
def generate_latent_points(latent_dim, n):
	# generate points in the latent space
	x_input = np.random.randn(latent_dim * n)
	# reshape into a batch of inputs for the network
	x_input = x_input.reshape(n, latent_dim)
	return x_input
# use the generator to generate n fake examples and plot the results
def generate_fake_samples(generator, latent_dim, n):
	# generate points in latent space
	x_input = generate_latent_points(latent_dim, n)
	# predict outputs
	X = generator.predict(x_input)
    # create class labels
	y = np.zeros((n, 1))
	return X, y

When the discriminator is good at detecting fake samples, the generator is updated more, and when the discriminator model is relatively poor or confused when detecting fake samples, the generator model is updated less.

# define the combined generator and discriminator model, for updating the generator
def define_gan(generator, discriminator):
	# make weights in the discriminator not trainable
	discriminator.trainable = False
	# connect them
	model = Sequential()
	# add generator
	model.add(generator)
	# add the discriminator
	model.add(discriminator)
	# compile model
	model.compile(loss='binary_crossentropy', optimizer='adam')
	return model
# train the generator and discriminator
def train(g_model, d_model, gan_model, latent_dim, n_epochs=10000, n_batch=128, n_eval=2000):
	# determine half the size of one batch, for updating the discriminator
	half_batch = int(n_batch / 2)
	# manually enumerate epochs
	for i in range(n_epochs):
		# prepare real samples
		x_real, y_real = generate_real_samples(half_batch)
		# prepare fake examples
		x_fake, y_fake = generate_fake_samples(g_model, latent_dim, half_batch)
		# update discriminator
		d_model.train_on_batch(x_real, y_real)
		d_model.train_on_batch(x_fake, y_fake)
		# prepare points in latent space as input for the generator
		x_gan = generate_latent_points(latent_dim, n_batch)
		# create inverted labels for the fake samples
		y_gan = np.ones((n_batch, 1))
		# update the generator via the discriminator's error
		gan_model.train_on_batch(x_gan, y_gan)
		# evaluate the model every n_eval epochs
		if (i+1) % n_eval == 0:
			summarize_performance(i, g_model, d_model, latent_dim)
# evaluate the discriminator and plot real and fake points
def summarize_performance(epoch, generator, discriminator, latent_dim, n=100):
	# prepare real samples
	x_real, y_real = generate_real_samples(n)
	# evaluate discriminator on real examples
	_, acc_real = discriminator.evaluate(x_real, y_real, verbose=0)
	# prepare fake examples
	x_fake, y_fake = generate_fake_samples(generator, latent_dim, n)
	# evaluate discriminator on fake examples
	_, acc_fake = discriminator.evaluate(x_fake, y_fake, verbose=0)
	# summarize discriminator performance
	print(epoch, acc_real, acc_fake)
	# scatter plot real and fake data points
	pyplot.scatter(x_real[:, 0], x_real[:, 1], color='red')
	pyplot.scatter(x_fake[:, 0], x_fake[:, 1], color='blue')
	pyplot.show()
# size of the latent space
latent_dim = 5
# create the discriminator
discriminator = define_discriminator()
# create the generator
generator = define_generator(latent_dim)
# create the gan
gan_model = define_gan(generator, discriminator)
# train model
train(generator, discriminator, gan_model, latent_dim)
1999 0.7400000095367432 0.4399999976158142