class_docstr: Adds aggregate lags as a feature to the data_entry.
  
  Aggregates the original time series to a new frequency and selects
  the aggregated lags of interest. It does not use aggregate lags that
  need the last `prediction_length` values to be computed. Therefore
  the transformation is applicable to both training and inference.
  
  If `is_train=True` the lags have the same length as the `target` field.
  If `is_train=False` the lags have length len(target) + pred_length
  
  Parameters
  ----------
  target_field
      Field with target values (array) of time series
  output_field
      Field name to use for the output.
  pred_length
      Prediction length.
  base_freq
      Base frequency, i.e., the frequency of the original time series.
  agg_freq
      Aggregate frequency, i.e., the frequency of the aggregate time series.
  agg_lags
      List of aggregate lags given in the aggregate frequency. If some of them
      are invalid (need some of the last `prediction_length` values to be
      computed) they are ignored.
  agg_fun
      Aggregation function. Default is 'mean'.
class_docstr_tok: ["Adds","aggregate","lags","as","a","feature","to","the","data_entry",".","Aggregates","the","original","time","series","to","a","new","frequency","and","selects","the","aggregated","lags","of","interest",".","It","does","not","use","aggregate","lags","that","need","the","last","`","prediction_length","`","values","to","be","computed",".","Therefore","the","transformation","is","applicable","to","both","training","and","inference",".","If","`","is_train=True","`","the","lags","have","the","same","length","as","the","`","target","`","field",".","If","`","is_train=False","`","the","lags","have","length","len","(","target",")","+","pred_length","Parameters","--","--","--","--","--","target_field","Field","with","target","values","(","array",")","of","time","series","output_field","Field","name","to","use","for","the","output",".","pred_length","Prediction","length",".","base_freq","Base","frequency",",","i.e.",",","the","frequency","of","the","original","time","series",".","agg_freq","Aggregate","frequency",",","i.e.",",","the","frequency","of","the","aggregate","time","series",".","agg_lags","List","of","aggregate","lags","given","in","the","aggregate","frequency",".","If","some","of","them","are","invalid","(","need","some","of","the","last","`","prediction_length","`","values","to","be","computed",")","they","are","ignored",".","agg_fun","Aggregation","function",".","Default","is","'mean","'","."]
code: def __init__(
      self,
      target_field: str,
      output_field: str,
      pred_length: int,
      base_freq: str,
      agg_freq: str,
      agg_lags: List[int],
      agg_fun: str = "mean",
      dtype: Type = np.float32,
  ) -> None:
      self.pred_length = pred_length
      self.target_field = target_field
      self.feature_name = output_field
      self.base_freq = base_freq
      self.agg_freq = agg_freq
      self.agg_lags = agg_lags
      self.agg_fun = agg_fun
      self.dtype = dtype
  
      self.ratio = pd.Timedelta(self.agg_freq) / pd.Timedelta(
          self.base_freq
      )
      assert self.ratio.is_integer() and self.ratio >= 1, (
          "The aggregate frequency should be a multiple of the base"
          " frequency."
      )
      self.ratio = int(self.ratio)
  
      self.half_window = (self.ratio - 1) // 2
      self.valid_lags = [
          x
          for x in self.agg_lags
          if x > (self.pred_length - 1 + self.half_window) / self.ratio
      ]
  
      if set(self.agg_lags) - set(self.valid_lags):
          print(
              "The aggregate lags"
              f" {set(self.agg_lags) - set(self.valid_lags)} of frequency"
              f" {self.agg_freq} are ignored."
          )
  
imports: from typing import List, Optional, Union, Type
  import numpy
  import pandas
  from gluonts.core.component import validated
  from gluonts.dataset.common import DataEntry
  from gluonts.dataset.field_names import FieldName
  from gluonts.time_feature import TimeFeature
  from ._base import MapTransformation, SimpleTransformation
label_desc: Use image node_id 1 to create a new AddAggregateLags object from inherited base classes: MapTransformation with example: obj = AddAggregateLags(target_field, output_field, pred_length, base_freq, agg_freq, agg_lags, agg_fun, dtype)