Skip to main content

No project description provided

Project description

Forecastblurdenoise Package

Forecastblurdenoise is the PyTorch-based package for the research paper Fine-grained Forecasting Models Via Gaussian Process Blurring Effect.

Methodology: The core methodology involves training the blur model parameters end-to-end with forecasting and denoising components. This unique approach enables the underlying forecasting model to learn coarse-grained patterns, while the denoising forecaster fills in fine-grained details. The results demonstrate significant improvements over state-of-the-art models like Autoformer and Informer.

This package provides:

  • The forecast-blur-denoise framework that can integrate any state-of-the-art neural time series forecasting models as the forecaster and denoiser.
  • Three options for the blur model: Gaussian Process (GP), scaled isotropic noise, and no noise (perform denoising directly on predictions).
  • A data loader module that works with the provided datasets in Google Drive.
  • A forecasting model example (Autoformer
  • Hyperparameter tuning with Optuna.

Datasets

In this repository, we have provided the links to google Drive of six pre-processed datasets in the following link: Datasets

Installation

To install run one of the following:

pip install forecastblurdenoise==1.0.3
conda install sepkfr::forecastblurdenoise

Usage Example

Run Script for a toy dataset example

./example_usage --exp_name toy_data

Command Line Args

- exp_name (str): Name of the experiment (dataset).
- forecating_model_name (str): Name of the forecasting model.
- n_jobs (int): Total number of jobs for Optuna.
- num_epochs (int): Total number of epochs.
- forecasting_model (nn.Module): The underlying forecasting model.
- train (DataLoader): DataLoader for training data.
- valid (DataLoader): DataLoader for validation data.
- test (DataLoader): DataLoader for test data.
- noise_type (str): Type of noise to be added during denoising ('gp', 'iso', 'no_noise').
- add_noise_only_at_training (bool): Flag indicating whether to add noise only during training.
- src_input_size (int): Size of the source input.
- tgt_input_size (int): Size of the target input.
- tgt_output_size (int): Size of the target output.
- pred_len (int): Length of the prediction horizon.
- num_inducing (int): Number of inducing points for GP regression.
- hyperparameters (dict): Hyperparameters to be optimized.
- args: Command line arguments.
- seed (int): Random seed for reproducibility.
- device: Device on which to run the training.

Run as a Library

import torch
from torch.utils.data import DataLoader, TensorDataset
from torch import nn
from forecastblurdenoise.train_forecast_blur_denoise import TrainForecastBlurDenoise

# defining a simple LSTM model

class LSTM(nn.Module):
    def __init__(self, n_layers, hidden_size):
        super(LSTM, self).__init__()

        self.encoder_lstm = nn.LSTM(hidden_size, hidden_size, n_layers)
        self.decoder_lstm = nn.LSTM(hidden_size, hidden_size, n_layers)
        self.n_layers = n_layers
        self.hidden_size = hidden_size

    def forward(self, input_encoder, input_decoder):

        enc_outputs, _ = self.encoder_lstm(input_encoder)
        dec_outputs, _ = self.encoder_lstm(input_decoder)
        return enc_outputs, dec_outputs

# Create a toy dataset
def create_time_series_data(num_samples,
                            input_sequence_length,
                            output_sequence_length,
                            input_size,
                            output_size,
                            device):
    # input for encoder, input for decoder, and output (ground-truth)
    return TensorDataset(torch.randn(num_samples, input_sequence_length, input_size, device=device),
                         torch.randn(num_samples, output_sequence_length, input_size, device=device),
                         torch.randn(num_samples, output_sequence_length, output_size, device=device))


# setting parameters
num_samples_train = 32
num_samples_valid = 8
num_samples_test = 8
input_sequence_length = 96
output_sequence_length = 96
batch_size = 4
input_size = 5
output_size = 1
cuda = "cuda:0"

device = torch.device(cuda if torch.cuda.is_available() else "cpu")

train_dataset = create_time_series_data(num_samples_train, input_sequence_length,
                                        output_sequence_length, input_size, output_size,
                                        device)
valid_dataset = create_time_series_data(num_samples_valid, input_sequence_length,
                                        output_sequence_length, input_size, output_size,
                                        device)
test_dataset = create_time_series_data(num_samples_test, input_sequence_length,
                                       output_sequence_length, input_size, output_size,
                                       device)

train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True)
valid_loader = DataLoader(valid_dataset, batch_size=batch_size, shuffle=False)
test_loader = DataLoader(test_dataset, batch_size=batch_size, shuffle=False)

forecasting_model = LSTM(n_layers=1, hidden_size=32)

# Hyperparameter search space (change accordingly)
hyperparameters = {"d_model": [16, 32], "n_layers": [1, 2], "lr": [0.01, 0.001]}

# Initializing and training the ForecastDenoise model using Optuna
trainforecastdenoise = TrainForecastBlurDenoise(forecasting_model=forecasting_model,
                                                train=train_loader,
                                                valid=valid_loader,
                                                test=test_loader,
                                                noise_type="gp",
                                                num_inducing=32,
                                                add_noise_only_at_training=False,
                                                input_size=input_size,
                                                output_size=output_size,
                                                pred_len=96,
                                                hyperparameters=hyperparameters,
                                                seed=1234,
                                                device=device)
# train the forecast blur denoise model end-to-end
trainforecastdenoise.train()
# evaluate and save MSE, and MAE results in a csv file as reported_errors_{exp_name}.csv
trainforecastdenoise.evaluate()

Citation

If you are interested in using our forecastblurdenoise model for your forcasting problem, cite our paper as:

@misc{koohfar2023finegrained,
      title={Fine-grained Forecasting Models Via Gaussian Process Blurring Effect}, 
      author={Sepideh Koohfar and Laura Dietz},
      year={2023},
      eprint={2312.14280},
      archivePrefix={arXiv},
      primaryClass={cs.LG}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

forecastblurdenoise-1.0.3.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

forecastblurdenoise-1.0.3-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file forecastblurdenoise-1.0.3.tar.gz.

File metadata

  • Download URL: forecastblurdenoise-1.0.3.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for forecastblurdenoise-1.0.3.tar.gz
Algorithm Hash digest
SHA256 0c5dd2383117b022e21f9c6583ef9c2990e3fd15707fbe6ab038eb5874541030
MD5 f9403978b4f10734e05f9c047175f61a
BLAKE2b-256 ad017b34c86a61d6b45266505469708ea3d838a088ed0590112ada12bcc6c083

See more details on using hashes here.

File details

Details for the file forecastblurdenoise-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for forecastblurdenoise-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 11311c91ed85d0c1acb8f7d1d525b1949218fb0e07037fb7c279d93e757d0a20
MD5 ca0db078c2661acf4c3d998d28785ca2
BLAKE2b-256 5992902eb37e63b9ea5f003d3b9b881460c29e952b6c05b2118ad34a8fba5860

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page