Newer
Older
rnn_bachelor_thesis / 1_to_1_multi_layer.ipynb
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\users\\sa_li\\anaconda3\\envs\\rnn-tf-ker\\lib\\site-packages\\h5py\\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  from ._conv import register_converters as _register_converters\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib as mpl\n",
    "import random\n",
    "import math\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import tensorflow as tf\n",
    "from tensorflow.python.framework import ops\n",
    "from sklearn import preprocessing\n",
    "import pickle as pkl\n",
    "from pathlib import Path\n",
    "\n",
    "#import seaborn as sns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#import data as array\n",
    "# 8 hits with x,y,z\n",
    "\n",
    "testset = pd.read_pickle('matched_8hittracks.pkl')\n",
    "#print(testset)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Check testset with arbitrary particle\n",
    "\n",
    "tset = np.array(testset)\n",
    "tset = tset.astype('float32')\n",
    "#print(tset.shape)\n",
    "#for i in range(8):\n",
    "    #print(tset[1,3*i:(3*i+3)])\n",
    "#print(tset[0,:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Reshape original array into the shape (particlenumber, timesteps, input = coordinates)###\n",
    "\n",
    "def reshapor(arr_orig, num_inputs=3):\n",
    "    timesteps = int(arr_orig.shape[1]/num_inputs)\n",
    "    number_examples = int(arr_orig.shape[0])\n",
    "    arr = np.zeros((number_examples, timesteps, num_inputs))\n",
    "    \n",
    "    for i in range(number_examples):\n",
    "        for t in range(timesteps):\n",
    "            arr[i,t,:] = arr_orig[i,num_inputs*t:num_inputs*t+num_inputs]\n",
    "        \n",
    "    return arr\n",
    "\n",
    "def reshapor_inv(array_shaped, num_inputs=3):\n",
    "    timesteps = int(array_shaped.shape[1])\n",
    "    num_examples = int(array_shaped.shape[0])\n",
    "    arr = np.zeros((num_examples, timesteps*num_inputs))\n",
    "    \n",
    "    for i in range(num_examples):\n",
    "        for t in range(timesteps):\n",
    "            arr[i,num_inputs*t:num_inputs*t+num_inputs] = array_shaped[i,t,:]\n",
    "        \n",
    "    return arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "### create the training set and the test set###\n",
    "\n",
    "def create_random_sets(dataset, train_to_total_ratio):\n",
    "    #shuffle the dataset\n",
    "    num_examples = dataset.shape[0]\n",
    "    p = np.random.permutation(num_examples)\n",
    "    dataset = dataset[p,:]\n",
    "    \n",
    "    #evaluate siye of training and test set and initialize them\n",
    "    train_set_size = np.int(num_examples*train_to_total_ratio)\n",
    "    test_set_size = num_examples - train_set_size\n",
    "    \n",
    "    train_set = np.zeros((train_set_size, dataset.shape[1]))\n",
    "    test_set = np.zeros((test_set_size, dataset.shape[1]))\n",
    "   \n",
    "\n",
    "    #fill train and test sets\n",
    "    for i in range(num_examples):\n",
    "        if train_set_size > i:\n",
    "            train_set[i,:] += dataset[i,:]\n",
    "        else:\n",
    "            test_set[i - train_set_size,:]  += dataset[i,:]\n",
    "                \n",
    "    return train_set, test_set\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_set, test_set = create_random_sets(tset, 0.9)\n",
    "\n",
    "#print(test_set.shape, train_set.shape, reshapor(tset).shape)\n",
    "#print(test_set[0,:,:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Normalize the data advanced version with scikit learn\n",
    "def correct_array_steps(arr, steps= 8, num_inputs= 3): #steps > array_steps\n",
    "        if arr.shape[1] != steps:\n",
    "            _ = np.zeros((arr.shape[0], steps, num_inputs))\n",
    "            _[:,:arr.shape[1],:] += arr\n",
    "            arr = _\n",
    "        return arr\n",
    "\n",
    "\n",
    "#set the transormation based on training set\n",
    "def set_min_max_scaler(arr, feature_range= (-1,1)):\n",
    "    min_max_scalor = preprocessing.MinMaxScaler(feature_range=feature_range)\n",
    "    if len(arr.shape) == 3:\n",
    "        arr = reshapor(min_max_scalor.fit_transform(reshapor_inv(arr)))        \n",
    "    else:\n",
    "        arr = min_max_scalor.fit_transform(arr)\n",
    "    return min_max_scalor\n",
    "\n",
    "min_max_scalor = set_min_max_scaler(train_set)\n",
    "\n",
    "\n",
    "#transform data\n",
    "def min_max_scaler(arr, min_max_scalor= min_max_scalor, num_inputs= 3):\n",
    "    arr = correct_array_steps(arr)\n",
    "    arr = reshapor(min_max_scalor.transform(reshapor_inv(arr)))\n",
    "    return arr\n",
    "        \n",
    "#inverse transformation\n",
    "def min_max_scaler_inv(arr, min_max_scalor= min_max_scalor, num_inputs= 3):\n",
    "    arr = correct_array_steps(arr)\n",
    "    arr = reshapor(min_max_scalor.inverse_transform(reshapor_inv(arr)))\n",
    "    return arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Normalize the data advanced version with scikit learn - Standard scaler\n",
    "\n",
    "#set the transormation based on training set\n",
    "def set_std_scaler(arr):\n",
    "    std_scalor = preprocessing.StandardScaler()\n",
    "    if len(arr.shape) == 3:\n",
    "        arr = reshapor(std_scalor.fit_transform(reshapor_inv(arr)))        \n",
    "    else:\n",
    "        arr = std_scalor.fit_transform(arr)\n",
    "    return std_scalor\n",
    "\n",
    "std_scalor = set_std_scaler(train_set)\n",
    "\n",
    "#transform data\n",
    "def std_scaler(arr, std_scalor= std_scalor, num_inputs=3):\n",
    "    arr = correct_array_steps(arr)\n",
    "    arr = reshapor(std_scalor.transform(reshapor_inv(arr)))\n",
    "    return arr\n",
    "        \n",
    "#inverse transformation\n",
    "def std_scaler_inv(arr, std_scalor= std_scalor, num_inputs=3):\n",
    "    arr = correct_array_steps(arr)\n",
    "    arr = reshapor(std_scalor.inverse_transform(reshapor_inv(arr)))\n",
    "    return arr\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#reshape the data\n",
    "\n",
    "train_set = reshapor(train_set)\n",
    "test_set = reshapor(test_set)\n",
    "\n",
    "#print(train_set[0,:,:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Scale data either with MinMax scaler or with Standard scaler\n",
    "#Return scalor if fit = True and and scaled array otherwise\n",
    "\n",
    "def scaler(arr, std_scalor= std_scalor, min_max_scalor= min_max_scalor, scalerfunc= \"minmax\", scalor = False):\n",
    "    \n",
    "    if scalor != False:\n",
    "        arr = correct_array_steps(arr)\n",
    "        arr = reshapor(scalor.transform(reshapor_inv(arr)))\n",
    "        return arr\n",
    "    \n",
    "    elif scalerfunc == \"std\":\n",
    "        arr = std_scaler(arr, std_scalor= std_scalor)\n",
    "        return arr\n",
    "    \n",
    "    elif scalerfunc == \"minmax\":\n",
    "        arr = min_max_scaler(arr, min_max_scalor= min_max_scalor)\n",
    "        return arr\n",
    "    \n",
    "    else:\n",
    "        raise ValueError(\"Uknown scaler chosen: {}\".format(scalerfunc))\n",
    "\n",
    "def scaler_inv(arr, std_scalor= std_scalor, min_max_scalor= min_max_scalor, scalerfunc= \"std\", scalor = False, num_inputs= 3):\n",
    "\n",
    "    if scalor != False:\n",
    "        arr = correct_array_steps(arr)\n",
    "        arr = reshapor(scalor.inverse_transform(reshapor_inv(arr)))\n",
    "        return arr\n",
    "    \n",
    "    elif scalerfunc == \"std\":\n",
    "        arr = std_scaler_inv(arr, std_scalor= std_scalor)\n",
    "        return arr\n",
    "    \n",
    "    elif scalerfunc == \"minmax\":\n",
    "        arr = min_max_scaler_inv(arr, min_max_scalor= min_max_scalor)\n",
    "        return arr\n",
    "    \n",
    "    else:\n",
    "        raise ValueError(\"Uknown scaler chosen: {}\".format(scalerfunc))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "#scale the data\n",
    "\n",
    "func = \"minmax\"\n",
    "\n",
    "train_set = scaler(train_set, scalerfunc = func)\n",
    "test_set = scaler(test_set, scalerfunc = func)\n",
    "\n",
    "if func == \"minmax\":\n",
    "    scalor = min_max_scalor\n",
    "elif func == \"std\":\n",
    "    scalor = std_scalor\n",
    "\n",
    "#print(train_set[0,:,:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "###create random mini_batches###\n",
    "\n",
    "\n",
    "def unison_shuffled_copies(a, b):\n",
    "    assert a.shape[0] == b.shape[0]\n",
    "    p = np.random.permutation(a.shape[0])\n",
    "    return a[p,:,:], b[p,:,:]\n",
    "\n",
    "def random_mini_batches(inputt, target, minibatch_size = 100):\n",
    "    \n",
    "    num_examples = inputt.shape[0]\n",
    "    \n",
    "    \n",
    "    #Number of complete batches\n",
    "    \n",
    "    number_of_batches = int(num_examples/minibatch_size)\n",
    "    minibatches = []\n",
    "   \n",
    "    #shuffle particles\n",
    "    _i, _t = unison_shuffled_copies(inputt, target)\n",
    "    #print(_t.shape)\n",
    "        \n",
    "    \n",
    "    for i in range(number_of_batches):\n",
    "        \n",
    "        minibatch_train = _i[minibatch_size*i:minibatch_size*(i+1), :, :]\n",
    "        \n",
    "        minibatch_true = _t[minibatch_size*i:minibatch_size*(i+1), :, :]\n",
    "        \n",
    "        minibatches.append((minibatch_train, minibatch_true))\n",
    "        \n",
    "        \n",
    "    minibatches.append((_i[number_of_batches*minibatch_size:, :, :], _t[number_of_batches*minibatch_size:, :, :]))\n",
    "    \n",
    "    \n",
    "    return minibatches\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Create random minibatches of train and test set with input and target array\n",
    "\n",
    "\n",
    "minibatches = random_mini_batches(train_set[:,:-1,:], train_set[:,1:,:], minibatch_size = 1000)\n",
    "#_train, _target = minibatches[0]\n",
    "test_input, test_target = test_set[:,:-1,:], test_set[:,1:,:]\n",
    "#print(train[0,:,:], target[0,:,:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "#minibatches = random_mini_batches(inputt_train, target_train)\n",
    "\n",
    "\n",
    "#_inputt, _target = minibatches[int(inputt_train.shape[0]/500)]\n",
    "\n",
    "#print(len(minibatches))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "class RNNPlacePrediction():\n",
    "    \n",
    "    \n",
    "    def __init__(self, time_steps, future_steps, ninputs, ncells, num_output, cell_type=\"basic_rnn\", activation=\"relu\", scalor= scalor):\n",
    "        \n",
    "        self.nsteps = time_steps\n",
    "        self.future_steps = future_steps\n",
    "        self.ninputs = ninputs\n",
    "        self.ncells = ncells\n",
    "        self.num_output = num_output\n",
    "        self._ = cell_type #later used to create folder name\n",
    "        self.__ = activation #later used to create folder name\n",
    "        self.loss_list = []\n",
    "        self.loss_validation = []\n",
    "        self.scalor = scalor\n",
    "        \n",
    "        #### The input is of shape (num_examples, time_steps, ninputs)\n",
    "        #### ninputs is the dimentionality (number of features) of the time series (here coordinates)\n",
    "        self.X = tf.placeholder(dtype=tf.float32, shape=(None, self.nsteps, ninputs))\n",
    "        self.Y = tf.placeholder(dtype=tf.float32, shape=(None, self.nsteps, ninputs))\n",
    "\n",
    "        \n",
    "        #Check if activation function valid and set activation\n",
    "        if self.__==\"relu\":\n",
    "            self.activation = tf.nn.relu\n",
    "            \n",
    "        elif self.__==\"tanh\":\n",
    "            self.activation = tf.nn.tanh\n",
    "                    \n",
    "        elif self.__==\"leaky_relu\":\n",
    "            self.activation = tf.nn.leaky_relu\n",
    "            \n",
    "        elif self.__==\"elu\":\n",
    "            self.activation = tf.nn.elu\n",
    "            \n",
    "        else:\n",
    "            raise ValueError(\"Wrong rnn avtivation function: {}\".format(self.__))\n",
    "        \n",
    "        \n",
    "        \n",
    "        #Check if cell type valid and set cell_type\n",
    "        if self._==\"basic_rnn\":\n",
    "            self.cell_type = tf.contrib.rnn.BasicRNNCell\n",
    "            \n",
    "        elif self._==\"lstm\":\n",
    "            self.cell_type = tf.contrib.rnn.BasicLSTMCell\n",
    "                    \n",
    "        elif self._==\"GRU\":\n",
    "            self.cell_type = tf.contrib.rnn.GRUCell\n",
    "            \n",
    "        else:\n",
    "            raise ValueError(\"Wrong rnn cell type: {}\".format(self._))\n",
    "            \n",
    "        \n",
    "        #Check Input of ncells        \n",
    "        if (type(self.ncells) == int):\n",
    "            self.ncells = [self.ncells]\n",
    "        \n",
    "        if (type(self.ncells) != list):\n",
    "            raise ValueError(\"Wrong type of Input for ncells\")\n",
    "        \n",
    "        for _ in range(len(self.ncells)):\n",
    "            if type(self.ncells[_]) != int:\n",
    "                raise ValueError(\"Wrong type of Input for ncells\")\n",
    "                \n",
    "        self.activationlist = []\n",
    "        for _ in range(len(self.ncells)-1):\n",
    "            self.activationlist.append(self.activation)\n",
    "        self.activationlist.append(tf.nn.tanh)\n",
    "        \n",
    "        self.cell = tf.contrib.rnn.MultiRNNCell([self.cell_type(num_units=self.ncells[layer], activation=self.activationlist[layer])\n",
    "                                                 for layer in range(len(self.ncells))])\n",
    "            \n",
    "        \n",
    "        #### I now define the output\n",
    "        self.RNNCell = tf.contrib.rnn.OutputProjectionWrapper(self.cell, output_size= num_output)\n",
    "        \n",
    "        \n",
    "        \n",
    "        \n",
    "        \n",
    "        self.sess = tf.Session()\n",
    "        \n",
    "    def set_cost_and_functions(self, LR=0.001):\n",
    "        #### I define here the function that unrolls the RNN cell\n",
    "        self.output, self.state = tf.nn.dynamic_rnn(self.RNNCell, self.X, dtype=tf.float32)\n",
    "        #### I define the cost function as the mean_squared_error (distance of predicted point to target)\n",
    "        self.cost = tf.reduce_mean(tf.losses.mean_squared_error(self.Y, self.output))   \n",
    "        \n",
    "        #### the rest proceed as usual\n",
    "        self.train = tf.train.AdamOptimizer(LR).minimize(self.cost)\n",
    "        #### Variable initializer\n",
    "        self.init = tf.global_variables_initializer()\n",
    "        self.saver = tf.train.Saver()\n",
    "        self.sess.run(self.init)\n",
    "  \n",
    "    \n",
    "    def save(self, rnn_folder=\"./rnn_model/rnn_basic\"):\n",
    "        self.saver.save(self.sess, rnn_folder)       \n",
    "            \n",
    "            \n",
    "    def load(self, filename=\"./rnn_model/rnn_basic\"):\n",
    "        self.saver.restore(self.sess, filename)\n",
    "\n",
    "               \n",
    "        \n",
    "    def fit(self, minibatches, epochs, print_step, validation_input, validation_output, checkpoint = 5, patience = 20, patience_trigger= 2./10**6):\n",
    "        patience_cnt = 0\n",
    "        start = len(self.loss_list)\n",
    "        epoche_save = start\n",
    "        \n",
    "        folder = \"./rnn_model_\" + str(self._)+ \"_\" + self.__ + \"_\" + str(self.ncells).replace(\" \",\"\") + \"c/rnn_basic\"\n",
    "        \n",
    "        for iep in range(start, start + epochs):\n",
    "            loss = 0\n",
    "            loss_val = 0\n",
    "            \n",
    "            batches = len(minibatches)\n",
    "            #Here I iterate over the batches\n",
    "            for batch in range(batches):\n",
    "            #### Here I train the RNNcell\n",
    "            #### The X is the time series, the Y is shifted by 1 time step\n",
    "                train, target = minibatches[batch]\n",
    "                self.sess.run(self.train, feed_dict={self.X:train, self.Y:target})\n",
    "                \n",
    "            \n",
    "                loss += self.sess.run(self.cost, feed_dict={self.X:train, self.Y:target})\n",
    "                loss_val += rnn.sess.run(self.cost, feed_dict={self.X:validation_input, rnn.Y:validation_output})\n",
    "            \n",
    "            #Normalize loss over number of batches and scale it back before normaliziation\n",
    "            loss /= batches\n",
    "            loss_val /= batches\n",
    "            self.loss_list.append(loss)\n",
    "            self.loss_validation.append(loss_val)\n",
    "            \n",
    "            #print(loss)\n",
    "            \n",
    "            #Here I create the checkpoint if the perfomance is better\n",
    "            if iep > 1 and iep%checkpoint == 0 and self.loss_validation[iep] < self.loss_validation[epoche_save]:\n",
    "                #print(\"Checkpoint created at epoch: \", iep)\n",
    "                self.save(folder)\n",
    "                epoche_save = iep\n",
    "            \n",
    "            #early stopping with patience\n",
    "            if iep > 1 and abs(self.loss_validation[iep]-self.loss_validation[iep-1]) < patience_trigger:\n",
    "                patience_cnt += 1\n",
    "                #print(\"Patience now at: \", patience_cnt, \" of \", patience)\n",
    "                \n",
    "                if patience_cnt + 1 > patience:\n",
    "                    print(\"\\n\", \"Early stopping at epoch \", iep, \", difference: \", abs(self.loss_validation[iep]-self.loss_validation[iep-1]))\n",
    "                    print(\"Cost: \", loss*10**6, \"e-6\")\n",
    "                    print(\"Cost on valdiation_set: \",loss_val*10**6, \"e-6\")\n",
    "                    break\n",
    "            \n",
    "            #Note that the loss here is multiplied with 1000 for easier reading\n",
    "            if iep%print_step==0:\n",
    "                print(\"Epoch number \",iep)\n",
    "                print(\"Cost: \",loss*10**6, \"e-6\")\n",
    "                print(\"Cost on validation_set: \",loss_val*10**6, \"e-6\")\n",
    "                print(\"Patience: \",patience_cnt, \"/\", patience)\n",
    "                print(\"Last checkpoint at: Epoch \", epoche_save, \"\\n\")\n",
    "        \n",
    "        #Set model back to the last checkpoint if performance was better\n",
    "        if self.loss_validation[epoche_save] < self.loss_validation[iep]:\n",
    "            self.load(folder)\n",
    "            print(\"\\n\")\n",
    "            print(\"State of last checkpoint checkpoint at epoch \", epoche_save, \" restored\")\n",
    "            print(\"Performance at last checkpoint is \" ,(self.loss_list[iep] - self.loss_list[epoche_save])/self.loss_list[iep]*100, \"% better\" )\n",
    "\n",
    "        \n",
    "        print(\"\\n\")\n",
    "        print(\"Model saved in at: \", folder)\n",
    "            \n",
    "            \n",
    "              \n",
    "        \n",
    "    def predict(self, x):\n",
    "        return self.sess.run(self.output, feed_dict={self.X:x})\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "#saves the rnn model and all its parameters including the scaler used\n",
    "#optional also saves the minibatches used to train and the test set\n",
    "\n",
    "def full_save(rnn, train= True, test= True):\n",
    "    folder = \"./rnn_model_\" + str(rnn._)+ \"_\" + rnn.__ + \"_\" + str(rnn.ncells).replace(\" \",\"\") + \"c/rnn_basic\"\n",
    "    rnn.save(folder)\n",
    "    pkl_name = folder[2:-10] + \".pkl\"\n",
    "    \n",
    "    \n",
    "    pkl_dic = {\"ncells\": rnn.ncells,\n",
    "              \"ninputs\": rnn.ninputs,\n",
    "              \"future_steps\": rnn.future_steps,\n",
    "              \"nsteps\": rnn.nsteps,\n",
    "              \"num_output\": rnn.num_output,\n",
    "              \"cell_type\": rnn._, #cell_type\n",
    "              \"activation\": rnn.__, #Activation\n",
    "              \"loss_list\": rnn.loss_list,\n",
    "              \"scalor\": rnn.scalor,\n",
    "              \"loss_validation\": rnn.loss_validation}\n",
    "    \n",
    "    if train == True:\n",
    "        pkl_dic[\"minibatches\"] = minibatches\n",
    "    \n",
    "    if test == True:\n",
    "        pkl_dic[\"test_input\"] = test_input\n",
    "        pkl_dic[\"test_target\"] = test_target\n",
    "        \n",
    "    pkl.dump( pkl_dic, open(pkl_name , \"wb\" ) )\n",
    "    \n",
    "    print(\"Model saved at: \", folder)\n",
    "    print(\"Remaining data saved as: {}\".format(pkl_name))\n",
    "\n",
    "\n",
    "\n",
    "#loads the rnn model with all its parameters including the scaler used\n",
    "#Checks if the pkl data also contains the training or test sets an return them accordingly\n",
    "def full_load(folder): \n",
    "    #returns state of rnn with all information and returns the train and test set used\n",
    "    \n",
    "    #Directory of pkl file\n",
    "    pkl_name = folder[2:-10] + \".pkl\"\n",
    "    \n",
    "    #Check if pkl file exists\n",
    "    my_file = Path(pkl_name)\n",
    "    if my_file.is_file() == False:\n",
    "        raise ValueError(\"There is no .pkl file with the name: {}\".format(pkl_name))\n",
    "        \n",
    "    pkl_dic = pkl.load( open(pkl_name , \"rb\" ) )\n",
    "    ncells = pkl_dic[\"ncells\"]\n",
    "    ninputs = pkl_dic[\"ninputs\"]\n",
    "    scalor = pkl_dic[\"scalor\"]\n",
    "    future_steps = pkl_dic[\"future_steps\"]\n",
    "    timesteps = pkl_dic[\"nsteps\"] \n",
    "    num_output = pkl_dic[\"num_output\"]\n",
    "    cell_type = pkl_dic[\"cell_type\"]\n",
    "    activation = pkl_dic[\"activation\"]\n",
    "    \n",
    "    #Check if test or trainng set in dictionary\n",
    "    batch = False\n",
    "    test = False\n",
    "    if \"minibatches\" in pkl_dic:\n",
    "        batch = True\n",
    "        minibatches = pkl_dic[\"minibatches\"]\n",
    "    if \"test_input\" in pkl_dic:\n",
    "        test = True\n",
    "        test_input = pkl_dic[\"test_input\"]\n",
    "        test_target = pkl_dic[\"test_target\"]\n",
    "    \n",
    "    #loads and initializes a new model with the exact same properties\n",
    "    \n",
    "    tf.reset_default_graph()\n",
    "    rnn = RNNPlacePrediction(time_steps=timesteps, future_steps=future_steps, ninputs=ninputs, \n",
    "                        ncells=ncells, num_output=num_output, cell_type=cell_type, activation=activation, scalor=scalor)\n",
    "\n",
    "    rnn.set_cost_and_functions()\n",
    "    \n",
    "    rnn.load(folder)\n",
    "    \n",
    "    rnn.loss_list = pkl_dic[\"loss_list\"]\n",
    "    \n",
    "    rnn.loss_validation = pkl_dic[\"loss_validation\"]\n",
    "    \n",
    "    print(\"Model succesfully loaded\")\n",
    "    \n",
    "    if batch and test:\n",
    "        data = [minibatches, test_input, test_target]\n",
    "        print(\"Minibatches (=training data) and test_input and test_target in data loaded\")\n",
    "        return rnn, data\n",
    "        \n",
    "    elif batch:\n",
    "        data = [minibatches]\n",
    "        print(\"Minibatches (=training data) loaded in data\")\n",
    "        return rnn, data\n",
    "        \n",
    "    elif test:\n",
    "        data = [test_input, test_target]\n",
    "        print(\"test_input and test_target loaded in data\")\n",
    "        return rnn, data\n",
    "    \n",
    "    else:\n",
    "        data = []\n",
    "        print(\"Only Model restored, no trainig or test data found in {}\".format(pkl_name))\n",
    "        print(\"Returned data is empty!\")\n",
    "        return rnn, data\n",
    "\n",
    "#returns the folder name used by full_save and full_load for a given architecture\n",
    "def get_rnn_folder(ncells, cell_type, activation):\n",
    "    folder = \"./rnn_model_\" + cell_type + \"_\" + activation + \"_\" + str(ncells).replace(\" \",\"\") + \"c/rnn_basic\"\n",
    "    return folder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "timesteps = 7\n",
    "future_steps = 1\n",
    "\n",
    "ninputs = 3\n",
    "\n",
    "#ncells as int or list of int\n",
    "ncells = [100, 100, 100]\n",
    "activation = \"leaky_relu\"\n",
    "cell_type = \"lstm\"\n",
    "\n",
    "num_output = 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From c:\\users\\sa_li\\anaconda3\\envs\\rnn-tf-ker\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\base.py:198: retry (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use the retry module or similar alternatives.\n"
     ]
    }
   ],
   "source": [
    "tf.reset_default_graph()\n",
    "rnn = RNNPlacePrediction(time_steps=timesteps, future_steps=future_steps, ninputs=ninputs, \n",
    "                        ncells=ncells, num_output=num_output, cell_type=\"lstm\", activation=\"leaky_relu\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "rnn.set_cost_and_functions()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch number  0\n",
      "Cost:  316163.4969156842 e-6\n",
      "Cost on validation_set:  317156.1284120692 e-6\n",
      "Patience:  0 / 20\n",
      "Last checkpoint at: Epoch  0 \n",
      "\n",
      "Epoch number  10\n",
      "Cost:  17620.41081349517 e-6\n",
      "Cost on validation_set:  17808.353961553683 e-6\n",
      "Patience:  0 / 20\n",
      "Last checkpoint at: Epoch  10 \n",
      "\n",
      "Epoch number  20\n",
      "Cost:  12158.986289314058 e-6\n",
      "Cost on validation_set:  12332.019157880959 e-6\n",
      "Patience:  0 / 20\n",
      "Last checkpoint at: Epoch  20 \n",
      "\n",
      "Epoch number  30\n",
      "Cost:  8429.908161159865 e-6\n",
      "Cost on validation_set:  8557.763253880103 e-6\n",
      "Patience:  0 / 20\n",
      "Last checkpoint at: Epoch  30 \n",
      "\n",
      "Epoch number  40\n",
      "Cost:  6765.2886581802095 e-6\n",
      "Cost on validation_set:  6839.355951998123 e-6\n",
      "Patience:  0 / 20\n",
      "Last checkpoint at: Epoch  40 \n",
      "\n",
      "Epoch number  50\n",
      "Cost:  5792.310645500588 e-6\n",
      "Cost on validation_set:  5863.479143658349 e-6\n",
      "Patience:  0 / 20\n",
      "Last checkpoint at: Epoch  50 \n",
      "\n",
      "Epoch number  60\n",
      "Cost:  5376.994696467422 e-6\n",
      "Cost on validation_set:  5446.046904855689 e-6\n",
      "Patience:  0 / 20\n",
      "Last checkpoint at: Epoch  60 \n",
      "\n",
      "Epoch number  70\n",
      "Cost:  4835.011047679324 e-6\n",
      "Cost on validation_set:  4899.287358099638 e-6\n",
      "Patience:  0 / 20\n",
      "Last checkpoint at: Epoch  70 \n",
      "\n",
      "Epoch number  80\n",
      "Cost:  4453.0257474371165 e-6\n",
      "Cost on validation_set:  4506.959038418393 e-6\n",
      "Patience:  0 / 20\n",
      "Last checkpoint at: Epoch  80 \n",
      "\n",
      "Epoch number  90\n",
      "Cost:  4041.3462069578645 e-6\n",
      "Cost on validation_set:  4103.328707779563 e-6\n",
      "Patience:  0 / 20\n",
      "Last checkpoint at: Epoch  90 \n",
      "\n",
      "Epoch number  100\n",
      "Cost:  3746.72157949833 e-6\n",
      "Cost on validation_set:  3810.4774051367544 e-6\n",
      "Patience:  0 / 20\n",
      "Last checkpoint at: Epoch  100 \n",
      "\n",
      "Epoch number  110\n",
      "Cost:  3510.6311173199915 e-6\n",
      "Cost on validation_set:  3572.610001144714 e-6\n",
      "Patience:  1 / 20\n",
      "Last checkpoint at: Epoch  110 \n",
      "\n",
      "Epoch number  120\n",
      "Cost:  3328.6676720477817 e-6\n",
      "Cost on validation_set:  3388.9460420712485 e-6\n",
      "Patience:  1 / 20\n",
      "Last checkpoint at: Epoch  120 \n",
      "\n",
      "Epoch number  130\n",
      "Cost:  3178.6257574378055 e-6\n",
      "Cost on validation_set:  3237.9631613662773 e-6\n",
      "Patience:  1 / 20\n",
      "Last checkpoint at: Epoch  130 \n",
      "\n",
      "Epoch number  140\n",
      "Cost:  3045.4906938207705 e-6\n",
      "Cost on validation_set:  3103.9184121804874 e-6\n",
      "Patience:  1 / 20\n",
      "Last checkpoint at: Epoch  140 \n",
      "\n",
      "Epoch number  150\n",
      "Cost:  3014.904371094565 e-6\n",
      "Cost on validation_set:  3073.1504057469065 e-6\n",
      "Patience:  1 / 20\n",
      "Last checkpoint at: Epoch  150 \n",
      "\n",
      "Epoch number  160\n",
      "Cost:  2844.7661992855546 e-6\n",
      "Cost on validation_set:  2901.79907257647 e-6\n",
      "Patience:  1 / 20\n",
      "Last checkpoint at: Epoch  160 \n",
      "\n",
      "Epoch number  170\n",
      "Cost:  2818.9633171572245 e-6\n",
      "Cost on validation_set:  2878.737646739843 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  165 \n",
      "\n",
      "Epoch number  180\n",
      "Cost:  2705.8817240474527 e-6\n",
      "Cost on validation_set:  2767.457837931985 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  180 \n",
      "\n",
      "Epoch number  190\n",
      "Cost:  2802.5307259414085 e-6\n",
      "Cost on validation_set:  2868.40574902504 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  185 \n",
      "\n",
      "Epoch number  200\n",
      "Cost:  2473.8708554312243 e-6\n",
      "Cost on validation_set:  2533.3558035971123 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  200 \n",
      "\n",
      "Epoch number  210\n",
      "Cost:  2456.7929551351904 e-6\n",
      "Cost on validation_set:  2513.4514421657764 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  210 \n",
      "\n",
      "Epoch number  220\n",
      "Cost:  2420.2582480515853 e-6\n",
      "Cost on validation_set:  2477.84735375019 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  220 \n",
      "\n",
      "Epoch number  230\n",
      "Cost:  2906.6367897876476 e-6\n",
      "Cost on validation_set:  2968.231827930309 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  225 \n",
      "\n",
      "Epoch number  240\n",
      "Cost:  2734.680800850308 e-6\n",
      "Cost on validation_set:  2792.3258075620547 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  225 \n",
      "\n",
      "Epoch number  250\n",
      "Cost:  2242.8401929954457 e-6\n",
      "Cost on validation_set:  2296.759985214056 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  250 \n",
      "\n",
      "Epoch number  260\n",
      "Cost:  2807.354240483323 e-6\n",
      "Cost on validation_set:  2874.5259948854527 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  250 \n",
      "\n",
      "Epoch number  270\n",
      "Cost:  2101.4384015701535 e-6\n",
      "Cost on validation_set:  2161.6989031953867 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  270 \n",
      "\n",
      "Epoch number  280\n",
      "Cost:  2128.7833589540664 e-6\n",
      "Cost on validation_set:  2190.027813708713 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  275 \n",
      "\n",
      "Epoch number  290\n",
      "Cost:  2030.9363811298513 e-6\n",
      "Cost on validation_set:  2090.106961902144 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  290 \n",
      "\n",
      "Epoch number  300\n",
      "Cost:  2049.279973170785 e-6\n",
      "Cost on validation_set:  2111.154213157851 e-6\n",
      "Patience:  2 / 20\n",
      "Last checkpoint at: Epoch  290 \n",
      "\n",
      "Epoch number  310\n",
      "Cost:  1975.3764973693462 e-6\n",
      "Cost on validation_set:  2037.5676658870868 e-6\n",
      "Patience:  3 / 20\n",
      "Last checkpoint at: Epoch  310 \n",
      "\n",
      "Epoch number  320\n",
      "Cost:  2357.8102402605637 e-6\n",
      "Cost on validation_set:  2425.418484436218 e-6\n",
      "Patience:  3 / 20\n",
      "Last checkpoint at: Epoch  315 \n",
      "\n",
      "Epoch number  330\n",
      "Cost:  1948.3688953440897 e-6\n",
      "Cost on validation_set:  2011.0500397074013 e-6\n",
      "Patience:  3 / 20\n",
      "Last checkpoint at: Epoch  330 \n",
      "\n",
      "Epoch number  340\n",
      "Cost:  1970.0811163327376 e-6\n",
      "Cost on validation_set:  2031.9556784924378 e-6\n",
      "Patience:  4 / 20\n",
      "Last checkpoint at: Epoch  330 \n",
      "\n",
      "Epoch number  350\n",
      "Cost:  1940.5714647714483 e-6\n",
      "Cost on validation_set:  2004.524148719082 e-6\n",
      "Patience:  5 / 20\n",
      "Last checkpoint at: Epoch  350 \n",
      "\n",
      "Epoch number  360\n",
      "Cost:  1968.3953304233592 e-6\n",
      "Cost on validation_set:  2038.7437665661755 e-6\n",
      "Patience:  5 / 20\n",
      "Last checkpoint at: Epoch  355 \n",
      "\n",
      "Epoch number  370\n",
      "Cost:  1976.2183642448033 e-6\n",
      "Cost on validation_set:  2046.2597617446338 e-6\n",
      "Patience:  5 / 20\n",
      "Last checkpoint at: Epoch  355 \n",
      "\n",
      "Epoch number  380\n",
      "Cost:  2104.1538024884326 e-6\n",
      "Cost on validation_set:  2173.166846596571 e-6\n",
      "Patience:  5 / 20\n",
      "Last checkpoint at: Epoch  355 \n",
      "\n",
      "Epoch number  390\n",
      "Cost:  1913.8040573357841 e-6\n",
      "Cost on validation_set:  1984.506214665639 e-6\n",
      "Patience:  6 / 20\n",
      "Last checkpoint at: Epoch  385 \n",
      "\n",
      "Epoch number  400\n",
      "Cost:  1854.3496478868778 e-6\n",
      "Cost on validation_set:  1922.2521764594455 e-6\n",
      "Patience:  6 / 20\n",
      "Last checkpoint at: Epoch  400 \n",
      "\n",
      "Epoch number  410\n",
      "Cost:  1861.1944058563472 e-6\n",
      "Cost on validation_set:  1930.6607739350131 e-6\n",
      "Patience:  6 / 20\n",
      "Last checkpoint at: Epoch  400 \n",
      "\n",
      "Epoch number  420\n",
      "Cost:  1866.6057852854908 e-6\n",
      "Cost on validation_set:  1936.6092286830724 e-6\n",
      "Patience:  6 / 20\n",
      "Last checkpoint at: Epoch  400 \n",
      "\n",
      "Epoch number  430\n",
      "Cost:  1881.5245793395957 e-6\n",
      "Cost on validation_set:  1952.4438295859932 e-6\n",
      "Patience:  6 / 20\n",
      "Last checkpoint at: Epoch  400 \n",
      "\n",
      "Epoch number  440\n",
      "Cost:  1911.4178085569727 e-6\n",
      "Cost on validation_set:  1983.390877369878 e-6\n",
      "Patience:  9 / 20\n",
      "Last checkpoint at: Epoch  400 \n",
      "\n",
      "Epoch number  450\n",
      "Cost:  1808.151681257715 e-6\n",
      "Cost on validation_set:  1876.5825160973986 e-6\n",
      "Patience:  9 / 20\n",
      "Last checkpoint at: Epoch  450 \n",
      "\n",
      "Epoch number  460\n",
      "Cost:  1807.536144719221 e-6\n",
      "Cost on validation_set:  1876.1289024422335 e-6\n",
      "Patience:  9 / 20\n",
      "Last checkpoint at: Epoch  460 \n",
      "\n",
      "Epoch number  470\n",
      "Cost:  1835.432499213967 e-6\n",
      "Cost on validation_set:  1907.6892071901711 e-6\n",
      "Patience:  9 / 20\n",
      "Last checkpoint at: Epoch  460 \n",
      "\n",
      "Epoch number  480\n",
      "Cost:  1824.4561668875258 e-6\n",
      "Cost on validation_set:  1897.5317781401236 e-6\n",
      "Patience:  13 / 20\n",
      "Last checkpoint at: Epoch  460 \n",
      "\n",
      "\n",
      " Early stopping at epoch  489 , difference:  5.850276021763991e-07\n",
      "Cost:  0.0018202092466052882\n",
      "Cost on valdiation_set:  0.0018940789727927294\n",
      "INFO:tensorflow:Restoring parameters from ./rnn_model_lstm_leaky_relu_[100,100,100]c/rnn_basic\n",
      "\n",
      "\n",
      "State of last checkpoint checkpoint at epoch  460  restored\n",
      "Performance at last checkpoint is  0.6962442317938289 % better\n",
      "\n",
      "\n",
      "Model saved in at:  ./rnn_model_lstm_leaky_relu_[100,100,100]c/rnn_basic\n",
      "Model saved at:  ./rnn_model_lstm_leaky_relu_[100,100,100]c/rnn_basic\n",
      "Remaining data saved as: rnn_model_lstm_leaky_relu_[100,100,100]c.pkl\n"
     ]
    }
   ],
   "source": [
    "rnn.fit(minibatches, epochs = 5000, print_step=10, validation_input = test_input, validation_output= test_target)\n",
    "full_save(rnn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xt8VPWd//HX58wlCQSQS/ACIlCxilyiDYjgj0qtitt6+VmtF7bq1l+1tRZXf1Wxbm2XrbVuL1Yfdddq6/a3Xau2tbqsYr3grbVWCUptuahAQVNQbpKES5K5fH5/zEkYkkkmQCYTkvfz8ZhHZr5zzpnvGYZ5z/f7Ped7zN0RERHpSFDsCoiISM+nsBARkbwUFiIikpfCQkRE8lJYiIhIXgoLERHJS2EhIiJ5KSxERCQvhYWIiOQVLXYFusqwYcN89OjRxa6GiMgBZcmSJZvdvSLfcr0mLEaPHk11dXWxqyEickAxs3WdWU7dUCIikpfCQkRE8lJYiIhIXr1mzEJEdkskEtTU1NDQ0FDsqkgPUVpaysiRI4nFYvu0vsJCpBeqqalhwIABjB49GjMrdnWkyNydLVu2UFNTw5gxY/ZpG+qGEumFGhoaGDp0qIJCADAzhg4dul8tTYWFSC+loJBs+/t5UFg0bofnboUanaMhItKePh8WH9bVwUv/yht/XFTsqoj0KuXl5cWuQodeeOEF/vCHP+z1etXV1cydOzfvctOnT9+Xau23b3/72wXZbp8PCywCQFMiUeSKiEh36igskslku+tVVVVx11135d3+vgRRV1BYFEgQCQ8IS6eLWxGRPmDdunWccsopTJo0iVNOOYV3330XgF/96ldMmDCByZMnM3PmTACWLVvG1KlTqaysZNKkSbzzzjtttvfggw8yceJEJkyYwI033thSXl5ezs0338zkyZOZNm0aH3zwwR7rrV27lnvuuYc77riDyspKfve733HZZZdx3XXXMWvWLG688UZee+01pk+fznHHHcf06dN56623gEzIfPrTnwbgm9/8Jp///Oc5+eSTGTt27B4h0tyyeuGFFzj55JM577zzOProo5kzZw7uDsDChQs5+uijOemkk5g7d27LdrO19z7813/9V0v5lVdeSSqVYt68eezatYvKykrmzJmzb/9I7ejzh84GkTAv06niVkSkQP75f5axfH1dl25z/GED+caZx+71eldffTWXXHIJl156Kffffz9z587lscceY/78+Tz11FOMGDGCbdu2AXDPPfdwzTXXMGfOHJqamkil9vw/un79em688UaWLFnC4MGDOe2003jsscc455xz2LFjB9OmTePWW2/lhhtu4L777uOf/umfWtYdPXo0X/ziFykvL+erX/0qAD/96U95++23efbZZ4lEItTV1fHSSy8RjUZ59tln+drXvsYjjzzSZp9WrlzJ888/T319PR/96Ef50pe+1OZchjfeeINly5Zx2GGHMWPGDF5++WWqqqq48soreemllxgzZgwXXXRRzvcs1/uwYsUKHn74YV5++WVisRhXXXUVDzzwAN/5znf40Y9+xNKlS/f63yafPt+yiIQtC3eFhUihvfLKK1x88cUAfO5zn+P3v/89ADNmzOCyyy7jvvvuawmFE088kW9/+9vcfvvtrFu3jrKysj22tXjxYk4++WQqKiqIRqPMmTOHl156CYB4PN7yK/1jH/sYa9eu7VT9zj//fCKRTNd0bW0t559/PhMmTODaa69l2bJlOdf51Kc+RUlJCcOGDWP48OFtWjEAU6dOZeTIkQRBQGVlJWvXrmXlypWMHTu25byH9sIi1/uwaNEilixZwpQpU6isrGTRokWsWbOmU/u4r/p8yyISbe6GUlhI77QvLYDu0nw45z333MOrr77KE088QWVlJUuXLuXiiy/mhBNO4IknnuD000/nJz/5CZ/4xCda1m3uysklFou1bDsSiXQ4BpGtf//+Lfe//vWvM2vWLB599FHWrl3LySefnHOdkpKSlvvtvVauZTqqf7Zc74O7c+mll3Lbbbd1ahtdQS2LQGEh0l2mT5/OQw89BMADDzzASSedBMDq1as54YQTmD9/PsOGDeO9995jzZo1jB07lrlz53LWWWfx5ptv7rGtE044gRdffJHNmzeTSqV48MEH+fjHP97pugwYMID6+vp2n6+trWXEiBEA/OxnP9vLPc3v6KOPZs2aNS2tnocffjjncrneh1NOOYVf//rXbNy4EYCtW7eybl1mpvFYLEaiAAfsFDQszGy2mb1lZqvMbF6O579oZn82s6Vm9nszG5/13E3hem+Z2emFqmNzk5N05355iEjn7Ny5k5EjR7bcfvCDH3DXXXfxH//xH0yaNImf//zn3HnnnQBcf/31LQPVM2fOZPLkyTz88MNMmDC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mNmNQMzdv1X4PRPpmFoWIl3H27nf3jK5NGbdT6FxRekhFBYiXeeCrL+vhPf/QGYWVIA5wO/D+4uAL0HLxYoGdlclRfaFfrWI7J2y8Cp0zX7r7s2Hz5aY2atkfoRdFJbNBe43s+uBTcA/hOXXAPea2eVkWhBfIjM7sEiPpDELkS4QjllUufvmYtdFpBDUDSUiInmpZSEiInmpZSEiInkpLEREJC+FhYiI5KWwEBGRvBQWIiKSl8JCRETy+v+6HLRK//x40QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Plot the loss\n",
    "def plot_loss_list(loss_list = rnn.loss_list, loss_validation = rnn.loss_validation):\n",
    "    plt.plot(rnn.loss_list, label='Loss on training set')\n",
    "    plt.plot(rnn.loss_validation,  label='Loss on test set')\n",
    "    plt.legend()\n",
    "    plt.xlabel(\"Epoch\")\n",
    "    plt.ylabel(\"Cost\")\n",
    "    plt.show()\n",
    "\n",
    "plot_loss_list(rnn.loss_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "folder = get_rnn_folder(ncells = ncells, cell_type = cell_type, activation = activation)\n",
    "#rnn, data = full_load(folder)\n",
    "#minibatches, test_input, test_target = data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4690, 7, 3)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_input.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "def rnn_test(rnn, test_input= test_input, test_target= test_target, scalor= rnn.scalor):\n",
    "    \n",
    "    #Here I predict based on my test set\n",
    "    test_pred = rnn.predict(test_input)\n",
    "    \n",
    "    #Here i subtract a prediction (random particle) from the target to get an idea of the predictions\n",
    "    #scaler_inv(test_input, scalerfunc = func)[0,:,:]\n",
    "    diff = scaler_inv(test_pred, scalerfunc = func, scalor= scalor)-scaler_inv(test_target, scalerfunc = func, scalor= scalor)\n",
    "    print(diff[random.randint(0,test_pred.shape[0]),:,:])\n",
    "    \n",
    "    #Here I evaluate my model on the test set based on mean_squared_error\n",
    "    loss = rnn.sess.run(rnn.cost, feed_dict={rnn.X:test_input, rnn.Y:test_target})\n",
    "    print(\"Loss on test set:\", loss)\n",
    "    \n",
    "    return test_pred, loss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.22876946 -1.05757492  0.05743555]\n",
      " [ 0.4227805  -1.49878024 -0.45964226]\n",
      " [ 1.57940168 -0.0964699  -0.29063407]\n",
      " [ 8.23204061 -7.21131909  0.2346999 ]\n",
      " [ 0.63359657 -1.23937142  0.23865187]\n",
      " [ 3.5459507  -2.39105333  0.56137755]\n",
      " [ 0.0832766  -0.32882895  0.49288811]\n",
      " [ 0.          0.          0.        ]]\n",
      "Loss on test set: 0.0018604315\n"
     ]
    }
   ],
   "source": [
    "test_pred, test_loss = rnn_test(rnn=rnn)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}