code: def _update_td_fcst(g_matrix, x_sf, conn_df):
      """Update the "G" matrix for the top down forecast proportions method.
  
      Reconciliation methods require the G matrix. The G matrix is used to redefine
      base forecasts for the entire hierarchy to the bottom-level only before
      summation using the S matrix.
  
      This takes the gmatrix template from _get_g_matrix_td_fcst() and updates
      it based on a single forecast.
      Please refer to [1]_ for further information.
  
      Parameters
      ----------
      g_matrix :  pd.DataFrame reconciliation matrix template from
          _get_g_matrix_td_fcst()
      x_sf : pd.Series which contains a hierarchy forecast for a single timepoint
      conn_df : A look up table containing the child and parent of each connection
          in a hierarchy
  
      Returns
      -------
      g_matrix : pd.DataFrame with rows equal to the number of bottom level nodes
          only, i.e. with no aggregate nodes, and columns equal to the number of
          unique nodes in the hierarchy. The matrix indexes is inherited from the
          input data, with the time level removed.
  
      References
      ----------
      .. [1] https://otexts.com/fpp3/hierarchical.html
      """
      for i in g_matrix.index:
          # start from each bottom index
          child = i
          props = []
          # if the bottom level are single strings, integers, or whatever
          if not isinstance(child, tuple):
              child_chk = (child,)
          else:
              child_chk = child
  
          while sum([j == "__total" for j in list(child_chk)]) < len(
              child_chk
          ):
              # find the parent of the child
              parent = conn_df.loc[
                  conn_df["child"] == child, "parent"
              ].values[0]
              # now need to find nodes directly connected to the parent
              children = conn_df.loc[
                  conn_df["parent"] == parent, "child"
              ].unique()
              # calculate proportions
              props.append(
                  (x_sf.loc[child] / x_sf.loc[children].sum()).values[0]
              )
              # move up the chain
              child = parent
              if not isinstance(child, tuple):
                  child_chk = (child,)
              else:
                  child_chk = child
  
          g_matrix.loc[i, "__total"] = np.prod(props)
  
      return g_matrix
  
imports: import numpy
  import pandas
  from numpy.linalg import inv
  from sktime.transformations.base import BaseTransformer
  from sktime.transformations.hierarchical.aggregate import _check_index_no_total
  from sktime.utils.warnings import warn
label_desc: Use image node_id 6 for calling a global function with example usage: _update_td_fcst(g_matrix, x_sf, conn_df) and returns: g_matrix