class_docstr: DeepAR
  
  The DeepAR model produces probabilistic forecasts based on an autoregressive recurrent neural network optimized on panel data using cross-learning. DeepAR obtains its forecast distribution uses a Markov Chain Monte Carlo sampler with the following conditional probability:
  $$\mathbb{P}(\mathbf{y}_{[t+1:t+H]}|\;\mathbf{y}_{[:t]},\; \mathbf{x}^{(f)}_{[:t+H]},\; \mathbf{x}^{(s)})$$
  
  where $\mathbf{x}^{(s)}$ are static exogenous inputs, $\mathbf{x}^{(f)}_{[:t+H]}$ are future exogenous available at the time of the prediction.
  The predictions are obtained by transforming the hidden states $\mathbf{h}_{t}$ into predictive distribution parameters $   heta_{t}$, and then generating samples $\mathbf{\hat{y}}_{[t+1:t+H]}$ through Monte Carlo sampling trajectories.
  
  egin{align}
  \mathbf{h}_{t} &=   extrm{RNN}([\mathbf{y}_{t},\mathbf{x}^{(f)}_{t+1},\mathbf{x}^{(s)}], \mathbf{h}_{t-1})\
  \mathbf{    heta}_{t}&=     extrm{Linear}(\mathbf{h}_{t}) \
  \hat{y}_{t+1}&=     extrm{sample}(\;\mathrm{P}(y_{t+1}\;|\;\mathbf{ heta}_{t})\;)
  \end{align}
  
  **Parameters:**<br>
  `h`: int, Forecast horizon. <br>
  `input_size`: int, autorregresive inputs size, y=[1,2,3,4] input_size=2 -> y_[t-2:t]=[1,2].<br>
  `lstm_n_layers`: int=2, number of LSTM layers.<br>
  `lstm_hidden_size`: int=128, LSTM hidden size.<br>
  `lstm_dropout`: float=0.1, LSTM dropout.<br>
  `decoder_hidden_layers`: int=0, number of decoder MLP hidden layers. Default: 0 for linear layer. <br>
  `decoder_hidden_size`: int=0, decoder MLP hidden size. Default: 0 for linear layer.<br>
  `trajectory_samples`: int=100, number of Monte Carlo trajectories during inference.<br>
  `stat_exog_list`: str list, static exogenous columns.<br>
  `hist_exog_list`: str list, historic exogenous columns.<br>
  `futr_exog_list`: str list, future exogenous columns.<br>
  `exclude_insample_y`: bool=False, the model skips the autoregressive features y[t-input_size:t] if True.<br>
  `loss`: PyTorch module, instantiated train loss class from [losses collection](https://nixtla.github.io/neuralforecast/losses.pytorch.html).<br>
  `valid_loss`: PyTorch module=`loss`, instantiated valid loss class from [losses collection](https://nixtla.github.io/neuralforecast/losses.pytorch.html).<br>
  `max_steps`: int=1000, maximum number of training steps.<br>
  `learning_rate`: float=1e-3, Learning rate between (0, 1).<br>
  `num_lr_decays`: int=-1, Number of learning rate decays, evenly distributed across max_steps.<br>
  `early_stop_patience_steps`: int=-1, Number of validation iterations before early stopping.<br>
  `val_check_steps`: int=100, Number of training steps between every validation loss check.<br>
  `batch_size`: int=32, number of different series in each batch.<br>
  `valid_batch_size`: int=None, number of different series in each validation and test batch, if None uses batch_size.<br>
  `windows_batch_size`: int=1024, number of windows to sample in each training batch, default uses all.<br>
  `inference_windows_batch_size`: int=-1, number of windows to sample in each inference batch, -1 uses all.<br>
  `start_padding_enabled`: bool=False, if True, the model will pad the time series with zeros at the beginning, by input size.<br>
  `step_size`: int=1, step size between each window of temporal data.<br>
  `scaler_type`: str='identity', type of scaler for temporal inputs normalization see [temporal scalers](https://nixtla.github.io/neuralforecast/common.scalers.html).<br>
  `random_seed`: int, random_seed for pytorch initializer and numpy generators.<br>
  `num_workers_loader`: int=os.cpu_count(), workers to be used by `TimeSeriesDataLoader`.<br>
  `drop_last_loader`: bool=False, if True `TimeSeriesDataLoader` drops last non-full batch.<br>
  `alias`: str, optional,  Custom name of the model.<br>
  `**trainer_kwargs`: int,  keyword trainer arguments inherited from [PyTorch Lighning's trainer](https://pytorch-lightning.readthedocs.io/en/stable/api/pytorch_lightning.trainer.trainer.Trainer.html?highlight=trainer).<br>    
  
  **References**<br>
  - [David Salinas, Valentin Flunkert, Jan Gasthaus, Tim Januschowski (2020). "DeepAR: Probabilistic forecasting with autoregressive recurrent networks". International Journal of Forecasting.](https://www.sciencedirect.com/science/article/pii/S0169207019301888)<br>
  - [Alexander Alexandrov et. al (2020). "GluonTS: Probabilistic and Neural Time Series Modeling in Python". Journal of Machine Learning Research.](https://www.jmlr.org/papers/v21/19-820.html)<br>
class_docstr_tok: ["DeepAR","The","DeepAR","model","produces","probabilistic","forecasts","based","on","an","autoregressive","recurrent","neural","network","optimized","on","panel","data","using","cross-learning",".","DeepAR","obtains","its","forecast","distribution","uses","a","Markov","Chain","Monte","Carlo","sampler","with","the","following","conditional","probability",":","$","$","\\mathbb","{","P","}","(","\\mathbf","{","y","}","_","{","[","t+1",":","t+H","]","}","|\\",";","\\mathbf","{","y","}","_","{","[",":","t","]","}",",","\\",";","\\mathbf","{","x","}","^","{","(","f",")","}","_","{","[",":","t+H","]","}",",","\\",";","\\mathbf","{","x","}","^","{","(","s",")","}",")","$","$","where","$","\\mathbf","{","x","}","^","{","(","s",")","}","$","are","static","exogenous","inputs",",","$","\\mathbf","{","x","}","^","{","(","f",")","}","_","{","[",":","t+H","]","}","$","are","future","exogenous","available","at","the","time","of","the","prediction",".","The","predictions","are","obtained","by","transforming","the","hidden","states","$","\\mathbf","{","h","}","_","{","t","}","$","into","predictive","distribution","parameters","$","heta_","{","t","}","$",",","and","then","generating","samples","$","\\mathbf","{","\\hat","{","y","}","}","_","{","[","t+1",":","t+H","]","}","$","through","Monte","Carlo","sampling","trajectories",".","\begin","{","align","}","\\mathbf","{","h","}","_","{","t","}","&","=","extrm","{","RNN","}","(","[","\\mathbf","{","y","}","_","{","t","}",",","\\mathbf","{","x","}","^","{","(","f",")","}","_","{","t+1","}",",","\\mathbf","{","x","}","^","{","(","s",")","}","]",",","\\mathbf","{","h","}","_","{","t-1","}",")","\\","\\mathbf","{","heta","}","_","{","t","}","&","=","extrm","{","Linear","}","(","\\mathbf","{","h","}","_","{","t","}",")","\\","\\hat","{","y","}","_","{","t+1","}","&","=","extrm","{","sample","}","(","\\",";","\\mathrm","{","P","}","(","y_","{","t+1","}","\\",";","|\\",";","\\mathbf","{","heta","}","_","{","t","}",")","\\",";",")","\\end","{","align","}","*","*","Parameters",":","*","*","<","br",">","`","h","`",":","int",",","Forecast","horizon",".","<","br",">","`","input_size","`",":","int",",","autorregresive","inputs","size",",","y=","[","1,2,3,4","]","input_size=2","-",">","y_","[","t-2",":","t","]","=","[","1,2","]",".","<","br",">","`","lstm_n_layers","`",":","int=2",",","number","of","LSTM","layers.","<","br",">","`","lstm_hidden_size","`",":","int=128",",","LSTM","hidden","size.","<","br",">","`","lstm_dropout","`",":","float=0.1",",","LSTM","dropout.","<","br",">","`","decoder_hidden_layers","`",":","int=0",",","number","of","decoder","MLP","hidden","layers",".","Default",":","0","for","linear","layer",".","<","br",">","`","decoder_hidden_size","`",":","int=0",",","decoder","MLP","hidden","size",".","Default",":","0","for","linear","layer.","<","br",">","`","trajectory_samples","`",":","int=100",",","number","of","Monte","Carlo","trajectories","during","inference.","<","br",">","`","stat_exog_list","`",":","str","list",",","static","exogenous","columns.","<","br",">","`","hist_exog_list","`",":","str","list",",","historic","exogenous","columns.","<","br",">","`","futr_exog_list","`",":","str","list",",","future","exogenous","columns.","<","br",">","`","exclude_insample_y","`",":","bool=False",",","the","model","skips","the","autoregressive","features","y","[","t-input_size",":","t","]","if","True.","<","br",">","`","loss","`",":","PyTorch","module",",","instantiated","train","loss","class","from","[","losses","collection","]","(","https",":","\/\/nixtla.github.io\/neuralforecast\/losses.pytorch.html",")",".","<","br",">","`","valid_loss","`",":","PyTorch","module=","`","loss","`",",","instantiated","valid","loss","class","from","[","losses","collection","]","(","https",":","\/\/nixtla.github.io\/neuralforecast\/losses.pytorch.html",")",".","<","br",">","`","max_steps","`",":","int=1000",",","maximum","number","of","training","steps.","<","br",">","`","learning_rate","`",":","float=1e-3",",","Learning","rate","between","(","0",",","1",")",".","<","br",">","`","num_lr_decays","`",":","int=-1",",","Number","of","learning","rate","decays",",","evenly","distributed","across","max_steps.","<","br",">","`","early_stop_patience_steps","`",":","int=-1",",","Number","of","validation","iterations","before","early","stopping.","<","br",">","`","val_check_steps","`",":","int=100",",","Number","of","training","steps","between","every","validation","loss","check.","<","br",">","`","batch_size","`",":","int=32",",","number","of","different","series","in","each","batch.","<","br",">","`","valid_batch_size","`",":","int=None",",","number","of","different","series","in","each","validation","and","test","batch",",","if","None","uses","batch_size.","<","br",">","`","windows_batch_size","`",":","int=1024",",","number","of","windows","to","sample","in","each","training","batch",",","default","uses","all.","<","br",">","`","inference_windows_batch_size","`",":","int=-1",",","number","of","windows","to","sample","in","each","inference","batch",",","-1","uses","all.","<","br",">","`","start_padding_enabled","`",":","bool=False",",","if","True",",","the","model","will","pad","the","time","series","with","zeros","at","the","beginning",",","by","input","size.","<","br",">","`","step_size","`",":","int=1",",","step","size","between","each","window","of","temporal","data.","<","br",">","`","scaler_type","`",":","str='identity","'",",","type","of","scaler","for","temporal","inputs","normalization","see","[","temporal","scalers","]","(","https",":","\/\/nixtla.github.io\/neuralforecast\/common.scalers.html",")",".","<","br",">","`","random_seed","`",":","int",",","random_seed","for","pytorch","initializer","and","numpy","generators.","<","br",">","`","num_workers_loader","`",":","int=os.cpu_count","(",")",",","workers","to","be","used","by","`","TimeSeriesDataLoader","`",".","<","br",">","`","drop_last_loader","`",":","bool=False",",","if","True","`","TimeSeriesDataLoader","`","drops","last","non-full","batch.","<","br",">","`","alias","`",":","str",",","optional",",","Custom","name","of","the","model.","<","br",">","`","*","*","trainer_kwargs","`",":","int",",","keyword","trainer","arguments","inherited","from","[","PyTorch","Lighning","'s","trainer","]","(","https",":","\/\/pytorch-lightning.readthedocs.io\/en\/stable\/api\/pytorch_lightning.trainer.trainer.Trainer.html","?","highlight=trainer",")",".","<","br",">","*","*","References","*","*","<","br",">","-","[","David","Salinas",",","Valentin","Flunkert",",","Jan","Gasthaus",",","Tim","Januschowski","(","2020",")",".","``","DeepAR",":","Probabilistic","forecasting","with","autoregressive","recurrent","networks","''",".","International","Journal","of","Forecasting",".","]","(","https",":","\/\/www.sciencedirect.com\/science\/article\/pii\/S0169207019301888",")","<","br",">","-","[","Alexander","Alexandrov","et",".","al","(","2020",")",".","``","GluonTS",":","Probabilistic","and","Neural","Time","Series","Modeling","in","Python","''",".","Journal","of","Machine","Learning","Research",".","]","(","https",":","\/\/www.jmlr.org\/papers\/v21\/19-820.html",")","<","br",">"]
code: def predict_step(self, batch, batch_idx):
      self.h == self.horizon_backup
  
      # TODO: Hack to compute number of windows
      windows = self._create_windows(batch, step="predict")
      n_windows = len(windows["temporal"])
      y_idx = batch["y_idx"]
  
      # Number of windows in batch
      windows_batch_size = self.inference_windows_batch_size
      if windows_batch_size < 0:
          windows_batch_size = n_windows
      n_batches = int(np.ceil(n_windows / windows_batch_size))
  
      y_hats = []
      for i in range(n_batches):
          # Create and normalize windows [Ws, L+H, C]
          w_idxs = np.arange(
              i * windows_batch_size,
              min((i + 1) * windows_batch_size, n_windows),
          )
          windows = self._create_windows(
              batch, step="predict", w_idxs=w_idxs
          )
          windows = self._normalization(windows=windows, y_idx=y_idx)
  
          # Parse windows
          (
              insample_y,
              insample_mask,
              _,
              _,
              _,
              futr_exog,
              stat_exog,
          ) = self._parse_windows(batch, windows)
          windows_batch = dict(
              insample_y=insample_y,  # [Ws, L]
              insample_mask=insample_mask,  # [Ws, L]
              futr_exog=futr_exog,  # [Ws, L+H]
              stat_exog=stat_exog,
              temporal_cols=batch["temporal_cols"],
              y_idx=y_idx,
          )
  
          # Model Predictions
          y_hat = self(windows_batch)
          # Monte Carlo already returns y_hat with mean and quantiles
          y_hats.append(y_hat)
      y_hat = torch.cat(y_hats, dim=0)
      return y_hat
  
imports: import numpy
  import torch
  import torch.nn
  import logging
  import warnings
  from typing import Optional
  from ..common._base_windows import BaseWindows
  from ..losses.pytorch import DistributionLoss, MQLoss
label_desc: Use image node_id 4 for calling the DeepAR obj's underlying member method code with example usage: obj.predict_step(batch, batch_idx) and returns: y_hat