class_docstr: An ensemble N-BEATS Estimator (approximately) as described
  in the paper:  https://arxiv.org/abs/1905.10437.
  
  The three meta parameters 'meta_context_length', 'meta_loss_function' and 'meta_bagging_size'
  together define the way the sub-models are assembled together.
  The total number of models used for the ensemble is::
  
      |meta_context_length| x |meta_loss_function| x meta_bagging_size
  
  Noteworthy differences in this implementation compared to the paper:
  * The parameter L_H is not implemented; we sample training sequences
  using the default method in GluonTS using the "InstanceSplitter".
  
  Parameters
  ----------
  freq
      Time time granularity of the data
  prediction_length
      Length of the prediction. Also known as 'horizon'.
  meta_context_length
      The different 'context_length' (also known as 'lookback period')
      to use for training the models.
      The 'context_length' is the number of time units that condition the predictions.
      Default and recommended value: [multiplier * prediction_length for multiplier in range(2, 7)]
  meta_loss_function
      The different 'loss_function' (also known as metric) to use for training the models.
      Unlike other models in GluonTS this network does not use a distribution.
      Default and recommended value: ["sMAPE", "MASE", "MAPE"]
  meta_bagging_size
      The number of models that share the parameter combination of 'context_length'
      and 'loss_function'. Each of these models gets a different initialization random initialization.
      Default and recommended value: 10
  trainer
      Trainer object to be used (default: Trainer())
  num_stacks:
      The number of stacks the network should contain.
      Default and recommended value for generic mode: 30
      Recommended value for interpretable mode: 2
  num_blocks
      The number of blocks per stack.
      A list of ints of length 1 or 'num_stacks'.
      Default and recommended value for generic mode: [1]
      Recommended value for interpretable mode: [3]
  block_layers
      Number of fully connected layers with ReLu activation per block.
      A list of ints of length 1 or 'num_stacks'.
      Default and recommended value for generic mode: [4]
      Recommended value for interpretable mode: [4]
  widths
      Widths of the fully connected layers with ReLu activation in the blocks.
      A list of ints of length 1 or 'num_stacks'.
      Default and recommended value for generic mode: [512]
      Recommended value for interpretable mode: [256, 2048]
  sharing
      Whether the weights are shared with the other blocks per stack.
      A list of ints of length 1 or 'num_stacks'.
      Default and recommended value for generic mode: [False]
      Recommended value for interpretable mode: [True]
  expansion_coefficient_lengths
      If the type is "G" (generic), then the length of the expansion coefficient.
      If type is "T" (trend), then it corresponds to the degree of the polynomial.
      If the type is "S" (seasonal) then its not used.
      A list of ints of length 1 or 'num_stacks'.
      Default value for generic mode: [32]
      Recommended value for interpretable mode: [3]
  stack_types
      One of the following values: "G" (generic), "S" (seasonal) or "T" (trend).
      A list of strings of length 1 or 'num_stacks'.
      Default and recommended value for generic mode: ["G"]
      Recommended value for interpretable mode: ["T","S"]
  **kwargs
      Arguments passed down to the individual estimators.
class_docstr_tok: ["An","ensemble","N-BEATS","Estimator","(","approximately",")","as","described","in","the","paper",":","https",":","\/\/arxiv.org\/abs\/1905.10437",".","The","three","meta","parameters","'meta_context_length","'",",","'meta_loss_function","'","and","'meta_bagging_size'","together","define","the","way","the","sub-models","are","assembled","together",".","The","total","number","of","models","used","for","the","ensemble","is",":",":","|meta_context_length|","x","|meta_loss_function|","x","meta_bagging_size","Noteworthy","differences","in","this","implementation","compared","to","the","paper",":","*","The","parameter","L_H","is","not","implemented",";","we","sample","training","sequences","using","the","default","method","in","GluonTS","using","the","``","InstanceSplitter","''",".","Parameters","--","--","--","--","--","freq","Time","time","granularity","of","the","data","prediction_length","Length","of","the","prediction",".","Also","known","as","'horizon","'",".","meta_context_length","The","different","'context_length","'","(","also","known","as","'lookback","period","'",")","to","use","for","training","the","models",".","The","'context_length","'","is","the","number","of","time","units","that","condition","the","predictions",".","Default","and","recommended","value",":","[","multiplier","*","prediction_length","for","multiplier","in","range","(","2",",","7",")","]","meta_loss_function","The","different","'loss_function","'","(","also","known","as","metric",")","to","use","for","training","the","models",".","Unlike","other","models","in","GluonTS","this","network","does","not","use","a","distribution",".","Default","and","recommended","value",":","[","``","sMAPE","''",",","``","MASE","''",",","``","MAPE","''","]","meta_bagging_size","The","number","of","models","that","share","the","parameter","combination","of","'context_length'","and","'loss_function","'",".","Each","of","these","models","gets","a","different","initialization","random","initialization",".","Default","and","recommended","value",":","10","trainer","Trainer","object","to","be","used","(","default",":","Trainer","(",")",")","num_stacks",":","The","number","of","stacks","the","network","should","contain",".","Default","and","recommended","value","for","generic","mode",":","30","Recommended","value","for","interpretable","mode",":","2","num_blocks","The","number","of","blocks","per","stack",".","A","list","of","ints","of","length","1","or","'num_stacks","'",".","Default","and","recommended","value","for","generic","mode",":","[","1","]","Recommended","value","for","interpretable","mode",":","[","3","]","block_layers","Number","of","fully","connected","layers","with","ReLu","activation","per","block",".","A","list","of","ints","of","length","1","or","'num_stacks","'",".","Default","and","recommended","value","for","generic","mode",":","[","4","]","Recommended","value","for","interpretable","mode",":","[","4","]","widths","Widths","of","the","fully","connected","layers","with","ReLu","activation","in","the","blocks",".","A","list","of","ints","of","length","1","or","'num_stacks","'",".","Default","and","recommended","value","for","generic","mode",":","[","512","]","Recommended","value","for","interpretable","mode",":","[","256",",","2048","]","sharing","Whether","the","weights","are","shared","with","the","other","blocks","per","stack",".","A","list","of","ints","of","length","1","or","'num_stacks","'",".","Default","and","recommended","value","for","generic","mode",":","[","False","]","Recommended","value","for","interpretable","mode",":","[","True","]","expansion_coefficient_lengths","If","the","type","is","``","G","''","(","generic",")",",","then","the","length","of","the","expansion","coefficient",".","If","type","is","``","T","''","(","trend",")",",","then","it","corresponds","to","the","degree","of","the","polynomial",".","If","the","type","is","``","S","''","(","seasonal",")","then","its","not","used",".","A","list","of","ints","of","length","1","or","'num_stacks","'",".","Default","value","for","generic","mode",":","[","32","]","Recommended","value","for","interpretable","mode",":","[","3","]","stack_types","One","of","the","following","values",":","``","G","''","(","generic",")",",","``","S","''","(","seasonal",")","or","``","T","''","(","trend",")",".","A","list","of","strings","of","length","1","or","'num_stacks","'",".","Default","and","recommended","value","for","generic","mode",":","[","``","G","''","]","Recommended","value","for","interpretable","mode",":","[","``","T","''",",","''","S","''","]","*","*","kwargs","Arguments","passed","down","to","the","individual","estimators","."]
code: def _estimator_factory(self, **kwargs):
      estimators = []
      for context_length, loss_function, init_id in product(
          self.meta_context_length,
          self.meta_loss_function,
          list(range(self.meta_bagging_size)),
      ):
          # So far no use for the init_id, models are by default always randomly initialized
          estimators.append(
              NBEATSEstimator(
                  freq=self.freq,
                  prediction_length=self.prediction_length,
                  context_length=context_length,
                  trainer=copy.deepcopy(self.trainer),
                  num_stacks=self.num_stacks,
                  widths=self.widths,
                  num_blocks=self.num_blocks,
                  num_block_layers=self.num_block_layers,
                  expansion_coefficient_lengths=self.expansion_coefficient_lengths,
                  sharing=self.sharing,
                  stack_types=self.stack_types,
                  loss_function=loss_function,
                  **kwargs,
              )
          )
      return estimators
  
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 2 for calling the NBEATSEnsembleEstimator obj's underlying member method code with example usage: obj._estimator_factory() and returns: estimators