code: def optimize_layout_generic(
      head_embedding,
      tail_embedding,
      head,
      tail,
      n_epochs,
      n_vertices,
      epochs_per_sample,
      a,
      b,
      rng_state,
      gamma=1.0,
      initial_alpha=1.0,
      negative_sample_rate=5.0,
      output_metric=dist.euclidean,
      output_metric_kwds=(),
      verbose=False,
      tqdm_kwds=None,
      move_other=False,
  ):
      """Improve an embedding using stochastic gradient descent to minimize the
      fuzzy set cross entropy between the 1-skeletons of the high dimensional
      and low dimensional fuzzy simplicial sets. In practice this is done by
      sampling edges based on their membership strength (with the (1-p) terms
      coming from negative sampling similar to word2vec).
  
      Parameters
      ----------
      head_embedding: array of shape (n_samples, n_components)
          The initial embedding to be improved by SGD.
  
      tail_embedding: array of shape (source_samples, n_components)
          The reference embedding of embedded points. If not embedding new
          previously unseen points with respect to an existing embedding this
          is simply the head_embedding (again); otherwise it provides the
          existing embedding to embed with respect to.
  
      head: array of shape (n_1_simplices)
          The indices of the heads of 1-simplices with non-zero membership.
  
      tail: array of shape (n_1_simplices)
          The indices of the tails of 1-simplices with non-zero membership.
  
      n_epochs: int
          The number of training epochs to use in optimization.
  
      n_vertices: int
          The number of vertices (0-simplices) in the dataset.
  
      epochs_per_sample: array of shape (n_1_simplices)
          A float value of the number of epochs per 1-simplex. 1-simplices with
          weaker membership strength will have more epochs between being sampled.
  
      a: float
          Parameter of differentiable approximation of right adjoint functor
  
      b: float
          Parameter of differentiable approximation of right adjoint functor
  
      rng_state: array of int64, shape (3,)
          The internal state of the rng
  
      gamma: float (optional, default 1.0)
          Weight to apply to negative samples.
  
      initial_alpha: float (optional, default 1.0)
          Initial learning rate for the SGD.
  
      negative_sample_rate: int (optional, default 5)
          Number of negative samples to use per positive sample.
  
      verbose: bool (optional, default False)
          Whether to report information on the current progress of the algorithm.
  
      tqdm_kwds: dict (optional, default None)
          Keyword arguments for tqdm progress bar.
  
      move_other: bool (optional, default False)
          Whether to adjust tail_embedding alongside head_embedding
  
      Returns
      -------
      embedding: array of shape (n_samples, n_components)
          The optimized embedding.
      """
  
      dim = head_embedding.shape[1]
      alpha = initial_alpha
  
      epochs_per_negative_sample = (
          epochs_per_sample / negative_sample_rate
      )
      epoch_of_next_negative_sample = epochs_per_negative_sample.copy()
      epoch_of_next_sample = epochs_per_sample.copy()
  
      optimize_fn = numba.njit(
          _optimize_layout_generic_single_epoch,
          fastmath=True,
      )
  
      if tqdm_kwds is None:
          tqdm_kwds = {}
  
      if "disable" not in tqdm_kwds:
          tqdm_kwds["disable"] = not verbose
  
      for n in tqdm(range(n_epochs), **tqdm_kwds):
          optimize_fn(
              epochs_per_sample,
              epoch_of_next_sample,
              head,
              tail,
              head_embedding,
              tail_embedding,
              output_metric,
              output_metric_kwds,
              dim,
              alpha,
              move_other,
              n,
              epoch_of_next_negative_sample,
              epochs_per_negative_sample,
              rng_state,
              n_vertices,
              a,
              b,
              gamma,
          )
          alpha = initial_alpha * (1.0 - (float(n) / float(n_epochs)))
  
      return head_embedding
  
file_path: umap/umap/layouts.py
imports: import numpy
  import numba
  import umap.distances
  from umap.utils import tau_rand_int
  from tqdm.auto import tqdm
label_desc: Use image node_id 7 for calling a global function with example usage: optimize_layout_generic(head_embedding, tail_embedding, head, tail, n_epochs, n_vertices, epochs_per_sample, a, b, rng_state, gamma, initial_alpha, negative_sample_rate, output_metric, output_metric_kwds, verbose, tqdm_kwds, move_other) and returns: head_embedding