SpaSRL.run_SRL#

SpaSRL.run_SRL(adata, n_neighbors=None, n_pcs=None, metric='euclidean', Lambda=0.1, n_iterations=500, n_discriminant=None, Z_mask=None, use_landmarks=None, use_highly_variable=None, device=None, random_state=0, key_added=None, copy=False)[source]#

Run self-representation learning [Wong17] [Shi21].

Parameters:
adata : AnnData

Annotated data matrix.

n_neighbors : int | NoneOptional[int] (default: None)

Number of neighbors for constructing a NearestNeighbors graph as hard constraints in self-representation learning. Defaults to the number of samples devided by 10 with a minimum number of 20.

n_pcs : int | NoneOptional[int] (default: None)

Number of principal components to use for constructing a NearestNeighbors graph as hard constraints in self-representation learning. Defaults to the number of features devided by 50 with a minimum number of 20.

metric : {‘cityblock’, ‘cosine’, ‘euclidean’, ‘l1’, ‘l2’, ‘manhattan’, ‘braycurtis’, ‘canberra’, ‘chebyshev’, ‘correlation’, ‘dice’, ‘hamming’, ‘jaccard’, ‘kulsinski’, ‘mahalanobis’, ‘minkowski’, ‘rogerstanimoto’, ‘russellrao’, ‘seuclidean’, ‘sokalmichener’, ‘sokalsneath’, ‘sqeuclidean’, ‘yule’} | (ndarray, ndarray) → floatUnion[Literal[‘cityblock’, ‘cosine’, ‘euclidean’, ‘l1’, ‘l2’, ‘manhattan’, ‘braycurtis’, ‘canberra’, ‘chebyshev’, ‘correlation’, ‘dice’, ‘hamming’, ‘jaccard’, ‘kulsinski’, ‘mahalanobis’, ‘minkowski’, ‘rogerstanimoto’, ‘russellrao’, ‘seuclidean’, ‘sokalmichener’, ‘sokalsneath’, ‘sqeuclidean’, ‘yule’], Callable[[ndarray, ndarray], float]] (default: 'euclidean')

Distance metric to use for constructing a NearestNeighbors graph as hard constraints in self-representation learning.

Lambda : float (default: 0.1)

Hyperparameter for sparsity regularization.

n_iterations : int (default: 500)

Number of iterations for the optimization.

n_discriminant : int | NoneOptional[int] (default: None)

Number of discriminant vectors to store for label transfer. By default stores all discriminant vectors.

Z_mask : ndarray | spmatrix | NoneUnion[ndarray, spmatrix, None] (default: None)

Customized sample-by-sample graph of shape (adata.n_obs, adata.n_obs) as hard constraints in self-representation learning. By default computes a NearestNeighbors graph.

use_landmarks : bool | NoneOptional[bool] (default: None)

Whether to use landmarks as hard constraints in self-representation learning, stored in adata.obs[‘is_landmarks’]. By default uses them if they have been selected beforehand.

use_highly_variable : bool | NoneOptional[bool] (default: None)

Whether to use highly variable genes only, stored in adata.var[‘highly_variable’]. By default uses them if they have been determined beforehand.

device : str | NoneOptional[str] (default: None)

The desired device for PyTorch computation. By default uses cuda if cuda is avaliable cpu otherwise.

random_state : int (default: 0)

Change to use different initial states for the optimization.

key_added : str | NoneOptional[str] (default: None)

If not specified, the self-representation learning data is stored in adata.uns[‘representation’], representation is stored in adata.obsp[‘representation’] and discriminant matrix is stored in adata.uns[‘representation’][‘discriminant’]. If specified, the self-representation learning data is added to adata.uns[key_added], representation is stored in adata.obsp[key_added+’_representation’] and discriminant matrix is stored in adata.uns[key_added][‘discriminant’].

copy : bool (default: False)

Return a copy instead of writing to adata.

Return type:

AnnData | NoneOptional[AnnData]

Returns:

Depending on copy, returns or updates adata with the following fields.

See key_added parameter description for the storage path of representation and discriminant.

representationcsr_matrix (.obsp)

The self-representation of samples.

discriminantndarray (.uns[key_added])

The discriminant vectors for label transfer.