class_docstr: Compute affinities using nearest neighbors and a fixed bandwidth
  for the Gaussians in the ambient space.
  
  Using a fixed Gaussian bandwidth can enable us to find smaller clusters of
  data points than we might be able to using the automatically determined
  bandwidths using perplexity. Note however that this requires mostly trial
  and error.
  
  Parameters
  ----------
  data: np.ndarray
      The data matrix.
  
  sigma: float
      The bandwidth to use for the Gaussian kernels in the ambient space.
  
  k: int
      The number of nearest neighbors to consider for each kernel.
  
  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: 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.
  
  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","a","fixed","bandwidth","for","the","Gaussians","in","the","ambient","space",".","Using","a","fixed","Gaussian","bandwidth","can","enable","us","to","find","smaller","clusters","of","data","points","than","we","might","be","able","to","using","the","automatically","determined","bandwidths","using","perplexity",".","Note","however","that","this","requires","mostly","trial","and","error",".","Parameters","--","--","--","--","--","data",":","np.ndarray","The","data","matrix",".","sigma",":","float","The","bandwidth","to","use","for","the","Gaussian","kernels","in","the","ambient","space",".","k",":","int","The","number","of","nearest","neighbors","to","consider","for","each","kernel",".","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",":","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",".","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: int
      The number of nearest neighbors to consider for each kernel.
  
  sigma: float
      The bandwidth to use for the Gaussian kernels in the ambient space.
  
  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",":","int","The","number","of","nearest","neighbors","to","consider","for","each","kernel",".","sigma",":","float","The","bandwidth","to","use","for","the","Gaussian","kernels","in","the","ambient","space",".","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=None, sigma=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: int
          The number of nearest neighbors to consider for each kernel.
  
      sigma: float
          The bandwidth to use for the Gaussian kernels in the ambient space.
  
      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 is None:
          k = self.knn_index.k
      elif k >= n_reference_samples:
          raise ValueError(
              "`k` (%d) cannot be larger than the number of reference "
              "samples (%d)." % (k, self.n_samples)
          )
  
      if sigma is None:
          sigma = self.sigma
  
      # Find nearest neighbors and the distances to the new points
      neighbors, distances = self.knn_index.query(data, k)
  
      with utils.Timer("Calculating affinity matrix...", self.verbose):
          # Compute asymmetric pairwise input similarities
          conditional_P = np.exp(-(distances**2) / (2 * sigma**2))
  
          # Convert weights to probabilities
          conditional_P /= np.sum(conditional_P, axis=1)[:, np.newaxis]
  
          P = sp.csr_matrix(
              (
                  conditional_P.ravel(),
                  neighbors.ravel(),
                  range(0, n_samples * k + 1, k),
              ),
              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 FixedSigmaNN obj's underlying member method code with example usage: obj.to_new(data, k, sigma, return_distances) and returns: P, P,  neighbors,  distances