code: def average_link_graph(G):
      """
      Agglomerative function based on a (hopefully sparse) similarity graph
  
      Parameters
      ----------
      G the input graph
  
      Returns
      -------
      t a weightForest structure that represents the dendrogram of the data
  
      CAVEAT
      ------
      In that case, the homogeneity is associated with high similarity
      (as opposed to low cost as in most clustering procedures,
      e.g. distance-based procedures).  Thus the tree is created with
      negated affinity values, in roder to respect the traditional
      ordering of cluster potentials. individual points have the
      potential (-np.inf).
      This problem is handled transparently in the associated segment function.
      """
      warn(
          "Function average_link_graph deprecated, will be removed",
          FutureWarning,
          stacklevel=2,
      )
      # prepare a graph with twice the number of vertices
      n = G.V
      nbcc = G.cc().max() + 1
      K = WeightedGraph(2 * G.V)
      K.E = G.E
      K.edges = G.edges.copy()
      K.weights = G.weights.copy()
  
      parent = np.arange(2 * n - nbcc, dtype=np.int_)
      pop = np.ones(2 * n - nbcc, np.int_)
      height = np.inf * np.ones(2 * n - nbcc)
  
      # iteratively merge clusters
      for q in range(n - nbcc):
          # 1. find the heaviest edge
          m = (K.weights).argmax()
          cost = K.weights[m]
          k = q + n
          height[k] = cost
          i = K.edges[m, 0]
          j = K.edges[m, 1]
  
          # 2. remove the current edge
          K.edges[m] = -1
          K.weights[m] = -np.inf
          m = np.nonzero((K.edges[:, 0] == j) * (K.edges[:, 1] == i))[0]
          K.edges[m] = -1
          K.weights[m] = -np.inf
  
          # 3. merge the edges with third part edges
          parent[i] = k
          parent[j] = k
          pop[k] = pop[i] + pop[j]
          fusion(K, pop, i, j, k)
  
      height[height < 0] = 0
      height[np.isinf(height)] = height[n] + 1
      t = WeightedForest(2 * n - nbcc, parent, -height)
      return t
  
imports: from warnings import warn
  import numpy
  from ..graph.forest import Forest
  from ..graph.graph import WeightedGraph
label_desc: Use image node_id 2 for calling a global function with example usage: average_link_graph(G) and returns: t