class_docstr: Here we collect all the methods needed for generating NPTS Forecasts.
class_docstr_tok: ["Here","we","collect","all","the","methods","needed","for","generating","NPTS","Forecasts","."]
docstr: Given the `targets`, generates `Forecast` containing prediction samples
  for `predcition_length` time points.
  
  Predictions are generated via weighted sampling where the weights are
  specified in `sampling_weights_iterator`.
  
  Parameters
  ----------
  targets
      targets to predict
  prediction_length
      prediction length
  sampling_weights_iterator
      iterator over weights used for sampling
  num_samples
      number of samples to set in the :class:`SampleForecast` object
  item_id
      item_id to identify the time series
  Returns
  -------
  SampleForecast
     a :class:`SampleForecast` object for the given targets
docstr_tok: ["Given","the","`","targets","`",",","generates","`","Forecast","`","containing","prediction","samples","for","`","predcition_length","`","time","points",".","Predictions","are","generated","via","weighted","sampling","where","the","weights","are","specified","in","`","sampling_weights_iterator","`",".","Parameters","--","--","--","--","--","targets","targets","to","predict","prediction_length","prediction","length","sampling_weights_iterator","iterator","over","weights","used","for","sampling","num_samples","number","of","samples","to","set","in","the",":","class",":","`","SampleForecast","`","object","item_id","item_id","to","identify","the","time","series","Returns","--","--","--","-","SampleForecast","a",":","class",":","`","SampleForecast","`","object","for","the","given","targets"]
code: def predict(
      targets: pd.Series,
      prediction_length: int,
      sampling_weights_iterator: Iterator[np.ndarray],
      num_samples: int,
      item_id: Optional[Any] = None,
  ) -> SampleForecast:
      """
      Given the `targets`, generates `Forecast` containing prediction samples
      for `predcition_length` time points.
  
      Predictions are generated via weighted sampling where the weights are
      specified in `sampling_weights_iterator`.
  
      Parameters
      ----------
      targets
          targets to predict
      prediction_length
          prediction length
      sampling_weights_iterator
          iterator over weights used for sampling
      num_samples
          number of samples to set in the :class:`SampleForecast` object
      item_id
          item_id to identify the time series
      Returns
      -------
      SampleForecast
         a :class:`SampleForecast` object for the given targets
      """
  
      # Note that to generate prediction from the second time step onwards,
      # we need the sample predicted for all the previous time steps in the
      # prediction range.
      # To make this simpler, we replicate the training targets for
      # `num_samples` times.
  
      # samples shape: (num_samples, train_length + prediction_length)
      samples = np.tile(
          A=np.concatenate(
              (targets.values, np.zeros(prediction_length))
          ),
          reps=(num_samples, 1),
      )
  
      train_length = len(targets)
      for t, sampling_weights in enumerate(sampling_weights_iterator):
          samples_ix = WeightedSampler.sample(
              sampling_weights, num_samples
          )
          samples[:, train_length + t] = samples[
              np.arange(num_samples), samples_ix
          ]
  
      # Forecast takes as input the prediction range samples, the start date
      # of the prediction range, and the frequency of the time series.
      samples_pred_range = samples[
          :, train_length:
      ]  # prediction range only
  
      forecast_start = targets.index[-1] + 1 * targets.index.freq
  
      return SampleForecast(
          samples=samples_pred_range,
          start_date=forecast_start,
          item_id=item_id,
      )
  
file_path: gluonts/src/gluonts/model/npts/_model.py
imports: from typing import Any, Callable, Iterator, List, Optional, cast
  import numpy
  import pandas
  from gluonts.model.forecast import SampleForecast
  from ._weighted_sampler import WeightedSampler
label_desc: Use image node_id 2 for calling the NPTS obj's underlying member method code with example usage: obj.predict(targets, prediction_length, sampling_weights_iterator, num_samples, item_id) and returns: SampleForecast