mirror of
https://github.com/wassname/pytorch-ts.git
synced 2026-07-31 12:40:41 +08:00
922 lines
43 KiB
Plaintext
922 lines
43 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:04.900941Z",
|
|
"start_time": "2022-12-23T06:21:04.889808Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# import warnings\n",
|
|
"# warnings.simplefilter(\"ignore\")\n",
|
|
"\n",
|
|
"# autoreload import your package\n",
|
|
"%load_ext autoreload\n",
|
|
"%autoreload 2"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:06.416555Z",
|
|
"start_time": "2022-12-23T06:21:04.902165Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"%matplotlib inline\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"\n",
|
|
"import numpy as np\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"import torch"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:06.625752Z",
|
|
"start_time": "2022-12-23T06:21:06.418508Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from gluonts.dataset.multivariate_grouper import MultivariateGrouper\n",
|
|
"from gluonts.dataset.repository.datasets import dataset_recipes, get_dataset\n",
|
|
"from gluonts.evaluation.backtest import make_evaluation_predictions\n",
|
|
"from gluonts.evaluation import MultivariateEvaluator"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:06.738760Z",
|
|
"start_time": "2022-12-23T06:21:06.627406Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from pts.model.tempflow import TempFlowEstimator\n",
|
|
"from pts.model.time_grad2 import TimeGradEstimator2\n",
|
|
"from pts.model.transformer_tempflow import TransformerTempFlowEstimator\n",
|
|
"from pts import Trainer"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:06.790762Z",
|
|
"start_time": "2022-12-23T06:21:06.740481Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:06.817593Z",
|
|
"start_time": "2022-12-23T06:21:06.791945Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"def plot(target, forecast, prediction_length, prediction_intervals=(50.0, 90.0), color='g', fname=None):\n",
|
|
" label_prefix = \"\"\n",
|
|
" rows = 4\n",
|
|
" cols = 4\n",
|
|
" fig, axs = plt.subplots(rows, cols, figsize=(24, 24))\n",
|
|
" axx = axs.ravel()\n",
|
|
" seq_len, target_dim = target.shape\n",
|
|
" \n",
|
|
" ps = [50.0] + [\n",
|
|
" 50.0 + f * c / 2.0 for c in prediction_intervals for f in [-1.0, +1.0]\n",
|
|
" ]\n",
|
|
" \n",
|
|
" percentiles_sorted = sorted(set(ps))\n",
|
|
" \n",
|
|
" def alpha_for_percentile(p):\n",
|
|
" return (p / 100.0) ** 0.3\n",
|
|
" \n",
|
|
" for dim in range(0, min(rows * cols, target_dim)):\n",
|
|
" ax = axx[dim]\n",
|
|
"\n",
|
|
" target[-2 * prediction_length :][dim].plot(ax=ax)\n",
|
|
" \n",
|
|
" ps_data = [forecast.quantile(p / 100.0)[:,dim] for p in percentiles_sorted]\n",
|
|
" i_p50 = len(percentiles_sorted) // 2\n",
|
|
" \n",
|
|
" p50_data = ps_data[i_p50]\n",
|
|
" p50_series = pd.Series(data=p50_data, index=forecast.index)\n",
|
|
" p50_series.plot(color=color, ls=\"-\", label=f\"{label_prefix}median\", ax=ax)\n",
|
|
" \n",
|
|
" for i in range(len(percentiles_sorted) // 2):\n",
|
|
" ptile = percentiles_sorted[i]\n",
|
|
" alpha = alpha_for_percentile(ptile)\n",
|
|
" ax.fill_between(\n",
|
|
" forecast.index,\n",
|
|
" ps_data[i],\n",
|
|
" ps_data[-i - 1],\n",
|
|
" facecolor=color,\n",
|
|
" alpha=alpha,\n",
|
|
" interpolate=True,\n",
|
|
" )\n",
|
|
" # Hack to create labels for the error intervals.\n",
|
|
" # Doesn't actually plot anything, because we only pass a single data point\n",
|
|
" pd.Series(data=p50_data[:1], index=forecast.index[:1]).plot(\n",
|
|
" color=color,\n",
|
|
" alpha=alpha,\n",
|
|
" linewidth=10,\n",
|
|
" label=f\"{label_prefix}{100 - ptile * 2}%\",\n",
|
|
" ax=ax,\n",
|
|
" )\n",
|
|
"\n",
|
|
" legend = [\"observations\", \"median prediction\"] + [f\"{k}% prediction interval\" for k in prediction_intervals][::-1] \n",
|
|
" axx[0].legend(legend, loc=\"upper left\")\n",
|
|
" \n",
|
|
" if fname is not None:\n",
|
|
" plt.savefig(fname, bbox_inches='tight', pad_inches=0.05)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:06.839629Z",
|
|
"start_time": "2022-12-23T06:21:06.818741Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Available datasets: ['constant', 'exchange_rate', 'solar-energy', 'electricity', 'traffic', 'exchange_rate_nips', 'electricity_nips', 'traffic_nips', 'solar_nips', 'wiki-rolling_nips', 'taxi_30min', 'kaggle_web_traffic_with_missing', 'kaggle_web_traffic_without_missing', 'kaggle_web_traffic_weekly', 'm1_yearly', 'm1_quarterly', 'm1_monthly', 'nn5_daily_with_missing', 'nn5_daily_without_missing', 'nn5_weekly', 'tourism_monthly', 'tourism_quarterly', 'tourism_yearly', 'cif_2016', 'london_smart_meters_without_missing', 'wind_farms_without_missing', 'car_parts_without_missing', 'dominick', 'fred_md', 'pedestrian_counts', 'hospital', 'covid_deaths', 'kdd_cup_2018_without_missing', 'weather', 'm3_monthly', 'm3_quarterly', 'm3_yearly', 'm3_other', 'm4_hourly', 'm4_daily', 'm4_weekly', 'm4_monthly', 'm4_quarterly', 'm4_yearly', 'm5', 'uber_tlc_daily', 'uber_tlc_hourly', 'airpassengers']\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(f\"Available datasets: {list(dataset_recipes.keys())}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:06.856379Z",
|
|
"start_time": "2022-12-23T06:21:06.840657Z"
|
|
},
|
|
"scrolled": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# exchange_rate_nips, electricity_nips, traffic_nips, solar_nips, wiki-rolling_nips, ## taxi_30min is buggy still\n",
|
|
"dataset = get_dataset(\"electricity_nips\", regenerate=False)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:06.874723Z",
|
|
"start_time": "2022-12-23T06:21:06.858646Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"MetaData(freq='H', target=None, feat_static_cat=[CategoricalFeatureInfo(name='feat_static_cat_0', cardinality='370')], feat_static_real=[], feat_dynamic_real=[], feat_dynamic_cat=[], prediction_length=24)"
|
|
]
|
|
},
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"dataset.metadata"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:07.663837Z",
|
|
"start_time": "2022-12-23T06:21:06.875746Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"train_grouper = MultivariateGrouper(max_target_dim=min(2000, int(dataset.metadata.feat_static_cat[0].cardinality)))\n",
|
|
"\n",
|
|
"test_grouper = MultivariateGrouper(\n",
|
|
" num_test_dates=int(len(dataset.test)/len(dataset.train)*2),\n",
|
|
"# num_test_dates=7,\n",
|
|
" max_target_dim=min(2000, int(dataset.metadata.feat_static_cat[0].cardinality)))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.079230Z",
|
|
"start_time": "2022-12-23T06:21:07.665093Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/home/wassname/miniforge3/envs/glounts/lib/python3.9/site-packages/gluonts/dataset/multivariate_grouper.py:191: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.\n",
|
|
" return {FieldName.TARGET: np.array([funcs(data) for data in dataset])}\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"dataset_train = train_grouper(dataset.train)\n",
|
|
"dataset_test = test_grouper(dataset.test)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.096888Z",
|
|
"start_time": "2022-12-23T06:21:12.080635Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"370"
|
|
]
|
|
},
|
|
"execution_count": 12,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"int(dataset.metadata.feat_static_cat[0].cardinality)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.113235Z",
|
|
"start_time": "2022-12-23T06:21:12.098346Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"370"
|
|
]
|
|
},
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"int(dataset.metadata.feat_static_cat[0].cardinality)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 57,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:33:27.308113Z",
|
|
"start_time": "2022-12-23T06:33:23.559765Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"estimator = TimeGradEstimator2(\n",
|
|
" target_dim=int(dataset.metadata.feat_static_cat[0].cardinality),\n",
|
|
" prediction_length=dataset.metadata.prediction_length,\n",
|
|
" context_length=dataset.metadata.prediction_length,\n",
|
|
" cell_type='GRU',\n",
|
|
" input_size=1484,\n",
|
|
" freq=dataset.metadata.freq,\n",
|
|
" loss_type='l2',\n",
|
|
" scaling=False,\n",
|
|
" diff_steps=100,\n",
|
|
" beta_end=0.1,\n",
|
|
" beta_schedule=\"linear\",\n",
|
|
" trainer=Trainer(device=device,\n",
|
|
" epochs=20,\n",
|
|
" learning_rate=1e-3,\n",
|
|
" num_batches_per_epoch=100,\n",
|
|
" batch_size=64,)\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 58,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:33:28.565303Z",
|
|
"start_time": "2022-12-23T06:33:27.309629Z"
|
|
},
|
|
"scrolled": true
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"cond_length 100\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "f7efc1b8dbd24c0d92ecfe54a25359a1",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
" 0%| | 0/99 [00:00<?, ?it/s]"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"shapes torch.Size([64, 370, 48]) torch.Size([64]) torch.Size([64, 100, 48])\n",
|
|
"cond -> cond_up torch.Size([64, 100, 48]) torch.Size([64, 370, 48])\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/media/wassname/SGIronWolf/projects5/timeseries/pytorch-ts/pts/model/time_grad2/gaussian_diffusion_ou.py:283: UserWarning: Using a target size (torch.Size([64, 1, 48])) that is different to the input size (torch.Size([64, 370, 46])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.\n",
|
|
" loss = F.mse_loss(x_recon, noise_rand)\n"
|
|
]
|
|
},
|
|
{
|
|
"ename": "RuntimeError",
|
|
"evalue": "The size of tensor a (46) must match the size of tensor b (48) at non-singleton dimension 2",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
|
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
|
|
"Input \u001b[0;32mIn [58]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m predictor \u001b[38;5;241m=\u001b[39m \u001b[43mestimator\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtrain\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdataset_train\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnum_workers\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\n",
|
|
"File \u001b[0;32m/media/wassname/SGIronWolf/projects5/timeseries/pytorch-ts/pts/model/estimator.py:179\u001b[0m, in \u001b[0;36mPyTorchEstimator.train\u001b[0;34m(self, training_data, validation_data, num_workers, prefetch_factor, shuffle_buffer_length, cache_data, **kwargs)\u001b[0m\n\u001b[1;32m 169\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtrain\u001b[39m(\n\u001b[1;32m 170\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 171\u001b[0m training_data: Dataset,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 177\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[1;32m 178\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m PyTorchPredictor:\n\u001b[0;32m--> 179\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtrain_model\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 180\u001b[0m \u001b[43m \u001b[49m\u001b[43mtraining_data\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 181\u001b[0m \u001b[43m \u001b[49m\u001b[43mvalidation_data\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 182\u001b[0m \u001b[43m \u001b[49m\u001b[43mnum_workers\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnum_workers\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 183\u001b[0m \u001b[43m \u001b[49m\u001b[43mprefetch_factor\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mprefetch_factor\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 184\u001b[0m \u001b[43m \u001b[49m\u001b[43mshuffle_buffer_length\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mshuffle_buffer_length\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 185\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_data\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache_data\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 186\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 187\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39mpredictor\n",
|
|
"File \u001b[0;32m/media/wassname/SGIronWolf/projects5/timeseries/pytorch-ts/pts/model/estimator.py:151\u001b[0m, in \u001b[0;36mPyTorchEstimator.train_model\u001b[0;34m(self, training_data, validation_data, num_workers, prefetch_factor, shuffle_buffer_length, cache_data, **kwargs)\u001b[0m\n\u001b[1;32m 133\u001b[0m validation_iter_dataset \u001b[38;5;241m=\u001b[39m TransformedIterableDataset(\n\u001b[1;32m 134\u001b[0m dataset\u001b[38;5;241m=\u001b[39mvalidation_data,\n\u001b[1;32m 135\u001b[0m transform\u001b[38;5;241m=\u001b[39mtransformation\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 139\u001b[0m cache_data\u001b[38;5;241m=\u001b[39mcache_data,\n\u001b[1;32m 140\u001b[0m )\n\u001b[1;32m 141\u001b[0m validation_data_loader \u001b[38;5;241m=\u001b[39m DataLoader(\n\u001b[1;32m 142\u001b[0m validation_iter_dataset,\n\u001b[1;32m 143\u001b[0m batch_size\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtrainer\u001b[38;5;241m.\u001b[39mbatch_size,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 148\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[1;32m 149\u001b[0m )\n\u001b[0;32m--> 151\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtrainer\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 152\u001b[0m \u001b[43m \u001b[49m\u001b[43mnet\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtrained_net\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 153\u001b[0m \u001b[43m \u001b[49m\u001b[43mtrain_iter\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtraining_data_loader\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 154\u001b[0m \u001b[43m \u001b[49m\u001b[43mvalidation_iter\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mvalidation_data_loader\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 155\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 157\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m TrainOutput(\n\u001b[1;32m 158\u001b[0m transformation\u001b[38;5;241m=\u001b[39mtransformation,\n\u001b[1;32m 159\u001b[0m trained_net\u001b[38;5;241m=\u001b[39mtrained_net,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 162\u001b[0m ),\n\u001b[1;32m 163\u001b[0m )\n",
|
|
"File \u001b[0;32m/media/wassname/SGIronWolf/projects5/timeseries/pytorch-ts/pts/trainer.py:67\u001b[0m, in \u001b[0;36mTrainer.__call__\u001b[0;34m(self, net, train_iter, validation_iter)\u001b[0m\n\u001b[1;32m 64\u001b[0m optimizer\u001b[38;5;241m.\u001b[39mzero_grad()\n\u001b[1;32m 66\u001b[0m inputs \u001b[38;5;241m=\u001b[39m [v\u001b[38;5;241m.\u001b[39mto(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdevice) \u001b[38;5;28;01mfor\u001b[39;00m v \u001b[38;5;129;01min\u001b[39;00m data_entry\u001b[38;5;241m.\u001b[39mvalues()]\n\u001b[0;32m---> 67\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[43mnet\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43minputs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 69\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(output, (\u001b[38;5;28mlist\u001b[39m, \u001b[38;5;28mtuple\u001b[39m)):\n\u001b[1;32m 70\u001b[0m loss \u001b[38;5;241m=\u001b[39m output[\u001b[38;5;241m0\u001b[39m]\n",
|
|
"File \u001b[0;32m~/miniforge3/envs/glounts/lib/python3.9/site-packages/torch/nn/modules/module.py:1190\u001b[0m, in \u001b[0;36mModule._call_impl\u001b[0;34m(self, *input, **kwargs)\u001b[0m\n\u001b[1;32m 1186\u001b[0m \u001b[38;5;66;03m# If we don't have any hooks, we want to skip the rest of the logic in\u001b[39;00m\n\u001b[1;32m 1187\u001b[0m \u001b[38;5;66;03m# this function, and just call forward.\u001b[39;00m\n\u001b[1;32m 1188\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_backward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_forward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_forward_pre_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_backward_hooks\n\u001b[1;32m 1189\u001b[0m \u001b[38;5;129;01mor\u001b[39;00m _global_forward_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_forward_pre_hooks):\n\u001b[0;32m-> 1190\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mforward_call\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1191\u001b[0m \u001b[38;5;66;03m# Do not call functions when jit is used\u001b[39;00m\n\u001b[1;32m 1192\u001b[0m full_backward_hooks, non_full_backward_hooks \u001b[38;5;241m=\u001b[39m [], []\n",
|
|
"File \u001b[0;32m/media/wassname/SGIronWolf/projects5/timeseries/pytorch-ts/pts/model/time_grad2/time_grad_network.py:407\u001b[0m, in \u001b[0;36mTimeGradTrainingNetwork2.forward\u001b[0;34m(self, target_dimension_indicator, past_time_feat, past_target_cdf, past_observed_values, past_is_pad, future_time_feat, future_target_cdf, future_observed_values)\u001b[0m\n\u001b[1;32m 405\u001b[0m target \u001b[38;5;241m=\u001b[39m target\u001b[38;5;241m.\u001b[39mpermute(\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m 406\u001b[0m distr_args \u001b[38;5;241m=\u001b[39m distr_args\u001b[38;5;241m.\u001b[39mpermute(\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m--> 407\u001b[0m likelihoods \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdiffusion\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlog_prob\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtarget\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdistr_args\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39munsqueeze(\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m 409\u001b[0m \u001b[38;5;66;03m# assert_shape(likelihoods, (-1, seq_len, 1))\u001b[39;00m\n\u001b[1;32m 411\u001b[0m past_observed_values \u001b[38;5;241m=\u001b[39m torch\u001b[38;5;241m.\u001b[39mmin(\n\u001b[1;32m 412\u001b[0m past_observed_values, \u001b[38;5;241m1\u001b[39m \u001b[38;5;241m-\u001b[39m past_is_pad\u001b[38;5;241m.\u001b[39munsqueeze(\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m 413\u001b[0m )\n",
|
|
"File \u001b[0;32m/media/wassname/SGIronWolf/projects5/timeseries/pytorch-ts/pts/model/time_grad2/gaussian_diffusion_ou.py:298\u001b[0m, in \u001b[0;36mGaussianDiffusionOU.log_prob\u001b[0;34m(self, x, cond, *args, **kwargs)\u001b[0m\n\u001b[1;32m 295\u001b[0m B, T, _ \u001b[38;5;241m=\u001b[39m x\u001b[38;5;241m.\u001b[39mshape\n\u001b[1;32m 297\u001b[0m time \u001b[38;5;241m=\u001b[39m torch\u001b[38;5;241m.\u001b[39mrandint(\u001b[38;5;241m0\u001b[39m, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnum_timesteps, (B,), device\u001b[38;5;241m=\u001b[39mx\u001b[38;5;241m.\u001b[39mdevice)\u001b[38;5;241m.\u001b[39mlong()\n\u001b[0;32m--> 298\u001b[0m loss \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mp_losses\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 299\u001b[0m \u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcond\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtime\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[1;32m 300\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 302\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m loss\n",
|
|
"File \u001b[0;32m/media/wassname/SGIronWolf/projects5/timeseries/pytorch-ts/pts/model/time_grad2/gaussian_diffusion_ou.py:283\u001b[0m, in \u001b[0;36mGaussianDiffusionOU.p_losses\u001b[0;34m(self, x_start, cond, t)\u001b[0m\n\u001b[1;32m 281\u001b[0m loss \u001b[38;5;241m=\u001b[39m F\u001b[38;5;241m.\u001b[39ml1_loss(x_recon, noise_rand)\n\u001b[1;32m 282\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mloss_type \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ml2\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m--> 283\u001b[0m loss \u001b[38;5;241m=\u001b[39m \u001b[43mF\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmse_loss\u001b[49m\u001b[43m(\u001b[49m\u001b[43mx_recon\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnoise_rand\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 284\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mloss_type \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhuber\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 285\u001b[0m loss \u001b[38;5;241m=\u001b[39m F\u001b[38;5;241m.\u001b[39msmooth_l1_loss(x_recon, noise_rand)\n",
|
|
"File \u001b[0;32m~/miniforge3/envs/glounts/lib/python3.9/site-packages/torch/nn/functional.py:3291\u001b[0m, in \u001b[0;36mmse_loss\u001b[0;34m(input, target, size_average, reduce, reduction)\u001b[0m\n\u001b[1;32m 3288\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m size_average \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m reduce \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 3289\u001b[0m reduction \u001b[38;5;241m=\u001b[39m _Reduction\u001b[38;5;241m.\u001b[39mlegacy_get_string(size_average, reduce)\n\u001b[0;32m-> 3291\u001b[0m expanded_input, expanded_target \u001b[38;5;241m=\u001b[39m \u001b[43mtorch\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbroadcast_tensors\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtarget\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3292\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m torch\u001b[38;5;241m.\u001b[39m_C\u001b[38;5;241m.\u001b[39m_nn\u001b[38;5;241m.\u001b[39mmse_loss(expanded_input, expanded_target, _Reduction\u001b[38;5;241m.\u001b[39mget_enum(reduction))\n",
|
|
"File \u001b[0;32m~/miniforge3/envs/glounts/lib/python3.9/site-packages/torch/functional.py:74\u001b[0m, in \u001b[0;36mbroadcast_tensors\u001b[0;34m(*tensors)\u001b[0m\n\u001b[1;32m 72\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m has_torch_function(tensors):\n\u001b[1;32m 73\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m handle_torch_function(broadcast_tensors, tensors, \u001b[38;5;241m*\u001b[39mtensors)\n\u001b[0;32m---> 74\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_VF\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbroadcast_tensors\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtensors\u001b[49m\u001b[43m)\u001b[49m\n",
|
|
"\u001b[0;31mRuntimeError\u001b[0m: The size of tensor a (46) must match the size of tensor b (48) at non-singleton dimension 2"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"predictor = estimator.train(dataset_train, num_workers=0)\n",
|
|
"# predictor = estimator.train(dataset_train, num_workers=8)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"start_time": "2022-12-23T06:33:31.564Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"> \u001b[0;32m/home/wassname/miniforge3/envs/glounts/lib/python3.9/site-packages/torch/functional.py\u001b[0m(74)\u001b[0;36mbroadcast_tensors\u001b[0;34m()\u001b[0m\n",
|
|
"\u001b[0;32m 72 \u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0mhas_torch_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtensors\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m 73 \u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mhandle_torch_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbroadcast_tensors\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtensors\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0mtensors\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m---> 74 \u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0m_VF\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbroadcast_tensors\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtensors\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# type: ignore[attr-defined]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m 75 \u001b[0;31m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m 76 \u001b[0;31m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\n",
|
|
"ipdb> u\n",
|
|
"> \u001b[0;32m/home/wassname/miniforge3/envs/glounts/lib/python3.9/site-packages/torch/nn/functional.py\u001b[0m(3291)\u001b[0;36mmse_loss\u001b[0;34m()\u001b[0m\n",
|
|
"\u001b[0;32m 3289 \u001b[0;31m \u001b[0mreduction\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_Reduction\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlegacy_get_string\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msize_average\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreduce\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m 3290 \u001b[0;31m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m-> 3291 \u001b[0;31m \u001b[0mexpanded_input\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexpanded_target\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbroadcast_tensors\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtarget\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m 3292 \u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_C\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_nn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmse_loss\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mexpanded_input\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexpanded_target\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_Reduction\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_enum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreduction\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m 3293 \u001b[0;31m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\n",
|
|
"ipdb> u\n",
|
|
"> \u001b[0;32m/media/wassname/SGIronWolf/projects5/timeseries/pytorch-ts/pts/model/time_grad2/gaussian_diffusion_ou.py\u001b[0m(283)\u001b[0;36mp_losses\u001b[0;34m()\u001b[0m\n",
|
|
"\u001b[0;32m 281 \u001b[0;31m \u001b[0mloss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mF\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0ml1_loss\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_recon\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnoise_rand\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m 282 \u001b[0;31m \u001b[0;32melif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloss_type\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"l2\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m--> 283 \u001b[0;31m \u001b[0mloss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mF\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmse_loss\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_recon\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnoise_rand\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m 284 \u001b[0;31m \u001b[0;32melif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloss_type\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"huber\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m 285 \u001b[0;31m \u001b[0mloss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mF\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msmooth_l1_loss\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_recon\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnoise_rand\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\n",
|
|
"ipdb> u\n",
|
|
"> \u001b[0;32m/media/wassname/SGIronWolf/projects5/timeseries/pytorch-ts/pts/model/time_grad2/gaussian_diffusion_ou.py\u001b[0m(298)\u001b[0;36mlog_prob\u001b[0;34m()\u001b[0m\n",
|
|
"\u001b[0;32m 296 \u001b[0;31m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m 297 \u001b[0;31m \u001b[0mtime\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnum_timesteps\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mB\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlong\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m--> 298 \u001b[0;31m loss = self.p_losses(\n",
|
|
"\u001b[0m\u001b[0;32m 299 \u001b[0;31m \u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcond\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0m\u001b[0;32m 300 \u001b[0;31m )\n",
|
|
"\u001b[0m\n",
|
|
"ipdb> x.shape\n",
|
|
"torch.Size([64, 370, 48])\n",
|
|
"ipdb> cond.shape\n",
|
|
"torch.Size([64, 100, 48])\n",
|
|
"ipdb> time.shape\n",
|
|
"torch.Size([64])\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"%debug"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.613548Z",
|
|
"start_time": "2022-12-23T06:21:12.613540Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"forecast_it, ts_it = make_evaluation_predictions(dataset=dataset_test,\n",
|
|
" predictor=predictor,\n",
|
|
" num_samples=100)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.614197Z",
|
|
"start_time": "2022-12-23T06:21:12.614190Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"forecasts = list(forecast_it)\n",
|
|
"targets = list(ts_it)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.614817Z",
|
|
"start_time": "2022-12-23T06:21:12.614810Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"plot(\n",
|
|
" target=targets[0],\n",
|
|
" forecast=forecasts[0],\n",
|
|
" prediction_length=dataset.metadata.prediction_length,\n",
|
|
")\n",
|
|
"plt.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.615375Z",
|
|
"start_time": "2022-12-23T06:21:12.615368Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"evaluator = MultivariateEvaluator(quantiles=(np.arange(20)/20.0)[1:], \n",
|
|
" target_agg_funcs={'sum': np.sum})"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.615882Z",
|
|
"start_time": "2022-12-23T06:21:12.615875Z"
|
|
},
|
|
"scrolled": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"agg_metric, item_metrics = evaluator(targets, forecasts, num_series=len(dataset_test))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.616531Z",
|
|
"start_time": "2022-12-23T06:21:12.616525Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"print(\"CRPS:\", agg_metric[\"mean_wQuantileLoss\"])\n",
|
|
"print(\"ND:\", agg_metric[\"ND\"])\n",
|
|
"print(\"NRMSE:\", agg_metric[\"NRMSE\"])\n",
|
|
"print(\"\")\n",
|
|
"print(\"CRPS-Sum:\", agg_metric[\"m_sum_mean_wQuantileLoss\"])\n",
|
|
"print(\"ND-Sum:\", agg_metric[\"m_sum_ND\"])\n",
|
|
"print(\"NRMSE-Sum:\", agg_metric[\"m_sum_NRMSE\"])"
|
|
]
|
|
},
|
|
{
|
|
"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": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Scratch: debug transforms\n",
|
|
"\n",
|
|
"See estimator"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.617247Z",
|
|
"start_time": "2022-12-23T06:21:12.617240Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"predictor = estimator.train(dataset_train, num_workers=0)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.617846Z",
|
|
"start_time": "2022-12-23T06:21:12.617838Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"%debug"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.618406Z",
|
|
"start_time": "2022-12-23T06:21:12.618396Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from tqdm.auto import tqdm"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.619142Z",
|
|
"start_time": "2022-12-23T06:21:12.619132Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"transformation = estimator.create_transformation()\n",
|
|
"training_instance_splitter = estimator.create_instance_splitter(\"training\")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.619649Z",
|
|
"start_time": "2022-12-23T06:21:12.619642Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"g1 = trans.apply(dataset_train, is_train=True)\n",
|
|
"b = next(iter(g1))\n",
|
|
"b.keys()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.620194Z",
|
|
"start_time": "2022-12-23T06:21:12.620187Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"for _ in tqdm(g1):\n",
|
|
" pass"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.620996Z",
|
|
"start_time": "2022-12-23T06:21:12.620988Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"transform = transformation + training_instance_splitter\n",
|
|
"g2 = transform.apply(dataset_train, is_train=True)\n",
|
|
"gg = iter(g2)\n",
|
|
"b = next(gg)\n",
|
|
"b.keys()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.621464Z",
|
|
"start_time": "2022-12-23T06:21:12.621458Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"for _ in tqdm(g2):\n",
|
|
" pass"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.622209Z",
|
|
"start_time": "2022-12-23T06:21:12.622202Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"b = next(gg)\n",
|
|
"b.keys()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.622763Z",
|
|
"start_time": "2022-12-23T06:21:12.622756Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from pts.model import get_module_forward_input_names\n",
|
|
"from gluonts.transform import SelectFields, Transformation\n",
|
|
"\n",
|
|
"trained_net = estimator.create_training_network(estimator.trainer.device)\n",
|
|
"input_names = get_module_forward_input_names(trained_net)\n",
|
|
"transform = transformation + training_instance_splitter + SelectFields(input_names)\n",
|
|
"g = transform.apply(dataset_train, is_train=True)\n",
|
|
"b = next(iter(g))\n",
|
|
"b.keys()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T05:18:19.966830Z",
|
|
"start_time": "2022-12-23T05:18:19.964901Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.623279Z",
|
|
"start_time": "2022-12-23T06:21:12.623272Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from pts.dataset.loader import TransformedIterableDataset\n",
|
|
"training_data = dataset_train\n",
|
|
"training_iter_dataset = TransformedIterableDataset(\n",
|
|
" dataset=training_data,\n",
|
|
" transform=transformation\n",
|
|
" + training_instance_splitter\n",
|
|
" + SelectFields(input_names),\n",
|
|
" is_train=True,\n",
|
|
" shuffle_buffer_length=None,\n",
|
|
"# cache_data=cache_data,\n",
|
|
")\n",
|
|
"training_iter_dataset"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.623864Z",
|
|
"start_time": "2022-12-23T06:21:12.623857Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"next(iter(training_iter_dataset))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.624379Z",
|
|
"start_time": "2022-12-23T06:21:12.624372Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from torch.utils.data import DataLoader\n",
|
|
"training_data_loader = DataLoader(\n",
|
|
" training_iter_dataset,\n",
|
|
" batch_size=estimator.trainer.batch_size,\n",
|
|
" num_workers=0,\n",
|
|
"# prefetch_factor=prefetch_factor,\n",
|
|
" pin_memory=True,\n",
|
|
" worker_init_fn=estimator._worker_init_fn,\n",
|
|
"# **kwargs,\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.624842Z",
|
|
"start_time": "2022-12-23T06:21:12.624836Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"next(iter(training_data_loader))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2022-12-23T06:21:12.625415Z",
|
|
"start_time": "2022-12-23T06:21:12.625408Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"for b in tqdm(training_data_loader):\n",
|
|
" pass"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "glounts",
|
|
"language": "python",
|
|
"name": "glounts"
|
|
},
|
|
"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.9.15"
|
|
},
|
|
"toc": {
|
|
"base_numbering": 1,
|
|
"nav_menu": {},
|
|
"number_sections": true,
|
|
"sideBar": true,
|
|
"skip_h1_title": false,
|
|
"title_cell": "Table of Contents",
|
|
"title_sidebar": "Contents",
|
|
"toc_cell": false,
|
|
"toc_position": {},
|
|
"toc_section_display": true,
|
|
"toc_window_display": true
|
|
},
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "7f25a1f13147a60511cf6766827402baf95cbe50d53a241197155306ee38fe70"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|