Skip to content

Commit

Permalink
Merge pull request #724 from AIStream-Peelout/fix_bugs_series_id
Browse files Browse the repository at this point in the history
Fix bugs series
  • Loading branch information
isaacmg authored Jan 11, 2024
2 parents 2a79afa + b5f95f9 commit 033e84c
Show file tree
Hide file tree
Showing 10 changed files with 6,340 additions and 18 deletions.
2 changes: 2 additions & 0 deletions flood_forecast/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ def handle_later_ev(model, df_train_and_test, end_tensor, params, csv_test_loade
if num_prediction_samples is not None:
model.model.train() # sets mode to train so the dropout layers will be touched
assert num_prediction_samples > 0
if csv_test_loader.__class__.__name__ == "SeriesIDTestLoader":
raise NotImplementedError("SeriesIDTestLoader not yet supported for predictions.")
prediction_samples = generate_prediction_samples(
model,
df_train_and_test,
Expand Down
15 changes: 8 additions & 7 deletions flood_forecast/preprocessing/pytorch_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,12 @@ def __getitem__(self, idx: int) -> Tuple[Dict, Dict]:
targ_list = {}
for va in self.listed_vals:
# We need to exclude the index column on one end and the series id column on the other
t = torch.Tensor(va.iloc[idx: self.forecast_history + idx].values)[:, 1:-1]
print(t.shape)

targ_start_idx = idx + self.forecast_history
idx2 = va[self.series_id_col].iloc[0]
targ = torch.Tensor(va.iloc[targ_start_idx: targ_start_idx + self.forecast_length].to_numpy())[:, 1:-1]
va_returned = va[va.columns.difference([self.series_id_col], sort=False)]
t = torch.Tensor(va_returned.iloc[idx: self.forecast_history + idx].values)[:, 1:]
targ = torch.Tensor(va_returned.iloc[targ_start_idx: targ_start_idx + self.forecast_length].to_numpy())[:, 1:] # noqa
src_list[self.unique_dict[idx2]] = t
targ_list[self.unique_dict[idx2]] = targ
return src_list, targ_list
Expand All @@ -249,7 +250,7 @@ def __len__(self) -> int:
if self.return_all_series:
return len(self.listed_vals[0]) - self.forecast_history - self.forecast_length - 1
else:
raise NotImplementedError("Current code only supports returning all the series at each iteration")
raise NotImplementedError("Current code only supports returning all the series at once at each iteration")


class CSVTestLoader(CSVDataLoader):
Expand Down Expand Up @@ -667,11 +668,11 @@ class SeriesIDTestLoader(CSVSeriesIDLoader):
def __init__(self, series_id_col: str, main_params: dict, return_method: str, forecast_total=336, return_all=True):
"""_summary_
:param series_id_col: _de
:param series_id_col: The column that contains the series_id
:type series_id_col: str
:param main_params: _description_
:param main_params: The core params used to instantiate the CSVSeriesIDLoader
:type main_params: dict
:param return_method: _description_
:param return_method: _description_D
:type return_method: str
:param return_all: _description_, defaults to True
:type return_all: bool, optional
Expand Down
4 changes: 2 additions & 2 deletions flood_forecast/temporal_decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def decoding_function(model, src: torch.Tensor, trg: torch.Tensor, forecast_leng
"""This function is responsible for decoding models that use `TemporalLoader` data. The basic logic of this
function is as follows. The data to the encoder (e.g. src) is not modified at each step of the decoding process.
Instead only the data to the decoder (e.g. the masked trg) is changed when forecasting max_len > forecast_length.
New data is appended (forecast_len == 2) (decoder_seq==10) (max==20) (20 (8)->2 First 8 should
New data is appended (forecast_len == 2) (decoder_seq==10) (max==20) (20 (8)->2 First 8 should be the same).
:param model: The PyTorch time series forecasting model that you want to use forecasting on.
:type model: `torch.nn.Module`
Expand All @@ -28,7 +28,7 @@ def decoding_function(model, src: torch.Tensor, trg: torch.Tensor, forecast_leng
:type unknown_cols_st: List[str]
:param decoder_seq_len: The length of the sequence passed into the decoder
:type decoder_seq_len: int
:param max_len: The total number of time steps to forecast
:param max_len: The total number of time steps to forecas
:type max_len: int
:return: The forecasted values of shape (batch_size, max_len, n_targets)
:rtype: torch.Tensor
Expand Down
2 changes: 1 addition & 1 deletion flood_forecast/transformer_xl/cross_former.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
:param baseline: _description_, defaults to False
:type baseline: bool, optional
:param device: _description_, defaults to torch.device("cuda:0")
:type device: _type_, optional
:type device: str, optional
"""
super(Crossformer, self).__init__()
self.data_dim = n_time_series
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name='flood_forecast',
version='1.000000dev',
version='1.00dev',
packages=[
'flood_forecast',
'flood_forecast.transformer_xl',
Expand Down
Loading

0 comments on commit 033e84c

Please sign in to comment.