class_docstr: Linear time regression fun and some not so linear fun.
  A modular model that models classic time-series components
      * trend
      * seasonality
      * auto-regression (as AR-Net)
      * covariates (as AR-Net)
      * apriori regressors
      * events and holidays
  by using Neural Network components.
  The Auto-regression and covariate components can be configured as a deeper network (AR-Net).
class_docstr_tok: ["Linear","time","regression","fun","and","some","not","so","linear","fun",".","A","modular","model","that","models","classic","time-series","components","*","trend","*","seasonality","*","auto-regression","(","as","AR-Net",")","*","covariates","(","as","AR-Net",")","*","apriori","regressors","*","events","and","holidays","by","using","Neural","Network","components",".","The","Auto-regression","and","covariate","components","can","be","configured","as","a","deeper","network","(","AR-Net",")","."]
docstr: Computes the actual quantile forecasts from quantile differences estimated from the model
  Args:
      diffs : torch.Tensor
          tensor of dims (batch, n_forecasts, no_quantiles) which
          contains the median quantile forecasts as well as the diffs of other quantiles
          from the median quantile
      predict_mode : bool
          boolean variable indicating whether the model is in prediction mode
  Returns:
      dim (batch, n_forecasts, no_quantiles)
          final forecasts
docstr_tok: ["Computes","the","actual","quantile","forecasts","from","quantile","differences","estimated","from","the","model","Args",":","diffs",":","torch.Tensor","tensor","of","dims","(","batch",",","n_forecasts",",","no_quantiles",")","which","contains","the","median","quantile","forecasts","as","well","as","the","diffs","of","other","quantiles","from","the","median","quantile","predict_mode",":","bool","boolean","variable","indicating","whether","the","model","is","in","prediction","mode","Returns",":","dim","(","batch",",","n_forecasts",",","no_quantiles",")","final","forecasts"]
code: def _compute_quantile_forecasts_from_diffs(
      self, diffs: torch.Tensor, predict_mode: bool = False
  ) -> torch.Tensor:
      """
      Computes the actual quantile forecasts from quantile differences estimated from the model
      Args:
          diffs : torch.Tensor
              tensor of dims (batch, n_forecasts, no_quantiles) which
              contains the median quantile forecasts as well as the diffs of other quantiles
              from the median quantile
          predict_mode : bool
              boolean variable indicating whether the model is in prediction mode
      Returns:
          dim (batch, n_forecasts, no_quantiles)
              final forecasts
      """
      if len(self.quantiles) > 1:
          # generate the actual quantile forecasts from predicted differences
          if any(quantile > 0.5 for quantile in self.quantiles):
              quantiles_divider_index = next(
                  i
                  for i, quantile in enumerate(self.quantiles)
                  if quantile > 0.5
              )
          else:
              quantiles_divider_index = len(self.quantiles)
  
          n_upper_quantiles = diffs.shape[-1] - quantiles_divider_index
          n_lower_quantiles = quantiles_divider_index - 1
  
          out = torch.zeros_like(diffs)
          out[:, :, 0] = diffs[
              :, :, 0
          ]  # set the median where 0 is the median quantile index
  
          if n_upper_quantiles > 0:  # check if upper quantiles exist
              upper_quantile_diffs = diffs[
                  :, :, quantiles_divider_index:
              ]
              if (
                  predict_mode
              ):  # check for quantile crossing and correct them in predict mode
                  upper_quantile_diffs[:, :, 0] = torch.max(
                      torch.tensor(0, device=self.device),
                      upper_quantile_diffs[:, :, 0],
                  )
                  for i in range(n_upper_quantiles - 1):
                      next_diff = upper_quantile_diffs[:, :, i + 1]
                      diff = upper_quantile_diffs[:, :, i]
                      upper_quantile_diffs[:, :, i + 1] = torch.max(
                          next_diff, diff
                      )
              out[:, :, quantiles_divider_index:] = (
                  upper_quantile_diffs
                  + diffs[:, :, 0]
                  .unsqueeze(dim=2)
                  .repeat(1, 1, n_upper_quantiles)
                  .detach()
              )  # set the upper quantiles
  
          if n_lower_quantiles > 0:  # check if lower quantiles exist
              lower_quantile_diffs = diffs[
                  :, :, 1:quantiles_divider_index
              ]
              if (
                  predict_mode
              ):  # check for quantile crossing and correct them in predict mode
                  lower_quantile_diffs[:, :, -1] = torch.max(
                      torch.tensor(0, device=self.device),
                      lower_quantile_diffs[:, :, -1],
                  )
                  for i in range(n_lower_quantiles - 1, 0, -1):
                      next_diff = lower_quantile_diffs[:, :, i - 1]
                      diff = lower_quantile_diffs[:, :, i]
                      lower_quantile_diffs[:, :, i - 1] = torch.max(
                          next_diff, diff
                      )
              lower_quantile_diffs = -lower_quantile_diffs
              out[:, :, 1:quantiles_divider_index] = (
                  lower_quantile_diffs
                  + diffs[:, :, 0]
                  .unsqueeze(dim=2)
                  .repeat(1, 1, n_lower_quantiles)
                  .detach()
              )  # set the lower quantiles
      else:
          out = diffs
      return out
  
imports: import logging
  import math
  from collections import OrderedDict
  from functools import reduce
  from typing import Dict, List, Optional, Union
  import numpy
  import pytorch_lightning
  import torch
  import torch.nn
  import torchmetrics
  from neuralprophet import configure, np_types
  from neuralprophet.components.router import get_future_regressors, get_seasonality, get_trend
  from neuralprophet.utils import check_for_regularization, config_events_to_model_dims, reg_func_events, reg_func_regressors, reg_func_season, reg_func_trend
  from neuralprophet.utils_torch import init_parameter, interprete_model
label_desc: Use image node_id 6 for calling the TimeNet obj's underlying member method code with example usage: obj._compute_quantile_forecasts_from_diffs(diffs, predict_mode) and returns: out