code: def tree_generation(ng):
      ng.ndata["keep_eid"] = torch.zeros(ng.num_nodes()).long() - 1
  
      def message_func(edges):
          return {
              "mval": edges.data["edge_dist"],
              "meid": edges.data[dgl.EID],
          }
  
      def reduce_func(nodes):
          ind = torch.min(nodes.mailbox["mval"], dim=1)[1]
          keep_eid = nodes.mailbox["meid"].gather(1, ind.view(-1, 1))
          return {"keep_eid": keep_eid[:, 0]}
  
      node_order = dgl.traversal.topological_nodes_generator(ng)
      ng.prop_nodes(node_order, message_func, reduce_func)
      eids = ng.ndata["keep_eid"]
      eids = eids[eids > -1]
      edges = ng.find_edges(eids)
      treeg = dgl.graph(edges, num_nodes=ng.num_nodes())
      return treeg
  
file_path: dgl/examples/pytorch/hilander/utils/deduce.py
imports: import dgl
  import numpy
  import torch
  from sklearn import mixture
  from .density import density_to_peaks, density_to_peaks_vectorize
label_desc: Use image node_id 7 for calling a global function with example usage: tree_generation(ng) and returns: treeg, dict, dict