Skip to content

Commit 033e84c

Browse files
authored
Merge pull request #724 from AIStream-Peelout/fix_bugs_series_id
Fix bugs series
2 parents 2a79afa + b5f95f9 commit 033e84c

File tree

10 files changed

+6340
-18
lines changed

10 files changed

+6340
-18
lines changed

flood_forecast/evaluator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ def handle_later_ev(model, df_train_and_test, end_tensor, params, csv_test_loade
367367
if num_prediction_samples is not None:
368368
model.model.train() # sets mode to train so the dropout layers will be touched
369369
assert num_prediction_samples > 0
370+
if csv_test_loader.__class__.__name__ == "SeriesIDTestLoader":
371+
raise NotImplementedError("SeriesIDTestLoader not yet supported for predictions.")
370372
prediction_samples = generate_prediction_samples(
371373
model,
372374
df_train_and_test,

flood_forecast/preprocessing/pytorch_loaders.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,12 @@ def __getitem__(self, idx: int) -> Tuple[Dict, Dict]:
230230
targ_list = {}
231231
for va in self.listed_vals:
232232
# We need to exclude the index column on one end and the series id column on the other
233-
t = torch.Tensor(va.iloc[idx: self.forecast_history + idx].values)[:, 1:-1]
234-
print(t.shape)
233+
235234
targ_start_idx = idx + self.forecast_history
236235
idx2 = va[self.series_id_col].iloc[0]
237-
targ = torch.Tensor(va.iloc[targ_start_idx: targ_start_idx + self.forecast_length].to_numpy())[:, 1:-1]
236+
va_returned = va[va.columns.difference([self.series_id_col], sort=False)]
237+
t = torch.Tensor(va_returned.iloc[idx: self.forecast_history + idx].values)[:, 1:]
238+
targ = torch.Tensor(va_returned.iloc[targ_start_idx: targ_start_idx + self.forecast_length].to_numpy())[:, 1:] # noqa
238239
src_list[self.unique_dict[idx2]] = t
239240
targ_list[self.unique_dict[idx2]] = targ
240241
return src_list, targ_list
@@ -249,7 +250,7 @@ def __len__(self) -> int:
249250
if self.return_all_series:
250251
return len(self.listed_vals[0]) - self.forecast_history - self.forecast_length - 1
251252
else:
252-
raise NotImplementedError("Current code only supports returning all the series at each iteration")
253+
raise NotImplementedError("Current code only supports returning all the series at once at each iteration")
253254

254255

255256
class CSVTestLoader(CSVDataLoader):
@@ -667,11 +668,11 @@ class SeriesIDTestLoader(CSVSeriesIDLoader):
667668
def __init__(self, series_id_col: str, main_params: dict, return_method: str, forecast_total=336, return_all=True):
668669
"""_summary_
669670
670-
:param series_id_col: _de
671+
:param series_id_col: The column that contains the series_id
671672
:type series_id_col: str
672-
:param main_params: _description_
673+
:param main_params: The core params used to instantiate the CSVSeriesIDLoader
673674
:type main_params: dict
674-
:param return_method: _description_
675+
:param return_method: _description_D
675676
:type return_method: str
676677
:param return_all: _description_, defaults to True
677678
:type return_all: bool, optional

flood_forecast/temporal_decoding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def decoding_function(model, src: torch.Tensor, trg: torch.Tensor, forecast_leng
77
"""This function is responsible for decoding models that use `TemporalLoader` data. The basic logic of this
88
function is as follows. The data to the encoder (e.g. src) is not modified at each step of the decoding process.
99
Instead only the data to the decoder (e.g. the masked trg) is changed when forecasting max_len > forecast_length.
10-
New data is appended (forecast_len == 2) (decoder_seq==10) (max==20) (20 (8)->2 First 8 should
10+
New data is appended (forecast_len == 2) (decoder_seq==10) (max==20) (20 (8)->2 First 8 should be the same).
1111
1212
:param model: The PyTorch time series forecasting model that you want to use forecasting on.
1313
:type model: `torch.nn.Module`
@@ -28,7 +28,7 @@ def decoding_function(model, src: torch.Tensor, trg: torch.Tensor, forecast_leng
2828
:type unknown_cols_st: List[str]
2929
:param decoder_seq_len: The length of the sequence passed into the decoder
3030
:type decoder_seq_len: int
31-
:param max_len: The total number of time steps to forecast
31+
:param max_len: The total number of time steps to forecas
3232
:type max_len: int
3333
:return: The forecasted values of shape (batch_size, max_len, n_targets)
3434
:rtype: torch.Tensor

flood_forecast/transformer_xl/cross_former.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(
4949
:param baseline: _description_, defaults to False
5050
:type baseline: bool, optional
5151
:param device: _description_, defaults to torch.device("cuda:0")
52-
:type device: _type_, optional
52+
:type device: str, optional
5353
"""
5454
super(Crossformer, self).__init__()
5555
self.data_dim = n_time_series

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
setup(
1818
name='flood_forecast',
19-
version='1.000000dev',
19+
version='1.00dev',
2020
packages=[
2121
'flood_forecast',
2222
'flood_forecast.transformer_xl',

0 commit comments

Comments
 (0)