{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "70a32352-80c9-40b7-8f68-1aeecfc52658", "metadata": { "ExecuteTime": { "end_time": "2024-04-28T16:36:31.534991Z", "start_time": "2024-04-28T16:36:31.532153Z" }, "papermill": { "duration": 0.023706, "end_time": "2024-01-31T17:49:07.385771", "exception": false, "start_time": "2024-01-31T17:49:07.362065", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# Import to be able to import python package from src\n", "import sys\n", "sys.path.insert(0, '../src')" ] }, { "cell_type": "code", "execution_count": 3, "id": "f8a26d78-229f-47f7-9f66-d0c245dbc096", "metadata": { "ExecuteTime": { "end_time": "2024-04-28T10:23:48.796052Z", "start_time": "2024-04-28T10:23:37.448695Z" }, "papermill": { "duration": 2.47651, "end_time": "2024-01-31T17:49:09.867453", "exception": false, "start_time": "2024-01-31T17:49:07.390943", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "import ontime as on\n", "import pandas as pd\n", "import numpy as np\n", "\n", "from ontime.module.processing.tensorflow.utils import create_dataset\n", "from ontime.module.processing.common import train_test_split, normalize" ] }, { "cell_type": "markdown", "id": "fbfc7029-29a7-4ab8-be7d-fd2d36fd0ad9", "metadata": {}, "source": [ "# TensorFlow Dataset" ] }, { "cell_type": "markdown", "id": "ae9ae4d0-d7d6-4e6c-ac31-fa108baf13db", "metadata": {}, "source": [ "## Create test TimeSeries" ] }, { "cell_type": "code", "execution_count": 4, "id": "e6f47f17-3c04-4cc9-b806-26b37baa3030", "metadata": {}, "outputs": [], "source": [ "v1 = np.arange(0,100)\n", "v2 = np.arange(100,200)\n", "arr = np.column_stack((v1,v2))\n", "\n", "start_date = pd.Timestamp('2023-01-01')\n", "time_indices = pd.date_range(start=start_date, periods=len(arr), freq='D')\n", "\n", "ts = on.TimeSeries.from_times_and_values(time_indices, arr)" ] }, { "cell_type": "markdown", "id": "d43b1156-59ab-4498-bdde-15abd42cca10", "metadata": {}, "source": [ "## Create Splits" ] }, { "cell_type": "code", "execution_count": 6, "id": "d39b1594-2104-410f-980b-654130379d13", "metadata": {}, "outputs": [], "source": [ "train, test = train_test_split(ts, test_split=0.3)\n", "train_enc, transformer = normalize(train, return_transformer=True)\n", "test_enc = transformer.transform(test)" ] }, { "cell_type": "markdown", "id": "e36c90bf-7abd-4a94-bedc-b04ea3fecd3c", "metadata": {}, "source": [ "## Create DataSets" ] }, { "cell_type": "code", "execution_count": 7, "id": "7f9f2ed4-a4b3-4312-821d-6e2b09776731", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "I0000 00:00:1736180054.254876 319935 gpu_device.cc:2022] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 5564 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3070 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6\n" ] } ], "source": [ "ds_train = create_dataset(\n", " train_enc,\n", " window_length = 10,\n", " stride_length = 10,\n", " input_length = 6, \n", " target_length = 4\n", ")\n", "\n", "ds_test = create_dataset(\n", " test_enc,\n", " window_length = 10,\n", " stride_length = 10,\n", " input_length = 6, \n", " target_length = 4\n", ")" ] }, { "cell_type": "markdown", "id": "a0facaf1-9f3b-42c8-8a4a-a9df0bf74532", "metadata": {}, "source": [ "## Check samples encoding" ] }, { "cell_type": "markdown", "id": "695859ce-4833-4b94-b51d-9ddf2f1e08f7", "metadata": {}, "source": [ "Get a sample" ] }, { "cell_type": "code", "execution_count": 8, "id": "6bd1446b-1c4b-48a7-92e1-d0a5f8338b65", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2025-01-06 17:14:44.385253: I tensorflow/core/framework/local_rendezvous.cc:405] Local rendezvous is aborting with status: OUT_OF_RANGE: End of sequence\n" ] } ], "source": [ "# Input\n", "input = None\n", "target = None\n", "\n", "for i in ds_train.take(1):\n", " input = i[0]\n", " target = i[1]" ] }, { "cell_type": "markdown", "id": "ad3d1b8d-d920-4d6b-8f71-e1020c43d305", "metadata": {}, "source": [ "Print input" ] }, { "cell_type": "code", "execution_count": 9, "id": "d12152ce-0370-4ef7-9a9e-ff4dd8f552e2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<TimeSeries (DataArray) (time: 6, component: 2, sample: 1)> Size: 96B\n",
"array([[[ 0.],\n",
" [100.]],\n",
"\n",
" [[ 1.],\n",
" [101.]],\n",
"\n",
" [[ 2.],\n",
" [102.]],\n",
"\n",
" [[ 3.],\n",
" [103.]],\n",
"\n",
" [[ 4.],\n",
" [104.]],\n",
"\n",
" [[ 5.],\n",
" [105.]]])\n",
"Coordinates:\n",
" * time (time) int64 48B 0 1 2 3 4 5\n",
" * component (component) <U1 8B '0' '1'\n",
"Dimensions without coordinates: sample\n",
"Attributes:\n",
" static_covariates: None\n",
" hierarchy: None<TimeSeries (DataArray) (time: 4, component: 2, sample: 1)> Size: 64B\n",
"array([[[ 6.],\n",
" [106.]],\n",
"\n",
" [[ 7.],\n",
" [107.]],\n",
"\n",
" [[ 8.],\n",
" [108.]],\n",
"\n",
" [[ 9.],\n",
" [109.]]])\n",
"Coordinates:\n",
" * time (time) int64 32B 0 1 2 3\n",
" * component (component) <U1 8B '0' '1'\n",
"Dimensions without coordinates: sample\n",
"Attributes:\n",
" static_covariates: None\n",
" hierarchy: None"
],
"text/plain": [
"