SpaMetric.metric_learning_minibatch#

SpaMetric.metric_learning_minibatch(adata, beta=0.01, tol_err=1e-05, n_iters=1000, n_epochs=2, use_highly_variable=None, random_state=0, device=None, key_added=None, copy=False)[source]#

Mini-batch metric learning for large-scale spatial transcriptomics.

Parameters:
adata : AnnData

Annotated data matrix.

beta : float (default: 0.01)

Parameter to balance the main equation and the constraints.

tol_err : float (default: 1e-05)

Relative error tolerance (convergence criteria).

n_iters : int (default: 1000)

Number of iterations for the optimization.

n_epochs : int (default: 2)

How many times to traverse all samples.

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.

random_state : int (default: 0)

Change to use different initial states for the optimization.

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

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

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

If not specified, the metric learning data is stored in adata.uns[‘metric’] and the metric matrix is stored in adata.obsm[‘metric’]. If specified, the metric learning data is added to adata.uns[key_added] and the metric matrix is stored in adata.obsm[key_added+’_metric’].

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 the metric matrix.

metricndarray (.obsm)

The sample-by-reference metric matrix.