TorchSpatiotemporal / tsl

tsl: a PyTorch library for processing spatiotemporal data.
https://torch-spatiotemporal.readthedocs.io/
MIT License
267 stars 24 forks source link

Reconstruction of the time series after predict #7

Closed ucsky closed 2 years ago

ucsky commented 2 years ago

Hello,

I try to reconstruct the final time series after imputation as it is done in figure 3 of https://arxiv.org/pdf/2108.00298.pdf.

Do you have an utility function or method in tsl package for this?

Cheers, Guillaume

marshka commented 2 years ago

Hi Guillaume,

if I understood correctly, you want a way to split a long sequence in windows, reconstruct missing values inside each window, and then re-aggregate imputed windows together. If this is the case, then tsl.ops.imputation.prediction_dataframe could fit. It takes as input a batch of windows paired with the corresponding time index and aggregates them in a single DataFrame according to the specified method. Among the methods, you can find 'mean' to take the average over windows or 'central' to take the imputation from the window in which the missing value was in a central position.

This method was used by us to generate imputations "in-sample" in the GRIN paper and has been just copied in tsl. We will improve it in the next versions of the library.

I hope I helped you.

Best,

Ivan

ucsky commented 2 years ago

Hi Ivan,

Thanks, that is what I need. I just did a slight modification in order to handle multiple channels:

   dfs = [
        pd.DataFrame(
            data=data.reshape(data.shape[0], data.shape[1]*data.shape[2]),
            index=idx,
            columns=columns)
        for data, idx in zip(y, index)]

Cheers, Guillaume