class_docstr: Compute affinities using nearest neighbors and uniform kernel in
  the ambient space.
  
  Parameters
  ----------
  data: np.ndarray
      The data matrix.
  
  k_neighbors: int
  
  method: str
      Specifies the nearest neighbor method to use. Can be ``exact``, ``annoy``,
      ``pynndescent``, ``hnsw``, ``approx``, or ``auto`` (default). ``approx``
      uses Annoy if the input data matrix is not a sparse object and if Annoy
      supports the given metric. Otherwise, it uses Pynndescent. ``auto`` uses
      exact nearest neighbors for N<1000 and the same heuristic as ``approx``
      for N>=1000.
  
  metric: Union[str, Callable]
      The metric to be used to compute affinities between points in the
      original space.
  
  metric_params: dict
      Additional keyword arguments for the metric function.
  
  symmetrize: Union[str, bool]
      Symmetrize the affinity matrix. During standard t-SNE optimization, the
      affinities are symmetrized. However, when embedding new data points into
      existing embeddings, symmetrization is not performed.
      The uniform affinity supports ``max`` and ``mean`` symmetrization, as
      well as no symmetrization via ``none``.
      The ``max`` symmetrization yields a binary affinity matrix with all
      non-zero elements (corresponding to edges of the kNN graph) being the
      same. The ``mean`` symmetrization performs symmetrization via
      (A + A.T) / 2, resulting in the affinity matrix with two possible
      non-zero values. Applying no symmetrization results in a non-symmetric
      affinity matrix. We default to ``mean`` symmetrization, but the default
      will change to ``max`` in future versions.
  
  n_jobs: int
      The number of threads to use while running t-SNE. This follows the
      scikit-learn convention, ``-1`` meaning all processors, ``-2`` meaning
      all but one, etc.
  
  random_state: Union[int, RandomState]
      If the value is an int, random_state is the seed used by the random
      number generator. If the value is a RandomState instance, then it will
      be used as the random number generator. If the value is None, the random
      number generator is the RandomState instance used by `np.random`.
  
  verbose: bool
  
  knn_index: Optional[nearest_neighbors.KNNIndex]
      Optionally, a precomptued ``openTSNE.nearest_neighbors.KNNIndex`` object
      can be specified. This option will ignore any KNN-related parameters.
      When ``knn_index`` is specified, ``data`` must be set to None.
class_docstr_tok: ["Compute","affinities","using","nearest","neighbors","and","uniform","kernel","in","the","ambient","space",".","Parameters","--","--","--","--","--","data",":","np.ndarray","The","data","matrix",".","k_neighbors",":","int","method",":","str","Specifies","the","nearest","neighbor","method","to","use",".","Can","be","``","exact","``",",","``","annoy","``",",","``","pynndescent","``",",","``","hnsw","``",",","``","approx","``",",","or","``","auto","``","(","default",")",".","``","approx","``","uses","Annoy","if","the","input","data","matrix","is","not","a","sparse","object","and","if","Annoy","supports","the","given","metric",".","Otherwise",",","it","uses","Pynndescent",".","``","auto","``","uses","exact","nearest","neighbors","for","N","<","1000","and","the","same","heuristic","as","``","approx","``","for","N",">","=1000",".","metric",":","Union","[","str",",","Callable","]","The","metric","to","be","used","to","compute","affinities","between","points","in","the","original","space",".","metric_params",":","dict","Additional","keyword","arguments","for","the","metric","function",".","symmetrize",":","Union","[","str",",","bool","]","Symmetrize","the","affinity","matrix",".","During","standard","t-SNE","optimization",",","the","affinities","are","symmetrized",".","However",",","when","embedding","new","data","points","into","existing","embeddings",",","symmetrization","is","not","performed",".","The","uniform","affinity","supports","``","max","``","and","``","mean","``","symmetrization",",","as","well","as","no","symmetrization","via","``","none","``",".","The","``","max","``","symmetrization","yields","a","binary","affinity","matrix","with","all","non-zero","elements","(","corresponding","to","edges","of","the","kNN","graph",")","being","the","same",".","The","``","mean","``","symmetrization","performs","symmetrization","via","(","A","+","A.T",")","\/","2",",","resulting","in","the","affinity","matrix","with","two","possible","non-zero","values",".","Applying","no","symmetrization","results","in","a","non-symmetric","affinity","matrix",".","We","default","to","``","mean","``","symmetrization",",","but","the","default","will","change","to","``","max","``","in","future","versions",".","n_jobs",":","int","The","number","of","threads","to","use","while","running","t-SNE",".","This","follows","the","scikit-learn","convention",",","``","-1","``","meaning","all","processors",",","``","-2","``","meaning","all","but","one",",","etc",".","random_state",":","Union","[","int",",","RandomState","]","If","the","value","is","an","int",",","random_state","is","the","seed","used","by","the","random","number","generator",".","If","the","value","is","a","RandomState","instance",",","then","it","will","be","used","as","the","random","number","generator",".","If","the","value","is","None",",","the","random","number","generator","is","the","RandomState","instance","used","by","`","np.random","`",".","verbose",":","bool","knn_index",":","Optional","[","nearest_neighbors.KNNIndex","]","Optionally",",","a","precomptued","``","openTSNE.nearest_neighbors.KNNIndex","``","object","can","be","specified",".","This","option","will","ignore","any","KNN-related","parameters",".","When","``","knn_index","``","is","specified",",","``","data","``","must","be","set","to","None","."]
docstr: Compute the affinities of new samples to the initial samples.
  
  This is necessary for embedding new data points into an existing
  embedding.
  
  Parameters
  ----------
  data: np.ndarray
      The data points to be added to the existing embedding.
  
  k_neighbors: int
      The number of nearest neighbors to consider.
  
  return_distances: bool
      If needed, the function can return the indices of the nearest
      neighbors and their corresponding distances.
  
  Returns
  -------
  P: array_like
      An :math:`N \times M` affinity matrix expressing interactions
      between :math:`N` new data points the initial :math:`M` data
      samples.
  
  indices: np.ndarray
      Returned if ``return_distances=True``. The indices of the :math:`k`
      nearest neighbors in the existing embedding for every new data
      point.
  
  distances: np.ndarray
      Returned if ``return_distances=True``. The distances to the
      :math:`k` nearest neighbors in the existing embedding for every new
      data point.
docstr_tok: ["Compute","the","affinities","of","new","samples","to","the","initial","samples",".","This","is","necessary","for","embedding","new","data","points","into","an","existing","embedding",".","Parameters","--","--","--","--","--","data",":","np.ndarray","The","data","points","to","be","added","to","the","existing","embedding",".","k_neighbors",":","int","The","number","of","nearest","neighbors","to","consider",".","return_distances",":","bool","If","needed",",","the","function","can","return","the","indices","of","the","nearest","neighbors","and","their","corresponding","distances",".","Returns","--","--","--","-","P",":","array_like","An",":","math",":","`","N","\\times","M","`","affinity","matrix","expressing","interactions","between",":","math",":","`","N","`","new","data","points","the","initial",":","math",":","`","M","`","data","samples",".","indices",":","np.ndarray","Returned","if","``","return_distances=True","``",".","The","indices","of","the",":","math",":","`","k","`","nearest","neighbors","in","the","existing","embedding","for","every","new","data","point",".","distances",":","np.ndarray","Returned","if","``","return_distances=True","``",".","The","distances","to","the",":","math",":","`","k","`","nearest","neighbors","in","the","existing","embedding","for","every","new","data","point","."]
code: def to_new(self, data, k_neighbors=None, return_distances=False):
      """Compute the affinities of new samples to the initial samples.
  
      This is necessary for embedding new data points into an existing
      embedding.
  
      Parameters
      ----------
      data: np.ndarray
          The data points to be added to the existing embedding.
  
      k_neighbors: int
          The number of nearest neighbors to consider.
  
      return_distances: bool
          If needed, the function can return the indices of the nearest
          neighbors and their corresponding distances.
  
      Returns
      -------
      P: array_like
          An :math:`N \\times M` affinity matrix expressing interactions
          between :math:`N` new data points the initial :math:`M` data
          samples.
  
      indices: np.ndarray
          Returned if ``return_distances=True``. The indices of the :math:`k`
          nearest neighbors in the existing embedding for every new data
          point.
  
      distances: np.ndarray
          Returned if ``return_distances=True``. The distances to the
          :math:`k` nearest neighbors in the existing embedding for every new
          data point.
  
      """
      n_samples = data.shape[0]
      n_reference_samples = self.n_samples
  
      if k_neighbors is None:
          k_neighbors = self.knn_index.k
      elif k_neighbors >= n_reference_samples:
          raise ValueError(
              "`k` (%d) cannot be larger than the number of reference "
              "samples (%d)." % (k_neighbors, self.n_samples)
          )
  
      # Find nearest neighbors and the distances to the new points
      neighbors, distances = self.knn_index.query(data, k_neighbors)
  
      values = np.ones_like(distances)
      values /= np.sum(values, axis=1)[:, np.newaxis]
  
      P = sp.csr_matrix(
          (
              values.ravel(),
              neighbors.ravel(),
              range(0, n_samples * k_neighbors + 1, k_neighbors),
          ),
          shape=(n_samples, n_reference_samples),
      )
  
      if return_distances:
          return P, neighbors, distances
  
      return P
  
imports: import logging
  import numbers
  import operator
  from functools import reduce
  import numpy
  import scipy.sparse
  from openTSNE import _tsne
  from openTSNE import nearest_neighbors
  from openTSNE import utils
  from openTSNE.utils import is_package_installed
  import warnings
label_desc: Use image node_id 2 for calling the Uniform obj's underlying member method code with example usage: obj.to_new(data, k_neighbors, return_distances) and returns: P, P,  neighbors,  distances