FACSPy.tl._compute_tsne

Contents

FACSPy.tl._compute_tsne#

FACSPy.tl._compute_tsne(adata, uns_key=None, n_components=3, n_pcs=None, use_rep=None, perplexity=30, early_exaggeration=12, learning_rate='auto', random_state=187, use_fast_tsne=False, n_jobs=None, *, metric='euclidean')#

Internal function to compute the TSNE embedding. The core of the function is implemented from scanpy with the important difference that the TSNE coordinates are returned and not written to the adata object.

Parameters:
  • adata (AnnData) – The anndata object of shape n_obs x n_vars where rows correspond to cells and columns to the channels.

  • uns_key (Optional[str]) – Name of the slot in .obsm that the TSNE is calculated on.

  • n_components (int) – The number of dimensions of the embedding.

  • n_pcs (Optional[int]) – Number of principal components to use

  • use_rep (Optional[str]) – Name of the slot in .obsm that specifies the embedding that TSNE is calculated on. Used in conjunction with uns_key.

  • perplexity (Union[float, int]) – The perplexity is related to the number of nearest neighbors that is used in other manifold learning algorithms. Larger datasets usually require a larger perplexity. Consider selecting a value between 5 and 50. Different values can result in significantly different results. The perplexity must be less than the number of samples.

  • early_exaggeration (Union[float, int]) – Controls how tight natural clusters in the original space are in the embedded space and how much space will be between them. For larger values, the space between natural clusters will be larger in the embedded space. Again, the choice of this parameter is not very critical. If the cost function increases during initial optimization, the early exaggeration factor or the learning rate might be too high.

  • learning_rate (Union[float, int]) – Learning rate. The learning rate for t-SNE is usually in the range [10.0, 1000.0]. If the learning rate is too high, the data may look like a ‘ball’ with any point approximately equidistant from its nearest neighbours. If the learning rate is too low, most points may look compressed in a dense cloud with few outliers. If the cost function gets stuck in a bad local minimum increasing the learning rate may help.

  • random_state (int) – Sets the random state for the algorithm.

  • use_fast_tsne (bool) – Whether to use the fast_tsne implementation

  • n_jobs (Optional[int]) – number of CPU cores to use.

Return type:

tuple[ndarray, dict]

Returns:

  • X_tsne – The TSNE coordinates

  • params – A dictionary containing the parameters used for analysis.