From b610397433d4df41b35a4e867e65e6b92e51c1aa Mon Sep 17 00:00:00 2001 From: Wenjie Du Date: Sun, 14 Apr 2024 17:45:48 +0800 Subject: [PATCH] refactor: remove locf.modules and add assertions in bttf.core; --- pypots/forecasting/bttf/core.py | 5 +++++ pypots/imputation/locf/{modules => }/core.py | 0 pypots/imputation/locf/model.py | 5 +++-- pypots/imputation/locf/modules/__init__.py | 6 ------ 4 files changed, 8 insertions(+), 8 deletions(-) rename pypots/imputation/locf/{modules => }/core.py (100%) delete mode 100644 pypots/imputation/locf/modules/__init__.py diff --git a/pypots/forecasting/bttf/core.py b/pypots/forecasting/bttf/core.py index fb232e2e..ffd8ef67 100644 --- a/pypots/forecasting/bttf/core.py +++ b/pypots/forecasting/bttf/core.py @@ -218,6 +218,11 @@ def BTTF_forecast( ): dim1, dim2, T = dense_tensor.shape start_time = T - pred_step + assert start_time > -1, ( + "start_time should be larger than -1, " + "namely the number of the input tensor's time steps should be larger than pred_step." + ) + assert start_time >= np.max(time_lags), "start_time should be >= max(time_lags)" max_count = int(np.ceil(pred_step / multi_step)) tensor_hat = np.zeros((dim1, dim2, max_count * multi_step)) diff --git a/pypots/imputation/locf/modules/core.py b/pypots/imputation/locf/core.py similarity index 100% rename from pypots/imputation/locf/modules/core.py rename to pypots/imputation/locf/core.py diff --git a/pypots/imputation/locf/model.py b/pypots/imputation/locf/model.py index f634f87f..e7c47366 100644 --- a/pypots/imputation/locf/model.py +++ b/pypots/imputation/locf/model.py @@ -13,14 +13,15 @@ import numpy as np import torch -from .modules.core import locf_numpy, locf_torch +from .core import locf_numpy, locf_torch from ..base import BaseImputer from ...utils.logging import logger class LOCF(BaseImputer): """LOCF (Last Observed Carried Forward) imputation method. A naive imputation method that fills missing values - with the last observed value. Simple but commonly used in practice. + with the last observed value. When time-series data gets inverse on the time dimension, this method can also be + seen as NOCB (Next Observation Carried Backward). Simple but commonly used in practice. Parameters ---------- diff --git a/pypots/imputation/locf/modules/__init__.py b/pypots/imputation/locf/modules/__init__.py deleted file mode 100644 index ceaa7ee3..00000000 --- a/pypots/imputation/locf/modules/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -""" - -""" - -# Created by Wenjie Du -# License: BSD-3-Clause