{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-09-28T07:08:15.800630Z",
     "start_time": "2024-09-28T07:08:15.795358Z"
    }
   },
   "source": [
    "import pickle\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from matplotlib.patches import bbox_artist"
   ],
   "outputs": [],
   "execution_count": 88
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# Rivers",
   "id": "1bc57a44c96e39f5"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-28T07:08:16.094821Z",
     "start_time": "2024-09-28T07:08:16.069249Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data_real = pd.read_csv('../../data/rivers/train.csv', index_col=0).values\n",
    "data_real.shape"
   ],
   "id": "408b848129cbe2ed",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(11326, 3)"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 89
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-28T07:37:36.668362Z",
     "start_time": "2024-09-28T07:37:36.659943Z"
    }
   },
   "cell_type": "code",
   "source": [
    "with open('../../storage/ilbpx91y/inference_data/synthetics_epoch=50_seed=0.pkl', 'rb') as f:\n",
    "    data_l2dtw = pickle.load(f)\n",
    "data_l2dtw.shape"
   ],
   "id": "99cfa65b1014a899",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8192, 30, 3)"
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 137
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-28T07:19:59.681170Z",
     "start_time": "2024-09-28T07:19:59.666145Z"
    }
   },
   "cell_type": "code",
   "source": [
    "with open('causaltime_data/rivers/scaler_rivers.pkl', 'rb') as f:\n",
    "    scaler = pickle.load(f)\n",
    "data_causaltime = np.load('causaltime_data/rivers/generated_datas_seed=0_ne1=20_ne2=10.npy')[:, 30:, :3]\n",
    "data_causaltime.shape"
   ],
   "id": "de393a48896c63e1",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/novella/.virtualenvs/ts-causality/lib/python3.10/site-packages/sklearn/base.py:376: InconsistentVersionWarning: Trying to unpickle estimator MinMaxScaler from version 1.3.0 when using version 1.5.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:\n",
      "https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(8102, 30, 3)"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 113
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-28T07:25:02.107700Z",
     "start_time": "2024-09-28T07:25:02.100784Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data_crvae = np.load('crvae_data/rivers/syn_it=99000.npy')\n",
    "data_crvae.shape"
   ],
   "id": "1a7fbe8151aa6d27",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1024, 30, 3)"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 121
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-28T07:36:22.560660Z",
     "start_time": "2024-09-28T07:36:21.572139Z"
    }
   },
   "cell_type": "code",
   "source": [
    "fig, axes = plt.subplots(2, 4, figsize=(16, 8))\n",
    "axes = axes.ravel()\n",
    "\n",
    "axes[0].plot(data_real[10*30:(10+1)*30], label=['Dillingen', 'Kempten', 'Lenggries'], linewidth=3)\n",
    "axes[0].set_title('Real', fontsize=28)\n",
    "axes[1].plot(data_real[12*30:(12+1)*30], linewidth=3)\n",
    "axes[1].set_title('Real', fontsize=28)\n",
    "\n",
    "axes[2].plot(data_l2dtw[27], linewidth=3)\n",
    "axes[2].set_title('Our w/L2 w/DTW', fontsize=28)\n",
    "axes[3].plot(data_l2dtw[12], linewidth=3)\n",
    "axes[3].set_title('Our w/L2 w/DTW', fontsize=28)\n",
    "\n",
    "axes[4].set_title('CausalTime', fontsize=28)\n",
    "axes[4].plot(scaler.inverse_transform(data_causaltime[4]), linewidth=3)\n",
    "axes[5].set_title('CausalTime', fontsize=28)\n",
    "axes[5].plot(scaler.inverse_transform(data_causaltime[8]), linewidth=3)\n",
    "\n",
    "axes[6].set_title('CR-VAE', fontsize=28)\n",
    "axes[6].plot(scaler.inverse_transform(data_crvae[14]), linewidth=3)\n",
    "axes[7].set_title('CR-VAE', fontsize=28)\n",
    "axes[7].plot(scaler.inverse_transform(data_crvae[25]), linewidth=3)\n",
    "\n",
    "for ax in axes:\n",
    "    ax.set_xlabel('')\n",
    "    ax.xaxis.set_tick_params(labelsize=16)\n",
    "    ax.yaxis.set_tick_params(labelsize=16)\n",
    "\n",
    "lgd = fig.legend(fontsize=22, ncols=3, loc='upper center', bbox_to_anchor=(0.5, 1.1))\n",
    "fig.tight_layout()\n",
    "fig.savefig('../../experiments/samples/rivers.pdf', bbox_inches='tight')\n",
    "\n",
    "plt.show()\n",
    "plt.close()"
   ],
   "id": "cc4b9ed82754e073",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 1600x800 with 8 Axes>"
      ],
      "image/png": "[encoded data, 239984 characters]"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "execution_count": 134
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# Henon",
   "id": "741543d0c82c6b56"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-28T07:38:30.289688Z",
     "start_time": "2024-09-28T07:38:30.261592Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data_real = pd.read_csv('../../data/henon/train.csv', index_col=0).values\n",
    "data_real.shape"
   ],
   "id": "54514e0c865093ea",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10000, 6)"
      ]
     },
     "execution_count": 139,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 139
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-28T07:38:41.454881Z",
     "start_time": "2024-09-28T07:38:41.441981Z"
    }
   },
   "cell_type": "code",
   "source": [
    "with open('../../storage/5p3c6jot/inference_data/synthetics_epoch=50_seed=0.pkl', 'rb') as f:\n",
    "    data_l2dtw = pickle.load(f)\n",
    "data_l2dtw.shape"
   ],
   "id": "418b0e29e6723416",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8192, 30, 6)"
      ]
     },
     "execution_count": 140,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 140
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-28T07:46:03.667793Z",
     "start_time": "2024-09-28T07:46:03.644298Z"
    }
   },
   "cell_type": "code",
   "source": [
    "with open('causaltime_data/henon6/scaler_henon.pkl', 'rb') as f:\n",
    "    scaler = pickle.load(f)\n",
    "data_causaltime = np.load('causaltime_data/henon6/generated_datas_seed=0_ne1=40_ne2=10.npy')[:, 30:, :6]\n",
    "data_causaltime.shape"
   ],
   "id": "190f06e498a109",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/novella/.virtualenvs/ts-causality/lib/python3.10/site-packages/sklearn/base.py:376: InconsistentVersionWarning: Trying to unpickle estimator MinMaxScaler from version 1.3.0 when using version 1.5.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:\n",
      "https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(8120, 30, 6)"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 150
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-28T07:46:04.136187Z",
     "start_time": "2024-09-28T07:46:04.128022Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data_crvae = np.load('crvae_data/henon6/syn_it=90000.npy')\n",
    "data_crvae.shape"
   ],
   "id": "f2bbdc08874bca69",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1024, 30, 6)"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 151
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-28T07:46:33.169900Z",
     "start_time": "2024-09-28T07:46:32.067890Z"
    }
   },
   "cell_type": "code",
   "source": [
    "fig, axes = plt.subplots(2, 4, figsize=(16, 8))\n",
    "axes = axes.ravel()\n",
    "\n",
    "axes[0].plot(data_real[10*30:(10+1)*30], label=['X0', 'X1', 'X2', 'X3', 'X4', 'X5'], linewidth=1)\n",
    "axes[0].set_title('Real', fontsize=28)\n",
    "axes[1].plot(data_real[12*30:(12+1)*30], linewidth=1)\n",
    "axes[1].set_title('Real', fontsize=28)\n",
    "\n",
    "axes[2].plot(data_l2dtw[27], linewidth=1)\n",
    "axes[2].set_title('Our w/L2 w/DTW', fontsize=28)\n",
    "axes[3].plot(data_l2dtw[12], linewidth=1)\n",
    "axes[3].set_title('Our w/L2 w/DTW', fontsize=28)\n",
    "\n",
    "axes[4].set_title('CausalTime', fontsize=28)\n",
    "axes[4].plot(scaler.inverse_transform(data_causaltime[4]), linewidth=1)\n",
    "axes[5].set_title('CausalTime', fontsize=28)\n",
    "axes[5].plot(scaler.inverse_transform(data_causaltime[8]), linewidth=1)\n",
    "\n",
    "axes[6].set_title('CR-VAE', fontsize=28)\n",
    "axes[6].plot(scaler.inverse_transform(data_crvae[14]), linewidth=1)\n",
    "axes[7].set_title('CR-VAE', fontsize=28)\n",
    "axes[7].plot(scaler.inverse_transform(data_crvae[25]), linewidth=1)\n",
    "\n",
    "for ax in axes:\n",
    "    ax.set_xlabel('')\n",
    "    ax.xaxis.set_tick_params(labelsize=16)\n",
    "    ax.yaxis.set_tick_params(labelsize=16)\n",
    "\n",
    "lgd = fig.legend(fontsize=22, ncols=6, loc='upper center', bbox_to_anchor=(0.5, 1.1))\n",
    "fig.tight_layout()\n",
    "fig.savefig('../../experiments/samples/henon.pdf', bbox_inches='tight')\n",
    "\n",
    "plt.show()\n",
    "plt.close()"
   ],
   "id": "e845c2029c704c43",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 1600x800 with 8 Axes>"
      ],
      "image/png": "[encoded data, 848684 characters]"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "execution_count": 153
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "fd2f2b16a78a7964"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
