class_docstr: Class for representing hierarchical time series.
  
  The hierarchy is represented by the standard aggregation matrix `S`.
  The time series at the bottom (leaf) level of the hierarchy
  (`ts_at_bottom_level`) are assumed to be given by the columns of
  a single pandas dataframe.
  
  The ordering of columns of `ts_at_bottom_level` should be consistent
  with the ordering of the columns of `S`.
  
  Parameters
  ----------
  ts_at_bottom_level
      A single pandas dataframe whose columns are the time series
      corresponding to the leaves of the hierarchy.
  S
      Summation or aggregation matrix whose ordering should be consistent
      with the ordering of the columns of `ts_at_all_levels`.
      In particular, the bottom `k x k` sub-matrix should be identity matrix,
      where `k` is the number of leaves of the hierarchy.
class_docstr_tok: ["Class","for","representing","hierarchical","time","series",".","The","hierarchy","is","represented","by","the","standard","aggregation","matrix","`","S","`",".","The","time","series","at","the","bottom","(","leaf",")","level","of","the","hierarchy","(","`","ts_at_bottom_level","`",")","are","assumed","to","be","given","by","the","columns","of","a","single","pandas","dataframe",".","The","ordering","of","columns","of","`","ts_at_bottom_level","`","should","be","consistent","with","the","ordering","of","the","columns","of","`","S","`",".","Parameters","--","--","--","--","--","ts_at_bottom_level","A","single","pandas","dataframe","whose","columns","are","the","time","series","corresponding","to","the","leaves","of","the","hierarchy",".","S","Summation","or","aggregation","matrix","whose","ordering","should","be","consistent","with","the","ordering","of","the","columns","of","`","ts_at_all_levels","`",".","In","particular",",","the","bottom","`","k","x","k","`","sub-matrix","should","be","identity","matrix",",","where","`","k","`","is","the","number","of","leaves","of","the","hierarchy","."]
docstr: Constructs aggregated time series according to the
  summation/aggregation matrix `S`.
  
  Parameters
  ----------
  ts_at_bottom_level
      A single pandas dataframe whose columns are the time series
      corresponding to the leaves of the hierarchy.
  S
      Summation or aggregation matrix whose ordering should be consistent
      with the ordering of the columns of `ts_at_all_levels`.
      In particular, the bottom `k x k` sub-matrix should be an identity
      matrix, where `k` is the number of leaves of the hierarchy.
  
  Returns
  -------
      A pandas dataframe consisting of aggregated time series
      (at all non-leaf levels).
docstr_tok: ["Constructs","aggregated","time","series","according","to","the","summation\/aggregation","matrix","`","S","`",".","Parameters","--","--","--","--","--","ts_at_bottom_level","A","single","pandas","dataframe","whose","columns","are","the","time","series","corresponding","to","the","leaves","of","the","hierarchy",".","S","Summation","or","aggregation","matrix","whose","ordering","should","be","consistent","with","the","ordering","of","the","columns","of","`","ts_at_all_levels","`",".","In","particular",",","the","bottom","`","k","x","k","`","sub-matrix","should","be","an","identity","matrix",",","where","`","k","`","is","the","number","of","leaves","of","the","hierarchy",".","Returns","--","--","--","-","A","pandas","dataframe","consisting","of","aggregated","time","series","(","at","all","non-leaf","levels",")","."]
code: def aggregate_ts(
      ts_at_bottom_level: pd.DataFrame,
      S: np.ndarray,
  ) -> pd.DataFrame:
      """
      Constructs aggregated time series according to the
      summation/aggregation matrix `S`.
  
      Parameters
      ----------
      ts_at_bottom_level
          A single pandas dataframe whose columns are the time series
          corresponding to the leaves of the hierarchy.
      S
          Summation or aggregation matrix whose ordering should be consistent
          with the ordering of the columns of `ts_at_all_levels`.
          In particular, the bottom `k x k` sub-matrix should be an identity
          matrix, where `k` is the number of leaves of the hierarchy.
  
      Returns
      -------
          A pandas dataframe consisting of aggregated time series
          (at all non-leaf levels).
      """
      num_ts, num_bottom_ts = S.shape
      num_agg_ts = num_ts - num_bottom_ts
  
      assert ts_at_bottom_level.shape[1] == num_bottom_ts, (
          "Number of columns of the aggregation matrix `S` and "
          "the dataframe `ts_at_bottom_level` should be  same."
          f"But shape of `S`: {S.shape} and shape of `ts_at_bottom_level`: "
          f"{ts_at_bottom_level.shape}."
      )
  
      # Last `num_bottom_ts` rows contain the identity matrix.
      assert (S[num_agg_ts:, :] == np.eye(num_bottom_ts)).all(), (
          f"The last {num_bottom_ts} rows of aggregation matrix `S`"
          f" should contain Identity matrix."
      )
  
      # First `num_agg_ts` rows contain the aggregation information.
      S_sum = S[:num_agg_ts, :]
  
      # Construct aggregated time series.
      ts_aggregated = pd.concat(
          {
              f"agg_ts_{i}": ts_at_bottom_level.apply(
                  lambda row: np.dot(row, agg),
                  axis=1,
              )
              for i, agg in enumerate(S_sum)
          },
          axis=1,
      )
      ts_aggregated.set_index(ts_at_bottom_level.index, inplace=True)
  
      return ts_aggregated
  
file_path: gluonts/src/gluonts/dataset/hierarchical.py
imports: from typing import Optional
  import numpy
  import pandas
  from gluonts.dataset.pandas import PandasDataset
label_desc: Use image node_id 7 for calling the HierarchicalTimeSeries obj's underlying member method code with example usage: obj.aggregate_ts(ts_at_bottom_level, S) and returns: ts_aggregated