code: def naive_reconcilation_mat(S: np.ndarray, nodes: List):
      """
      Returns the (average) reconciliation matrix that reconciles forecasts from all levels.
      In particular, it first computes mapping matrices `G` to reconcile base forecasts of any chosen level.
      The G matrix is the one described in the book: https://otexts.com/fpp2/mapping-matrices.html
      After obtining such `G` matrices for each level (G_1, G_2, ..., G_k), it computes the final `projection` or the
      `reconciliation` matrix as:
                  P = S (G_1 + G_2 + ... + G_k) / k.
      This way it would use the un-reconciled forecasts of all nodes in the hierarchy to arrive at the final coherent
      forecasts.
      Parameters
      ----------
      S
          Summation or aggregation matrix. Shape: (total_num_time_series, num_base_time_series)
      nodes
          Node structure representing the hierarchy as defined in the hts package.
          To know the exact structure of nodes see the help:
          Hierarchical: https://stackoverflow.com/questions/13579292/how-to-use-hts-with-multi-level-hierarchies
          Grouped: https://robjhyndman.com/hyndsight/gts/
      Returns
      -------
      Numpy array of shape: (total_num_time_series, total_num_time_series)
      """
      num_ts, num_bottom_series = S.shape
      num_nodes_per_level = [1] + [
          np.asscalar(np.sum(n)) for n in nodes
      ]
      cum_num_nodes_per_level = np.cumsum(num_nodes_per_level)
  
      def mapping_matrix_at_level(level: int):
          start_ix = (
              0 if level == 0 else cum_num_nodes_per_level[level - 1]
          )
          end_ix = cum_num_nodes_per_level[level]
  
          M = np.zeros((num_bottom_series, num_ts))
          M[:, start_ix:end_ix] = S[start_ix:end_ix, :].transpose()
  
          # equal proportions
          row_sum = M[:, start_ix:end_ix].sum(axis=0)
          M[:, start_ix:end_ix] = (
              M[:, start_ix:end_ix] / row_sum[None, :]
          )
          return M
  
      mapping_matrices = np.array(
          [
              mapping_matrix_at_level(level=level)
              for level in range(len(cum_num_nodes_per_level))
          ]
      )
  
      mean_mapping_matrix = np.mean(mapping_matrices, axis=0)
      reconciliation_mat = np.matmul(S, mean_mapping_matrix)
  
      return reconciliation_mat
  
imports: from typing import Iterator, List
  import numpy
  import pandas
  from gluonts.core.component import validated
  from gluonts.model.forecast import SampleForecast
  from gluonts.mx import Tensor
label_desc: Use image node_id 7 for calling a global function with example usage: naive_reconcilation_mat(S, nodes) and returns: reconciliation_mat, M