code: def init_embedding_from_graph(
      _raw_data,
      graph,
      n_components,
      random_state,
      metric,
      _metric_kwds,
      init="spectral",
  ):
      """Initialize embedding using graph. This is for direct embeddings.
  
      Parameters
      ----------
      init : str, optional
          Type of initialization to use. Either random, or spectral, by default "spectral"
  
      Returns
      -------
      embedding : np.array
          the initialized embedding
      """
      if random_state is None:
          random_state = check_random_state(None)
  
      if isinstance(init, str) and init == "random":
          embedding = random_state.uniform(
              low=-10.0, high=10.0, size=(graph.shape[0], n_components)
          ).astype(np.float32)
      elif isinstance(init, str) and init == "spectral":
          # We add a little noise to avoid local minima for optimization to come
  
          initialisation = spectral_layout(
              _raw_data,
              graph,
              n_components,
              random_state,
              metric=metric,
              metric_kwds=_metric_kwds,
          )
          expansion = 10.0 / np.abs(initialisation).max()
          embedding = (initialisation * expansion).astype(
              np.float32
          ) + random_state.normal(
              scale=0.0001, size=[graph.shape[0], n_components]
          ).astype(
              np.float32
          )
  
      else:
          init_data = np.array(init)
          if len(init_data.shape) == 2:
              if (
                  np.unique(init_data, axis=0).shape[0]
                  < init_data.shape[0]
              ):
                  tree = KDTree(init_data)
                  dist, ind = tree.query(init_data, k=2)
                  nndist = np.mean(dist[:, 1])
                  embedding = init_data + random_state.normal(
                      scale=0.001 * nndist, size=init_data.shape
                  ).astype(np.float32)
              else:
                  embedding = init_data
  
      return embedding
  
imports: import numpy
  from umap import UMAP
  from warnings import warn, catch_warnings, filterwarnings
  from numba import TypingError
  import os
  from umap.spectral import spectral_layout
  from sklearn.utils import check_random_state
  import codecs, pickle
  from sklearn.neighbors import KDTree
  import sys
label_desc: Use image node_id 2 for calling a global function with example usage: init_embedding_from_graph(_raw_data, graph, n_components, random_state, metric, _metric_kwds, init) and returns: embedding