class_docstr: Implementation of Non-Parametric Time Series Forecaster.
  
  Forecasts of NPTS for time step :math:`T` are one of the previous values
  of the time series (these could be known values or predictions), sampled
  according to the (un-normalized) distribution :math:`q_T(t) > 0` where
  :math:`0 <= t < T`.
  
  The distribution :math:`q_T` is expressed in terms of a feature map
  :math:`f(t)` which associates a time step :math:`t` with a
  :math:`D`-dimensional feature map :math:`[f_1(t), ..., f_D(t)]`. More
  details on the feature map can be found below.
  
  We offer two types of distribution kernels.
  
  **Exponential Kernel (NPTS Forecaster)**
  
    The sampling distribution :math:`q_T` for the `exponential` kernel
    can be `weighted` or `unweighted` and is defined as follows.
  
    .. math::
  
      q_T(t) =
      \begin{cases}
        \exp( - \sum_{i=1}^D \alpha   \left| f_i(t) - f_i(T) \right| )
          & \text{unweighted}\\
        \exp( - \sum_{i=1}^D \alpha_i \left| f_i(t) - f_i(T) \right| )
          & \text{weighted}
      \end{cases}
  
    In the above definition :math:`\alpha > 0` and :math:`\alpha_i > 0` are
    user-defined sampling weights.
  
  **Uniform Kernel (Climatological Forecaster)**
  
    The sampling distribution :math:`q_T` for the `uniform` kernel can be
    `seasonal` or not. The `seasonal` version is defined as follows.
  
    .. math::
  
       q_T(t) =
       \begin{cases}
         1.0
           & \text{if }f(t) = f(T) \\
         0.0
           & \text{otherwise}
       \end{cases}
  
    The `not seasonal` version is defined as the constant map.
  
    .. math::
  
       q_T(t) = 1.0
  
  **Feature Map**
  
    The feature map :math:`f` is configurable. The special case
    :math:`f(t) = [t]` results in the so-called `naive NPTS`. For
    non-seasonal models, by default we have :math:`f(t) = [t]` for the NPTS
    Forecaster (i.e., with the `exponential` kernel) and no features for the
    Climatological Forecaster (i.e., the `uniform` kernel).
  
    For seasonal NPTS and seasonal Climatological, time features are
    determined based on the frequency of the time series are added to the
    default feature map.
  
    The default time features for various frequencies are
  
    .. math::
  
       f(t) =
       \begin{cases}
         [\mathit{MINUTE\_OF\_HOUR}(t)] & \text{for minutely frequency}\\
         [\mathit{HOUR\_OF\_DAY}(t)]    & \text{for hourly frequency}\\
         [\mathit{DAY\_OF\_WEEK}(t)]    & \text{for daily frequency}\\
         [\mathit{DAY\_OF\_MONTH}(t)]   & \text{for weekly frequency}\\
         [\mathit{MONTH\_OF\_YEAR}(t)]  & \text{for monthly frequency}
       \end{cases}
  
    During prediction, one can provide custom features in `feat_dynamic_real`
    (these have to be defined in both the training and the prediction range).
    If the model is seasonal, these custom features are added to the default
    feature map, otherwise they are ignored. If `feat_dynamic_real` is not
    empty, one can disable default time features by setting the flag
    `use_default_time_features` to `False`.
  
  Parameters
  ----------
  
  prediction_length
      number of time steps to predict
  context_length
      number of time-steps that are considered before making predictions
      (the default value of None corresponds to the case where all time steps
      in the history are considered)
  kernel_type
      the type of kernel to use (either "exponential" or "uniform")
  exp_kernel_weights
      single weight :math:`\alpha` or the weights for the features to use
      in the exponential kernel; currently, we use the single weight version
      and for seasonal NPTS we just rescale :math:`\alpha` by `feature_scale`
      for seasonal features.
  use_seasonal_model
      whether to use seasonal variant
  use_default_time_features
      time features derived based on the frequency of the time series
  num_default_time_features
      this is not exposed; this parameter is for having more control on the
      number of default time features, as the date_feature_set adds too
      many per default.
  feature_scale
      scale for time (seasonal) features in order to sample past seasons
      with higher probability
class_docstr_tok: ["Implementation","of","Non-Parametric","Time","Series","Forecaster",".","Forecasts","of","NPTS","for","time","step",":","math",":","`","T","`","are","one","of","the","previous","values","of","the","time","series","(","these","could","be","known","values","or","predictions",")",",","sampled","according","to","the","(","un-normalized",")","distribution",":","math",":","`","q_T","(","t",")",">","0","`","where",":","math",":","`","0","<","=","t","<","T","`",".","The","distribution",":","math",":","`","q_T","`","is","expressed","in","terms","of","a","feature","map",":","math",":","`","f","(","t",")","`","which","associates","a","time","step",":","math",":","`","t","`","with","a",":","math",":","`","D","`","-dimensional","feature","map",":","math",":","`","[","f_1","(","t",")",",","...",",","f_D","(","t",")","]","`",".","More","details","on","the","feature","map","can","be","found","below",".","We","offer","two","types","of","distribution","kernels",".","*","*","Exponential","Kernel","(","NPTS","Forecaster",")","*","*","The","sampling","distribution",":","math",":","`","q_T","`","for","the","`","exponential","`","kernel","can","be","`","weighted","`","or","`","unweighted","`","and","is","defined","as","follows",".","..","math",":",":","q_T","(","t",")","=","\\begin","{","cases","}","\\exp","(","-","\\sum_","{","i=1","}","^D","\\alpha","\\left|","f_i","(","t",")","-","f_i","(","T",")","\\right|",")","&","\\text","{","unweighted","}","\\\\","\\exp","(","-","\\sum_","{","i=1","}","^D","\\alpha_i","\\left|","f_i","(","t",")","-","f_i","(","T",")","\\right|",")","&","\\text","{","weighted","}","\\end","{","cases","}","In","the","above","definition",":","math",":","`","\\alpha",">","0","`","and",":","math",":","`","\\alpha_i",">","0","`","are","user-defined","sampling","weights",".","*","*","Uniform","Kernel","(","Climatological","Forecaster",")","*","*","The","sampling","distribution",":","math",":","`","q_T","`","for","the","`","uniform","`","kernel","can","be","`","seasonal","`","or","not",".","The","`","seasonal","`","version","is","defined","as","follows",".","..","math",":",":","q_T","(","t",")","=","\\begin","{","cases","}","1.0","&","\\text","{","if","}","f","(","t",")","=","f","(","T",")","\\\\","0.0","&","\\text","{","otherwise","}","\\end","{","cases","}","The","`","not","seasonal","`","version","is","defined","as","the","constant","map",".","..","math",":",":","q_T","(","t",")","=","1.0","*","*","Feature","Map","*","*","The","feature","map",":","math",":","`","f","`","is","configurable",".","The","special","case",":","math",":","`","f","(","t",")","=","[","t","]","`","results","in","the","so-called","`","naive","NPTS","`",".","For","non-seasonal","models",",","by","default","we","have",":","math",":","`","f","(","t",")","=","[","t","]","`","for","the","NPTS","Forecaster","(","i.e.",",","with","the","`","exponential","`","kernel",")","and","no","features","for","the","Climatological","Forecaster","(","i.e.",",","the","`","uniform","`","kernel",")",".","For","seasonal","NPTS","and","seasonal","Climatological",",","time","features","are","determined","based","on","the","frequency","of","the","time","series","are","added","to","the","default","feature","map",".","The","default","time","features","for","various","frequencies","are","..","math",":",":","f","(","t",")","=","\\begin","{","cases","}","[","\\mathit","{","MINUTE\\_OF\\_HOUR","}","(","t",")","]","&","\\text","{","for","minutely","frequency","}","\\\\","[","\\mathit","{","HOUR\\_OF\\_DAY","}","(","t",")","]","&","\\text","{","for","hourly","frequency","}","\\\\","[","\\mathit","{","DAY\\_OF\\_WEEK","}","(","t",")","]","&","\\text","{","for","daily","frequency","}","\\\\","[","\\mathit","{","DAY\\_OF\\_MONTH","}","(","t",")","]","&","\\text","{","for","weekly","frequency","}","\\\\","[","\\mathit","{","MONTH\\_OF\\_YEAR","}","(","t",")","]","&","\\text","{","for","monthly","frequency","}","\\end","{","cases","}","During","prediction",",","one","can","provide","custom","features","in","`","feat_dynamic_real","`","(","these","have","to","be","defined","in","both","the","training","and","the","prediction","range",")",".","If","the","model","is","seasonal",",","these","custom","features","are","added","to","the","default","feature","map",",","otherwise","they","are","ignored",".","If","`","feat_dynamic_real","`","is","not","empty",",","one","can","disable","default","time","features","by","setting","the","flag","`","use_default_time_features","`","to","`","False","`",".","Parameters","--","--","--","--","--","prediction_length","number","of","time","steps","to","predict","context_length","number","of","time-steps","that","are","considered","before","making","predictions","(","the","default","value","of","None","corresponds","to","the","case","where","all","time","steps","in","the","history","are","considered",")","kernel_type","the","type","of","kernel","to","use","(","either","``","exponential","''","or","``","uniform","''",")","exp_kernel_weights","single","weight",":","math",":","`","\\alpha","`","or","the","weights","for","the","features","to","use","in","the","exponential","kernel",";","currently",",","we","use","the","single","weight","version","and","for","seasonal","NPTS","we","just","rescale",":","math",":","`","\\alpha","`","by","`","feature_scale","`","for","seasonal","features",".","use_seasonal_model","whether","to","use","seasonal","variant","use_default_time_features","time","features","derived","based","on","the","frequency","of","the","time","series","num_default_time_features","this","is","not","exposed",";","this","parameter","is","for","having","more","control","on","the","number","of","default","time","features",",","as","the","date_feature_set","adds","too","many","per","default",".","feature_scale","scale","for","time","(","seasonal",")","features","in","order","to","sample","past","seasons","with","higher","probability"]
docstr: Internal method for computing default, (optional) seasonal features for
  the training and prediction ranges given time index for the training
  range and the prediction length.
  
  Appends `custom_features` if provided.
  
  Parameters
  ----------
  train_index
      Pandas PeriodIndex
  prediction_length
      prediction length
  custom_features
      shape: (num_custom_features, train_length + pred_length)
  
  Returns
  -------
  a tuple of (training, prediction) feature tensors
      shape: (num_features, train_length/pred_length)
docstr_tok: ["Internal","method","for","computing","default",",","(","optional",")","seasonal","features","for","the","training","and","prediction","ranges","given","time","index","for","the","training","range","and","the","prediction","length",".","Appends","`","custom_features","`","if","provided",".","Parameters","--","--","--","--","--","train_index","Pandas","PeriodIndex","prediction_length","prediction","length","custom_features","shape",":","(","num_custom_features",",","train_length","+","pred_length",")","Returns","--","--","--","-","a","tuple","of","(","training",",","prediction",")","feature","tensors","shape",":","(","num_features",",","train_length\/pred_length",")"]
code: def _get_features(
      self,
      train_index: pd.PeriodIndex,
      prediction_length: int,
      custom_features: Optional[np.ndarray] = None,
  ) -> Tuple[np.ndarray, np.ndarray]:
      """
      Internal method for computing default, (optional) seasonal features for
      the training and prediction ranges given time index for the training
      range and the prediction length.
  
      Appends `custom_features` if provided.
  
      Parameters
      ----------
      train_index
          Pandas PeriodIndex
      prediction_length
          prediction length
      custom_features
          shape: (num_custom_features, train_length + pred_length)
  
      Returns
      -------
      a tuple of (training, prediction) feature tensors
          shape: (num_features, train_length/pred_length)
      """
  
      train_length = len(train_index)
      full_time_index = pd.period_range(
          train_index.min(),
          periods=train_length + prediction_length,
          freq=train_index.freq,
      )
  
      # Default feature map for both seasonal and non-seasonal models.
      if self._is_exp_kernel():
          # Default time index features: index of the time point
          # [0, train_length + pred_length - 1]
          features = np.expand_dims(
              np.array(range(len(full_time_index))), axis=0
          )
  
          # Rescale time index features into the range: [-0.5, 0.5]
          # similar to the seasonal features
          # (see gluonts.time_feature)
          features = (
              features / (train_length + prediction_length - 1) - 0.5
          )
      else:
          # For uniform seasonal model we do not add time index features
          features = np.empty((0, len(full_time_index)))
  
      # Add more features for seasonal variant
      if self.use_seasonal_model:
          if custom_features is not None:
              total_length = train_length + prediction_length
  
              assert len(custom_features.shape) == 2, (
                  "Custom features should be 2D-array where the rows "
                  "represent features and columns the time points."
              )
  
              assert custom_features.shape[1] == total_length, (
                  "For a seasonal model, feat_dynamic_real must be defined "
                  "for both training and prediction ranges. They are only "
                  f"provided for {custom_features.shape[1]} time steps "
                  f"instead of {train_length + prediction_length} steps."
              )
  
              features = np.vstack(
                  [features, self.feature_scale * custom_features]
              )
  
          if self.use_default_time_features or custom_features is None:
              # construct seasonal features
              seasonal_features_gen = time_features_from_frequency_str(
                  full_time_index.freqstr
              )
              seasonal_features = [
                  self.feature_scale * gen(full_time_index)
                  for gen in seasonal_features_gen[
                      : self.num_default_time_features
                  ]
              ]
  
              features = np.vstack([features, *seasonal_features])
  
      train_features = features[:, :train_length]
      pred_features = features[:, train_length:]
  
      return train_features, pred_features
  
imports: from enum import Enum
  from typing import Any, Iterator, List, Optional, Tuple, Union
  import numpy
  import pandas
  from gluonts.core.component import validated
  from gluonts.dataset.common import Dataset
  from gluonts.exceptions import GluonTSDataError
  from gluonts.model.forecast import SampleForecast
  from gluonts.model.predictor import RepresentablePredictor
  from gluonts.time_feature import time_features_from_frequency_str
  from ._model import NPTS
label_desc: Use image node_id 5 for calling the NPTSPredictor obj's underlying member method code with example usage: obj._get_features(train_index, prediction_length, custom_features) and returns: train_features,  pred_features