docstr: Calculate confidence interval of data based on Monte Carlo dropout(MC dropout).
  Related paper : https://arxiv.org/abs/1709.01907
  
  :param data: The data support following formats:
  
         | 1. numpy ndarrays: generate from `TSDataset.roll`,
              be sure to set label_len > 0 and time_enc = True
         | 2. pytorch dataloader: generate from `TSDataset.to_torch_data_loader`,
              be sure to set label_len > 0, time_enc = True
         | 3. A bigdl.chronos.data.tsdataset.TSDataset instance
  
  :param validation_data: The validation_data support following formats:
  
         | 1. numpy ndarrays: generate from `TSDataset.roll`,
              be sure to set label_len > 0 and time_enc = True
         | 2. pytorch dataloader: generate from `TSDataset.to_torch_data_loader`,
              be sure to set label_len > 0, time_enc = True
         | 3. A bigdl.chronos.data.tsdataset.TSDataset instance
  
  :param batch_size: predict batch size. The value will not affect predict
         result but will affect resources cost(e.g. memory and time).
  :param repetition_times : Defines repeate how many times to calculate model
                            uncertainty based on MC Dropout.
  
  :return: prediction and standard deviation which are both numpy array
           with shape (num_samples, horizon, target_dim)
docstr_tok: ["Calculate","confidence","interval","of","data","based","on","Monte","Carlo","dropout","(","MC","dropout",")",".","Related","paper",":","https",":","\/\/arxiv.org\/abs\/1709.01907",":","param","data",":","The","data","support","following","formats",":","|","1.","numpy","ndarrays",":","generate","from","`","TSDataset.roll","`",",","be","sure","to","set","label_len",">","0","and","time_enc","=","True","|","2.","pytorch","dataloader",":","generate","from","`","TSDataset.to_torch_data_loader","`",",","be","sure","to","set","label_len",">","0",",","time_enc","=","True","|","3",".","A","bigdl.chronos.data.tsdataset.TSDataset","instance",":","param","validation_data",":","The","validation_data","support","following","formats",":","|","1.","numpy","ndarrays",":","generate","from","`","TSDataset.roll","`",",","be","sure","to","set","label_len",">","0","and","time_enc","=","True","|","2.","pytorch","dataloader",":","generate","from","`","TSDataset.to_torch_data_loader","`",",","be","sure","to","set","label_len",">","0",",","time_enc","=","True","|","3",".","A","bigdl.chronos.data.tsdataset.TSDataset","instance",":","param","batch_size",":","predict","batch","size",".","The","value","will","not","affect","predict","result","but","will","affect","resources","cost","(","e.g",".","memory","and","time",")",".",":","param","repetition_times",":","Defines","repeate","how","many","times","to","calculate","model","uncertainty","based","on","MC","Dropout",".",":","return",":","prediction","and","standard","deviation","which","are","both","numpy","array","with","shape","(","num_samples",",","horizon",",","target_dim",")"]
code: def predict_interval(
      self,
      data,
      validation_data=None,
      batch_size=32,
      repetition_times=5,
  ):
      """
      Calculate confidence interval of data based on Monte Carlo dropout(MC dropout).
      Related paper : https://arxiv.org/abs/1709.01907
  
      :param data: The data support following formats:
  
             | 1. numpy ndarrays: generate from `TSDataset.roll`,
                  be sure to set label_len > 0 and time_enc = True
             | 2. pytorch dataloader: generate from `TSDataset.to_torch_data_loader`,
                  be sure to set label_len > 0, time_enc = True
             | 3. A bigdl.chronos.data.tsdataset.TSDataset instance
  
      :param validation_data: The validation_data support following formats:
  
             | 1. numpy ndarrays: generate from `TSDataset.roll`,
                  be sure to set label_len > 0 and time_enc = True
             | 2. pytorch dataloader: generate from `TSDataset.to_torch_data_loader`,
                  be sure to set label_len > 0, time_enc = True
             | 3. A bigdl.chronos.data.tsdataset.TSDataset instance
  
      :param batch_size: predict batch size. The value will not affect predict
             result but will affect resources cost(e.g. memory and time).
      :param repetition_times : Defines repeate how many times to calculate model
                                uncertainty based on MC Dropout.
  
      :return: prediction and standard deviation which are both numpy array
               with shape (num_samples, horizon, target_dim)
  
      """
      from bigdl.chronos.pytorch.utils import _pytorch_fashion_inference
  
      if self.fitted is not True:
          invalidInputError(
              False,
              "You must call fit or restore first before calling predict_interval!",
          )
  
      # step1, according to validation dataset, calculate inherent noise
      if not hasattr(self, "data_noise"):
          invalidInputError(
              validation_data is not None,
              "When call predict_interval for the first time, you must pass in "
              "validation_data to calculate data noise.",
          )
          # transform a TSDataset instance to dataloader
          if isinstance(validation_data, TSDataset):
              _rolled = validation_data.numpy_x is None
              validation_data = validation_data.to_torch_data_loader(
                  batch_size=batch_size,
                  roll=_rolled,
                  lookback=self.data_config["past_seq_len"],
                  horizon=self.data_config["future_seq_len"],
                  label_len=self.data_config["label_len"],
                  time_enc=True,
                  feature_col=data.roll_feature,
                  target_col=data.roll_target,
                  shuffle=False,
              )
          # data transform
          if isinstance(validation_data, DataLoader):
              target = np.concatenate(
                  tuple(val[1] for val in validation_data), axis=0
              )
          else:
              _, target, _, _ = validation_data
  
          target = target[:, -self.data_config["future_seq_len"] :, :]
  
          _yhat = self.predict(validation_data)
          val_yhat = np.concatenate(_yhat, axis=0)
          self.data_noise = Evaluator.evaluate(
              ["mse"], target, val_yhat, aggregate=None
          )[
              0
          ]  # 2d array
  
      # step2: calculate model uncertainty based MC Dropout
      def apply_dropout(m):
          if type(m) == torch.nn.Dropout:
              m.train()
  
      # turn on dropout
      self.internal.apply(apply_dropout)
  
      # transform a TSDataset instance to dataloader
      if isinstance(data, TSDataset):
          _rolled = data.numpy_x is None
          data = data.to_torch_data_loader(
              batch_size=batch_size,
              roll=_rolled,
              lookback=self.data_config["past_seq_len"],
              horizon=self.data_config["future_seq_len"],
              label_len=self.data_config["label_len"],
              time_enc=True,
              feature_col=data.roll_feature,
              target_col=data.roll_target,
              shuffle=False,
          )
  
      def predict(data, model):
          # manually implement predict to avoid .eval() in trainer.predict()
          if isinstance(data, tuple):
              data = DataLoader(
                  TensorDataset(
                      torch.from_numpy(data[0]),
                      torch.from_numpy(data[1]),
                      torch.from_numpy(data[2]),
                      torch.from_numpy(data[3]),
                  ),
                  batch_size=batch_size,
                  shuffle=False,
              )
          outputs_list = []
          for batch in data:
              batch_x, batch_y, batch_x_mark, batch_y_mark = map(
                  lambda x: x.float(), batch
              )
              outputs = model(
                  batch_x, batch_x_mark, batch_y, batch_y_mark
              )
              outputs = outputs[:, -model.pred_len :, -model.c_out :]
              outputs_list.append(outputs.detach().numpy())
          return outputs_list
  
      y_hat_list = []
      for i in range(repetition_times):
          _yhat = predict(data, self.internal)
          yhat = np.concatenate(_yhat, axis=0)
          y_hat_list.append(yhat)
      y_hat_mean = np.mean(np.stack(y_hat_list, axis=0), axis=0)
  
      model_bias = np.zeros_like(y_hat_mean)  # 3d array
      for i in range(repetition_times):
          model_bias += (y_hat_list[i] - y_hat_mean) ** 2
      model_bias /= repetition_times
      std_deviation = np.sqrt(self.data_noise + model_bias)
  
      return y_hat_mean, std_deviation
  
imports: import torch
  import numpy
  from pandas import Timedelta
  from bigdl.chronos.forecaster.abstract import Forecaster
  from bigdl.chronos.forecaster.utils import read_csv, delete_folder
  from bigdl.chronos.metric.forecast_metrics import Evaluator
  from bigdl.chronos.model.autoformer import model_creator, loss_creator
  from torch.utils.data import TensorDataset, DataLoader
  from bigdl.chronos.model.autoformer.Autoformer import AutoFormer, _transform_config_to_namedtuple
  from bigdl.nano.utils.common import invalidInputError, invalidOperationError
  from bigdl.chronos.forecaster.utils import check_transformer_data
  from bigdl.chronos.pytorch import TSTrainer
  from bigdl.chronos.data import TSDataset
  from bigdl.nano.automl.hpo.space import Space
  from bigdl.chronos.forecaster.utils_hpo import GenericTSTransformerLightningModule, _config_has_search_space
  from bigdl.chronos.pytorch.context_manager import DummyForecasterContextManager, ForecasterContextManager
  from .utils_hpo import _format_metric_str
  import warnings
  from tempfile import TemporaryDirectory
  import os
label_desc: Use image node_id 9 for calling the AutoformerForecaster obj's underlying member method code with example usage: obj.predict_interval(data, validation_data, batch_size, repetition_times) and returns: y_hat_mean,  std_deviation, outputs_list