### Install Dependencies for BasisFormer Source: https://github.com/nzl5116190/basisformer/blob/main/README.md Installs all the required Python packages for the BasisFormer project by reading from the 'requirements.txt' file. Ensure you have activated the correct conda environment before running this command. ```bash pip install -r requirements.txt ``` -------------------------------- ### Basis-Channel Attention Block (BCAB) Components (Python) Source: https://context7.com/nzl5116190/basisformer/llms.txt This Python code illustrates the core architecture components of the Basisformer model, specifically the Basis-Channel Attention Block (BCAB) and associated utility modules. It demonstrates initializing a `Coefnet` which stacks BCABs for learning basis-series relationships, and an `MLP_bottle` for dimension reduction. Example forward passes show how learnable basis representations and time series features interact within the network. ```python import torch from utils import Coefnet, BCAB, MLP_bottle # Assuming 'device' is defined # Example: device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # Initialize coefficient network with stacked BCABs # coefnet = Coefnet(blocks=2, d_model=100, heads=16) # Example: Learning basis-series relationships batch_size = 16 num_basis = 10 num_channels = 7 d_model = 100 # Learnable basis representations basis = torch.randn(batch_size, num_basis, d_model) #.to(device) # Time series features series = torch.randn(batch_size, num_channels, d_model) #.to(device) # Forward pass through coefficient network # coef, attns_basis, attns_series = coefnet(basis, series) # coef shape: (batch, heads, channels, num_basis) # Represents attention coefficients for combining basis functions per channel # print(f"Coefficient shape: {coef.shape}") # Expected: (16, 16, 7, 10) # print(f"Number of BCAB layers: {len(attns_basis)}") # Expected: 2 # Bottleneck MLP for dimension reduction mlp_bottle = MLP_bottle(input_len=96, output_len=160, bottleneck=20) x = torch.randn(batch_size, num_channels, 96) x_transformed = mlp_bottle(x) print(f"MLP output shape: {x_transformed.shape}") # Expected: (16, 7, 160) ``` -------------------------------- ### Training Loop with Multiple Losses (PyTorch) Source: https://context7.com/nzl5116190/basisformer/llms.txt Implements a full training loop for a PyTorch model, combining prediction, InfoNCE contrastive, and smoothness losses. It includes setup for directories, logging, optimizer initialization with differential learning rates, validation, TensorBoard logging, checkpointing, and early stopping. ```python import torch import torch.nn as nn from torch.utils.tensorboard import SummaryWriter from adabelief_pytorch import AdaBelief import numpy as np import os import time # Setup directories and logging record_dir = f"records/{args.data_path.split('.')[0]}/features_{args.features}/seq_len{args.seq_len},pred_len{args.pred_len}" os.makedirs(record_dir, exist_ok=True) writer = SummaryWriter(os.path.join(record_dir, 'event')) # Initialize optimizer with different learning rates for mapping layers para1 = [param for name, param in model.named_parameters() if 'map_MLP' in name] para2 = [param for name, param in model.named_parameters() if 'map_MLP' not in name] optimizer = AdaBelief( [{'params': para1, 'lr': 5e-3}, {'params': para2, 'lr': 5e-4}], eps=1e-16, betas=(0.9, 0.999), weight_decouple=True, rectify=False ) criterion = nn.MSELoss() train_epochs = 100 patience = 3 # Early stopping patience loss_weight_prediction = 1.0 loss_weight_infonce = 1.0 loss_weight_smooth = 1.0 best_loss = float('inf') patience_count = 0 for epoch in range(train_epochs): model.train() train_losses = [] epoch_time = time.time() for i, (batch_x, batch_y, batch_x_mark, batch_y_mark, index) in enumerate(train_loader): optimizer.zero_grad() # Move to device batch_x = batch_x.float().to(device) batch_y = batch_y.float().to(device) batch_y_mark = batch_y_mark.float().to(device) # Extract prediction target (last pred_len timesteps) f_dim = -1 if args.features == 'MS' else 0 batch_y_target = batch_y[:, -args.pred_len:, f_dim:].to(device) # Forward pass outputs, loss_infonce, loss_smooth, _, _, _, _ = model( batch_x, index.float().to(device), batch_y_target, y_mark=batch_y_mark ) # Compute combined loss loss_pred = criterion(outputs, batch_y_target) loss = (loss_weight_prediction * loss_pred + loss_weight_infonce * loss_infonce + loss_weight_smooth * loss_smooth) train_losses.append(loss.item()) loss.backward() optimizer.step() train_loss = np.mean(train_losses) epoch_time = time.time() - epoch_time print(f"Epoch {epoch+1}/{train_epochs} | Train Loss: {train_loss:.7f} | Time: {epoch_time:.2f}s") # Validation model.eval() vali_losses = [] with torch.no_grad(): for batch_x, batch_y, batch_x_mark, batch_y_mark, index in vali_loader: batch_x = batch_x.float().to(device) batch_y = batch_y.float().to(device) batch_y_mark = batch_y_mark.float().to(device) f_dim = -1 if args.features == 'MS' else 0 batch_y_target = batch_y[:, -args.pred_len:, f_dim:].to(device) outputs, _, _, _, _, _, _ = model( batch_x, index.float().to(device), batch_y_target, train=False, y_mark=batch_y_mark ) loss = criterion(outputs, batch_y_target) vali_losses.append(loss.item()) vali_loss = np.mean(vali_losses) print(f"Validation Loss: {vali_loss:.7f}") # Logging writer.add_scalar('train_loss', train_loss, epoch) writer.add_scalar('vali_loss', vali_loss, epoch) # Checkpointing ckpt_path = os.path.join(record_dir, 'checkpoint') os.makedirs(ckpt_path, exist_ok=True) if vali_loss < best_loss: best_loss = vali_loss torch.save(model.state_dict(), os.path.join(ckpt_path, 'valid_best_checkpoint.pth')) patience_count = 0 print(f"Best model saved with validation loss: {best_loss:.7f}") else: patience_count += 1 torch.save(model.state_dict(), os.path.join(ckpt_path, 'final_checkpoint.pth')) # Early stopping if patience_count >= patience: print(f"Early stopping at epoch {epoch+1}") break writer.close() ``` -------------------------------- ### Custom Dataset Integration for Basisformer (Python) Source: https://context7.com/nzl5116190/basisformer/llms.txt This Python script shows how to prepare and load a custom CSV time series dataset for the Basisformer model. It includes steps for creating a sample CSV file with required columns ('date', features, target) and then demonstrating how to instantiate the `Dataset_Custom` class and a `DataLoader` for training. It also shows how to initialize the Basisformer model in multivariate input, univariate output ('MS') mode. ```python import pandas as pd import numpy as np from data_provider.data_loader import Dataset_Custom from torch.utils.data import DataLoader # Prepare custom dataset CSV # Required format: 'date' column + feature columns + target column data = { 'date': pd.date_range('2020-01-01', periods=1000, freq='H'), 'feature1': np.random.randn(1000), 'feature2': np.random.randn(1000), 'feature3': np.random.randn(1000), 'target': np.random.randn(1000) } df = pd.DataFrame(data) df.to_csv('all_six_datasets/custom/my_data.csv', index=False) # Load custom dataset class CustomArgs: def __init__(self): self.root_path = 'all_six_datasets/custom' self.data_path = 'my_data.csv' self.features = 'MS' # Multivariate input, univariate output self.target = 'target' self.seq_len = 96 self.label_len = 96 self.pred_len = 96 self.freq = 'h' self.embed = 'timeF' self.input_channel = 3 # Number of input features custom_args = CustomArgs() # Create dataset dataset = Dataset_Custom( root_path=custom_args.root_path, data_path=custom_args.data_path, flag='train', size=[custom_args.seq_len, custom_args.label_len, custom_args.pred_len], features=custom_args.features, target=custom_args.target, scale=True, # Apply StandardScaler timeenc=1, # Use time features from timefeatures.py freq=custom_args.freq ) dataloader = DataLoader(dataset, batch_size=32, shuffle=True, num_workers=0) # Initialize model for MS forecasting # Assuming 'device' and 'Basisformer' are defined elsewhere # model_ms = Basisformer( # seq_len=96, pred_len=96, d_model=100, heads=16, # basis_nums=10, block_nums=2, bottle=2, map_bottleneck=20, # device=device, tau=0.07, # is_MS=True, input_channel=3 # Enable MS mode # ).to(device) print(f"Dataset samples: {len(dataset)}") print(f"Data splits: 70% train, 10% val, 20% test") ``` -------------------------------- ### Initialize BasisFormer Model for Multivariate Forecasting Source: https://context7.com/nzl5116190/basisformer/llms.txt Initializes a BasisFormer model with specified architecture parameters for multivariate time series forecasting. The model supports both training and inference modes. It requires PyTorch and the Basisformer class from the model module. Inputs include sequence length, prediction length, model dimensions, attention heads, number of basis functions, blocks, bottleneck factors, and device. Outputs are the model predictions and various loss components during training. ```python import torch from model import Basisformer # Configuration parameters seq_len = 96 # Input sequence length pred_len = 96 # Prediction horizon d_model = 100 # Model dimension heads = 16 # Number of attention heads N = 10 # Number of learnable basis functions block_nums = 2 # Number of BCAB blocks bottleneck = 2 # Bottleneck reduction factor map_bottleneck = 20 # Mapping bottleneck size tau = 0.07 # Temperature for InfoNCE loss device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu') # Initialize model for multivariate forecasting (M mode) model = Basisformer( seq_len=seq_len, pred_len=pred_len, d_model=d_model, heads=heads, basis_nums=N, block_nums=block_nums, bottle=bottleneck, map_bottleneck=map_bottleneck, device=device, tau=tau, is_MS=False, # Set True for multivariate-to-univariate input_channel=0 # Required if is_MS=True ) model.to(device) # Example forward pass during training batch_size = 32 channels = 7 x = torch.randn(batch_size, seq_len, channels).to(device) # Input sequence y = torch.randn(batch_size, pred_len, channels).to(device) # Target sequence mark = torch.randn(batch_size, seq_len + pred_len).to(device) # Temporal index y_mark = torch.randn(batch_size, pred_len, 4).to(device) # Time features # Forward pass returns predictions and losses output, loss_infonce, loss_smooth, attn_x1, attn_x2, attn_y1, attn_y2 = model( x, mark, y, train=True, y_mark=y_mark ) print(f"Prediction shape: {output.shape}") # (32, 96, 7) print(f"InfoNCE loss: {loss_infonce.item():.4f}") print(f"Smooth loss: {loss_smooth.item():.4f}") ``` -------------------------------- ### Load Basisformer Model and Perform Inference (PyTorch) Source: https://context7.com/nzl5116190/basisformer/llms.txt Loads a pre-trained Basisformer model, prepares input time series data, and performs inference to generate forecasts. It utilizes PyTorch for model handling and computation, requiring the 'torch' library. The input consists of a sequence, temporal index, and dummy target, outputting predictions and attention weights. ```python import torch # Assuming Basisformer class is defined elsewhere # from basisformer_model import Basisformer # Placeholder for the Basisformer class definition for self-containment class Basisformer(torch.nn.Module): def __init__(self, seq_len, pred_len, d_model, heads, basis_nums, block_nums, bottle, map_bottleneck, device, tau, is_MS, input_channel): super().__init__() # Simplified placeholder layers self.seq_len = seq_len self.pred_len = pred_len self.d_model = d_model self.basis_nums = basis_nums self.device = device # Dummy layers to simulate model structure self.input_projection = torch.nn.Linear(input_channel, d_model) self.transformer_encoder_layer = torch.nn.TransformerEncoderLayer(d_model=d_model, nhead=heads) self.transformer_encoder = torch.nn.TransformerEncoder(self.transformer_encoder_layer, num_layers=block_nums) self.output_projection = torch.nn.Linear(d_model, input_channel) self.basis_layer = torch.nn.Linear(d_model, basis_nums) def forward(self, x, temporal_index, y=None, train=False, y_mark=None): # Simplified forward pass residual = x x = self.input_projection(x) # In a real model, temporal_index and y_mark would be used # For simplicity, we'll just use x for encoding attn_weights1 = [torch.rand(1, self.d_model, self.seq_len, device=self.device) for _ in range(self.block_nums)] # Dummy attention weights attn_weights2 = [torch.rand(1, self.d_model, self.seq_len, device=self.device) for _ in range(self.block_nums)] # Dummy attention weights attn_weights3 = [torch.rand(1, self.d_model, self.pred_len, device=self.device) for _ in range(self.block_nums)] # Dummy attention weights attn_weights4 = [torch.rand(1, self.d_model, self.pred_len, device=self.device) for _ in range(self.block_nums)] # Dummy attention weights encoded = self.transformer_encoder(x) prediction = self.output_projection(encoded[:, -self.pred_len:, :]) basis = self.basis_layer(encoded) return prediction, basis, attn_weights1, attn_weights2, attn_weights3, attn_weights4 # --- Code from the provided text --- # Load trained model device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu') model = Basisformer( seq_len=96, pred_len=96, d_model=100, heads=16, basis_nums=10, block_nums=2, bottle=2, map_bottleneck=20, device=device, tau=0.07, is_MS=False, input_channel=0 ).to(device) # Placeholder for loading state dict, as the file might not exist # In a real scenario, you would have the actual file path # checkpoint_path = 'records/traffic/features_M/seq_len96,pred_len96/checkpoint/valid_best_checkpoint.pth' # try: # model.load_state_dict(torch.load(checkpoint_path, map_location=device)) # except FileNotFoundError: # print(f"Checkpoint file not found at {checkpoint_path}. Using randomly initialized model.") model.eval() # Prepare single input sample seq_len = 96 pred_len = 96 num_channels = 7 # Input time series (shape: [1, seq_len, channels]) input_sequence = torch.randn(1, seq_len, num_channels).to(device) # Temporal index (normalized by dataset length) temporal_index = torch.linspace(0, 1, seq_len + pred_len).unsqueeze(0).to(device) # Dummy target for inference (not used in train=False mode) dummy_target = torch.zeros(1, pred_len, num_channels).to(device) dummy_y_mark = torch.zeros(1, pred_len, 4).to(device) # Inference with torch.no_grad(): prediction, basis, attn_x1, attn_x2, attn_y1, attn_y2 = model( input_sequence, temporal_index, dummy_target, train=False, y_mark=dummy_y_mark ) print(f"Prediction shape: {prediction.shape}") # Expected: (1, 96, 7) print(f"Learned basis shape: {basis.shape}") # Expected: (1, 192, 10) # Convert to numpy for downstream processing forecast = prediction.cpu().numpy()[0] # Shape: (96, 7) print(f"Forecast for next {pred_len} timesteps: {forecast.shape}") # Attention weights provide interpretability # attn_x1, attn_x2: attention weights from input processing BCABs # attn_y1, attn_y2: attention weights from output processing BCABs print(f"Number of attention layers: {len(attn_x1)}") ``` -------------------------------- ### Run Multivariate Forecasting Experiments (Bash) Source: https://context7.com/nzl5116190/basisformer/llms.txt This bash script automates multivariate time series forecasting experiments for the BasisFormer model. It iterates through different prediction lengths and datasets (Electricity, Traffic, Weather, Illness), configuring and launching training runs with specified hyperparameters. The script requires Python 3 and the main.py training script. ```bash #!/bin/bash # Multivariate forecasting on multiple datasets export CUDA_VISIBLE_DEVICES=0 for pred_len in 96 192 336 720 do # Electricity dataset python -u main.py \ --is_training True \ --root_path all_six_datasets/electricity \ --data_path electricity.csv \ --data custom \ --features M \ --seq_len 96 \ --label_len 96 \ --pred_len $pred_len \ --learning_rate 5e-4 \ --batch_size 32 \ --train_epochs 100 \ --patience 3 \ --d_model 100 \ --heads 16 \ --N 10 \ --block_nums 2 \ --bottleneck 2 \ --map_bottleneck 20 \ --tau 0.07 \ --loss_weight_prediction 1.0 \ --loss_weight_infonce 1.0 \ --loss_weight_smooth 1.0 # Traffic dataset python -u main.py \ --is_training True \ --root_path all_six_datasets/traffic \ --data_path traffic.csv \ --data custom \ --features M \ --seq_len 96 \ --label_len 96 \ --pred_len $pred_len \ --learning_rate 5e-4 # Weather dataset python -u main.py \ --is_training True \ --root_path all_six_datasets/weather \ --data_path weather.csv \ --data custom \ --features M \ --seq_len 96 \ --label_len 96 \ --pred_len $pred_len \ --learning_rate 5e-4 done # Illness dataset with shorter sequences for pred_len in 24 36 48 60 do python -u main.py \ --is_training True \ --root_path all_six_datasets/illness \ --data_path national_illness.csv \ --data custom \ --features M \ --seq_len 36 \ --label_len 36 \ --pred_len $pred_len \ --learning_rate 6e-4 done ``` -------------------------------- ### Load and Preprocess Time Series Data with Data Factory Source: https://context7.com/nzl5116190/basisformer/llms.txt Loads time series datasets using the `data_provider` function, which handles standardization, temporal feature extraction, and automatic train/validation/test splitting. It supports ETT datasets and custom CSV files. Requires the `data_factory` module and an `argparse`-like configuration object. Outputs are the dataset and corresponding DataLoader for each split (train, val, test). ```python import argparse from data_provider.data_factory import data_provider # Create configuration class Args: def __init__(self): self.data = 'custom' self.root_path = 'all_six_datasets/traffic' self.data_path = 'traffic.csv' self.features = 'M' # 'M': multivariate, 'S': univariate, 'MS': multi-to-uni self.target = 'OT' # Target column for 'S' or 'MS' mode self.seq_len = 96 self.label_len = 96 self.pred_len = 96 self.freq = 'h' # Time frequency: 'h'=hourly, 'd'=daily, etc. self.embed = 'timeF' # Time encoding: 'timeF', 'fixed', 'learned' self.batch_size = 32 self.num_workers = 0 args = Args() # Load training data train_set, train_loader = data_provider(args, flag='train') print(f"Training samples: {len(train_set)}") # Load validation and test data vali_set, vali_loader = data_provider(args, flag='val') test_set, test_loader = data_provider(args, flag='test') ``` -------------------------------- ### Create Conda Environment for BasisFormer Source: https://github.com/nzl5116190/basisformer/blob/main/README.md This snippet demonstrates how to create and activate a conda environment named 'basisformer' with Python 3.8. This is an optional step for managing project dependencies. ```bash conda create -n basisformer -y python=3.8 conda activate basisformer ``` -------------------------------- ### Run Parallel Univariate Forecasting (Multi-GPU) Source: https://github.com/nzl5116190/basisformer/blob/main/README.md This script is an alternative to 'script/S.sh' that enables multi-GPU execution for univariate forecasting. It allows for accelerated training and evaluation on systems with multiple GPUs. ```bash sh script/S_parallel.sh ``` -------------------------------- ### Single-Sample Inference with Basisformer (Python) Source: https://context7.com/nzl5116190/basisformer/llms.txt This Python snippet outlines the process for performing single-sample inference using a trained Basisformer model. It focuses on loading a pre-trained model and using it to generate forecasts on new data without the need for a training loop. This is crucial for real-time forecasting applications where computational efficiency during prediction is paramount. ```python import torch import numpy as np from model import Basisformer # Placeholder for model loading and inference logic # Assuming 'device' is defined and a trained model is available # Example: Load a trained model (replace with actual path) # model_path = 'path/to/your/trained_model.pth' # model = Basisformer(...).to(device) # model.load_state_dict(torch.load(model_path)) # model.eval() # Set model to evaluation mode # Example: Prepare input data (replace with actual data) # input_data = torch.randn(1, 96, 7) # Batch size 1, seq_len 96, channels 7 # input_data = input_data.to(device) # with torch.no_grad(): # prediction = model(input_data) # print(f"Inference successful. Prediction shape: {prediction.shape}") ``` -------------------------------- ### Run Parallel Multivariate Forecasting (Multi-GPU) Source: https://github.com/nzl5116190/basisformer/blob/main/README.md This script is a variant of 'script/M.sh' designed to utilize multiple GPUs for faster multivariate forecasting. It's suitable for environments with parallel processing capabilities. ```bash sh script/M_parallel.sh ``` -------------------------------- ### Univariate Forecasting with Basisformer (S Mode) Source: https://context7.com/nzl5116190/basisformer/llms.txt This script demonstrates how to run univariate time series forecasting using the Basisformer model in 'S' mode for different datasets and prediction lengths. It configures training parameters, specifies data paths, and sets forecast horizons. The script iterates through predefined prediction lengths and applies the model to electricity, traffic, and ETTm2 datasets. ```shell export CUDA_VISIBLE_DEVICES=0 for pred_len in 96 192 336 720 do # Electricity dataset - univariate python -u main.py \ --is_training True \ --root_path all_six_datasets/electricity \ --data_path electricity.csv \ --data custom \ --features S \ --target OT \ --seq_len 96 \ --label_len 96 \ --pred_len $pred_len \ --learning_rate 2e-4 # Traffic dataset - univariate python -u main.py \ --is_training True \ --root_path all_six_datasets/traffic \ --data_path traffic.csv \ --data custom \ --features S \ --target OT \ --seq_len 96 \ --label_len 96 \ --pred_len $pred_len \ --learning_rate 1e-3 # ETTm2 dataset - univariate python -u main.py \ --is_training True \ --root_path all_six_datasets/ETT-small \ --data_path ETTm2.csv \ --data ETTm2 \ --features S \ --target OT \ --seq_len 96 \ --label_len 96 \ --pred_len $pred_len \ --learning_rate 3e-4 done ``` -------------------------------- ### Iterate Data Batches (Python) Source: https://context7.com/nzl5116190/basisformer/llms.txt Demonstrates iterating through data batches provided by a training loader. It shows the shapes of input, target, and temporal features for each batch. Data is pre-standardized, with inverse transformation available. ```python for batch_x, batch_y, batch_x_mark, batch_y_mark, index in train_loader: # batch_x: (B, seq_len, C) - input sequence # batch_y: (B, label_len+pred_len, C) - target sequence (includes overlap) # batch_x_mark: (B, seq_len, 4) - temporal features for input # batch_y_mark: (B, label_len+pred_len, 4) - temporal features for output # index: (B, seq_len+pred_len) - normalized temporal indices print(f"Input shape: {batch_x.shape}") print(f"Target shape: {batch_y.shape}") print(f"Time features shape: {batch_x_mark.shape}") break ``` -------------------------------- ### Run Multivariate Forecasting Script Source: https://github.com/nzl5116190/basisformer/blob/main/README.md Executes the main script for multivariate time series forecasting using the BasisFormer model. This shell script likely orchestrates the training and evaluation process for multivariate data. ```bash sh script/M.sh ``` -------------------------------- ### Evaluate BasisFormer Model Performance on Test Set (Python) Source: https://context7.com/nzl5116190/basisformer/llms.txt This Python script loads the best trained BasisFormer model checkpoint and evaluates its performance on the test set. It computes standard time series metrics such as MSE, MAE, RMSE, MAPE, and MSPE. The script supports inverse transforming predictions to the original scale for a more interpretable evaluation. It requires PyTorch, NumPy, and a custom 'evaluate_tool' module. ```python from evaluate_tool import metric # Load best model checkpoint_path = os.path.join(record_dir, 'checkpoint', 'valid_best_checkpoint.pth') model.load_state_dict(torch.load(checkpoint_path)) model.eval() preds = [] trues = [] with torch.no_grad(): for batch_x, batch_y, batch_x_mark, batch_y_mark, index in test_loader: batch_x = batch_x.float().to(device) batch_y = batch_y.float().to(device) batch_y_mark = batch_y_mark.float().to(device) f_dim = -1 if args.features == 'MS' else 0 batch_y_target = batch_y[:, -args.pred_len:, f_dim:].to(device) outputs, _, _, _, _, _, _ = model( batch_x, index.float().to(device), batch_y_target, train=False, y_mark=batch_y_mark ) outputs = outputs.detach().cpu().numpy() batch_y_target = batch_y_target.detach().cpu().numpy() preds.append(outputs) trues.append(batch_y_target) # Aggregate predictions preds = np.concatenate(preds, axis=0) # (N, pred_len, C) trues = np.concatenate(trues, axis=0) # Compute metrics mae, mse, rmse, mape, mspe = metric(preds, trues) print(f"Test Results:") print(f" MSE: {mse:.6f}") print(f" MAE: {mae:.6f}") print(f" RMSE: {rmse:.6f}") print(f" MAPE: {mape:.6f}") print(f" MSPE: {mspe:.6f}") # Inverse transform to original scale (optional) if hasattr(test_set, 'inverse_transform'): preds_original = test_set.inverse_transform(preds.reshape(-1, preds.shape[-1])) trues_original = test_set.inverse_transform(trues.reshape(-1, trues.shape[-1])) preds_original = preds_original.reshape(preds.shape) trues_original = trues_original.reshape(trues.shape) print("\nMetrics on original scale:") mae_orig, mse_orig, rmse_orig, mape_orig, mspe_orig = metric(preds_original, trues_original) print(f" MSE: {mse_orig:.6f}") print(f" MAE: {mae_orig:.6f}") ``` -------------------------------- ### BasisFormer Citation Source: https://github.com/nzl5116190/basisformer/blob/main/README.md The BibTeX entry for citing the BasisFormer paper. This should be included in academic publications that utilize or reference the BasisFormer model. ```bibtex @inproceedings{ni2023basisformer, title={{Basisformer}: Attention-based Time Series Forecasting with Learnable and Interpretable Basis}, author={Ni, Zelin and Yu, Hang and Liu, Shizhan and Li, Jianguo and Lin, Weiyao}, booktitle={Advances in Neural Information Processing Systems}, year={2023} } ``` -------------------------------- ### Run Univariate Forecasting Script Source: https://github.com/nzl5116190/basisformer/blob/main/README.md Executes the main script for univariate time series forecasting using the BasisFormer model. This shell script is responsible for managing the training and evaluation workflow for univariate data. ```bash sh script/S.sh ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.