Help with out of bounds error while plotting

I’ve been running into this problems for days with the Pytorch Forcasting package.

Running this code:

for idx in range(10): # plot 10 examples
best_tft.plot_prediction(x, raw_predictions, idx=idx, add_loss_to_title=True);

I get this message:

/usr/local/lib/python3.7/dist-packages/pytorch_forecasting/models/temporal_fusion_transformer/init.py in plot_prediction(self, x, out, idx, plot_attention, add_loss_to_title, show_future_observed, ax, **kwargs)
671 show_future_observed=show_future_observed,
672 ax=ax,
→ 673 **kwargs,
674 )
675

/usr/local/lib/python3.7/dist-packages/pytorch_forecasting/models/base_model.py in plot_prediction(self, x, out, idx, add_loss_to_title, show_future_observed, ax, quantiles_kwargs, prediction_kwargs)
759 ):
760
→ 761 y_all = torch.cat([encoder_target[idx], decoder_target[idx]])
762 max_encoder_length = x[“encoder_lengths”].max()
763 y = torch.cat(

IndexError: index 1 is out of bounds for dimension 0 with size 1

I’m very new at this. If there is more information or code that is needed to trouble shoot, then please let me know. Thanks in advance.

Based on the error message the indexing operation is failing in once of these tensors:

encoder_target[idx]
# or
decoder_target[idx]

make sure the size of the tensors in dim0 is sufficiently large for the index.

Thanks for replying. I saw that you’re a bit of a master at these messages and was hoping you’d reply.

I did figure out the problem. It was just mostly understanding the Pytorch Forecasting library. To run that specific loop, the data needs to more than a single time series. I thought it was choosing different starting time_idx from a single time series, but it’s actually looking for idx=idx from multiple time series data.

Hi, I have the exact same error. Can you please explain more and maybe show the fix? Thank you very much.

Hi, I’m very new at this, literally have only been learning python for the last six months as a self study. so, I don’t think I’m really the best to explain this. I’ll try and explain, but I just wanted to make sure you are also using the Python Forecasting package since I think my experience is very specific to that package.