code: def random_walk_induced_graph_sampling(
      G, N, T=100, growth_size=2, n_starts=5
  ):
      # Refer to https://github.com/Ashish7129/Graph-Sampling
      G = nx.convert_node_labels_to_integers(G, 0, "default", True)
      for n, data in G.nodes(data=True):
          G.node[n]["id"] = n
      n_node = G.number_of_nodes()
      labels = nx.get_node_attributes(G, "label")
      candidate_set = set()
      if len(labels) > 0:
          candidate_set_value = set()
          l = np.random.permutation(list(labels.keys()))
          for i in l:
              for j in labels[i]:
                  if j not in candidate_set_value:
                      candidate_set.add(i)
                      candidate_set_value.add(j)
      while len(candidate_set) < n_starts:
          candidate_set.add(np.random.random_integers(n_node))
      candidate_set = list(candidate_set)[:n_starts]
      sampled_nodes = set()
      for i, temp_node in enumerate(candidate_set):
          sampled_nodes.add(G.node[temp_node]["id"])
          iter_ = 1
          nodes_before_t_iter = 0
          curr_node = temp_node
          N_t = int(N / n_starts) * (i + 1)
          while len(sampled_nodes) < N_t:
              edges = [n for n in G.neighbors(curr_node)]
              index_of_edge = random.randint(0, len(edges) - 1)
              chosen_node = edges[index_of_edge]
              sampled_nodes.add(G.node[chosen_node]["id"])
              curr_node = chosen_node
              iter_ += 1
              if iter_ % T == 0:
                  if (
                      len(sampled_nodes) - nodes_before_t_iter
                      < growth_size
                  ):
                      curr_node = random.randint(0, n_node - 1)
                  nodes_before_t_iter = len(sampled_nodes)
      sampled_graph = G.subgraph(sampled_nodes)
      return sampled_graph
  
imports: import random
  import os
  import sys
  import collections
  import itertools
  import pickle
  import scipy.sparse
  import networkx
  import numpy
  from sklearn.cluster import SpectralClustering
  from sklearn import gaussian_process
  from scipy.optimize import minimize
  from bayes_opt import BayesianOptimization
label_desc: Use image node_id 4 for calling a global function with example usage: random_walk_induced_graph_sampling(G, N, T, growth_size, n_starts) and returns: sampled_graph