code: def multi_component_layout(
      data,
      graph,
      n_components,
      component_labels,
      dim,
      random_state,
      metric="euclidean",
      metric_kwds={},
      init="random",
      tol=0.0,
      maxiter=0,
  ):
      """Specialised layout algorithm for dealing with graphs with many connected components.
      This will first find relative positions for the components by spectrally embedding
      their centroids, then spectrally embed each individual connected component positioning
      them according to the centroid embeddings. This provides a decent embedding of each
      component while placing the components in good relative positions to one another.
  
      Parameters
      ----------
      data: array of shape (n_samples, n_features)
          The source data -- required so we can generate centroids for each
          connected component of the graph.
  
      graph: sparse matrix
          The adjacency matrix of the graph to be embedded.
  
      n_components: int
          The number of distinct components to be layed out.
  
      component_labels: array of shape (n_samples)
          For each vertex in the graph the label of the component to
          which the vertex belongs.
  
      dim: int
          The chosen embedding dimension.
  
      metric: string or callable (optional, default 'euclidean')
          The metric used to measure distances among the source data points.
  
      metric_kwds: dict (optional, default {})
          Keyword arguments to be passed to the metric function.
  
      init: string, either "random" or "tsvd"
          Indicates to initialize the eigensolver. Use "random" (the default) to
          use uniformly distributed random initialization; use "tsvd" to warm-start the
          eigensolver with singular vectors of the Laplacian associated to the largest
          singular values. This latter option also forces usage of the LOBPCG eigensolver;
          with the former, ARPACK's solver ``eigsh`` will be used for smaller Laplacians.
  
      tol: float, default chosen by implementation
          Stopping tolerance for the numerical algorithm computing the embedding.
  
      maxiter: int, default chosen by implementation
          Number of iterations the numerical algorithm will go through at most as it
          attempts to compute the embedding.
  
      Returns
      -------
      embedding: array of shape (n_samples, dim)
          The initial embedding of ``graph``.
      """
  
      result = np.empty((graph.shape[0], dim), dtype=np.float32)
  
      if n_components > 2 * dim:
          meta_embedding = component_layout(
              data,
              n_components,
              component_labels,
              dim,
              random_state,
              metric=metric,
              metric_kwds=metric_kwds,
          )
      else:
          k = int(np.ceil(n_components / 2.0))
          base = np.hstack([np.eye(k), np.zeros((k, dim - k))])
          meta_embedding = np.vstack([base, -base])[:n_components]
  
      for label in range(n_components):
          component_graph = graph.tocsr()[
              component_labels == label, :
          ].tocsc()
          component_graph = component_graph[
              :, component_labels == label
          ].tocoo()
  
          distances = pairwise_distances(
              [meta_embedding[label]], meta_embedding
          )
          data_range = distances[distances > 0.0].min() / 2.0
  
          if (
              component_graph.shape[0] < 2 * dim
              or component_graph.shape[0] <= dim + 1
          ):
              result[component_labels == label] = (
                  random_state.uniform(
                      low=-data_range,
                      high=data_range,
                      size=(component_graph.shape[0], dim),
                  )
                  + meta_embedding[label]
              )
          else:
              component_embedding = _spectral_layout(
                  data=None,
                  graph=component_graph,
                  dim=dim,
                  random_state=random_state,
                  metric=metric,
                  metric_kwds=metric_kwds,
                  init=init,
                  tol=tol,
                  maxiter=maxiter,
              )
              expansion = data_range / np.max(
                  np.abs(component_embedding)
              )
              component_embedding *= expansion
              result[component_labels == label] = (
                  component_embedding + meta_embedding[label]
              )
  
      return result
  
file_path: umap/umap/spectral.py
imports: import warnings
  from warnings import warn
  import numpy
  import scipy.sparse
  import scipy.sparse.csgraph
  from sklearn.decomposition import TruncatedSVD
  from sklearn.manifold import SpectralEmbedding
  from sklearn.metrics import pairwise_distances
  from sklearn.metrics.pairwise import _VALID_METRICS
  from umap.distances import pairwise_special_metric, SPECIAL_METRICS
  from umap.sparse import SPARSE_SPECIAL_METRICS, sparse_named_distances
label_desc: Use image node_id 2 for calling a global function with example usage: multi_component_layout(data, graph, n_components, component_labels, dim, random_state, metric, metric_kwds, init, tol, maxiter) and returns: result