code: def predict(
      self, dataset: Dataset, num_samples: Optional[int] = 1, **kwargs
  ) -> Iterator[Forecast]:
      if num_samples != 1:
          logging.warning(
              "NBEATSEnsemblePredictor does not support sampling. "
              "Therefore 'num_samples' will be ignored and set to 1."
          )
      iterators = []
  
      # create the iterators from the predictors
      for predictor in self.predictors:
          iterators.append(predictor.predict(dataset, num_samples=1))
  
      # we always have to predict for one series in the dataset with
      # all models and return it as a 'SampleForecast' so that it is
      # clear that all these prediction concern the same series
      for item in dataset:
          output = []
          start_date = None
  
          for iterator in iterators:
              prediction = next(iterator)
  
              # on order to avoid mypys complaints
              assert isinstance(prediction, SampleForecast)
  
              output.append(prediction.samples)
  
              # get the forecast start date
              if start_date is None:
                  start_date = prediction.start_date
          output = np.stack(output, axis=0)
  
          # aggregating output of different models
          # default according to paper is median,
          # but we can also make use of not aggregating
          if self.aggregation_method == "median":
              output = np.median(output, axis=0)
          elif self.aggregation_method == "mean":
              output = np.mean(output, axis=0)
          else:  # "none": do not aggregate
              pass
  
          # on order to avoid mypys complaints
          assert start_date is not None
  
          yield SampleForecast(
              output,
              start_date=start_date,
              freq=start_date.freqstr,
              item_id=item[FieldName.ITEM_ID]
              if FieldName.ITEM_ID in item
              else None,
              info=item["info"] if "info" in item else None,
          )
  
imports: import copy
  import logging
  from itertools import product
  from typing import List, Optional, Iterator
  import numpy
  from gluonts.core.component import validated
  from gluonts.dataset.field_names import FieldName
  from gluonts.dataset.common import Dataset
  from gluonts.model.predictor import Predictor
  from gluonts.model.forecast import Forecast, SampleForecast
  from pts.model import PyTorchEstimator
  from pts import Trainer
  from .n_beats_estimator import NBEATSEstimator
  from .n_beats_network import VALID_LOSS_FUNCTIONS
label_desc: Use image node_id 3 for calling the NBEATSEnsemblePredictor obj's underlying member method code with example usage: obj.predict(dataset, num_samples) without return types