smoother.models.reduction._sppca

Classes

SpatialPCA

Solving PCA using stochastic gradient descent.

Module Contents

class smoother.models.reduction._sppca.SpatialPCA(adata: anndata.AnnData, layer: str | None = None, n_latent: int = 10, spatial_loss: smoother.SpatialLoss | None = None, lambda_spatial_loss=0.1)

Bases: torch.nn.Module

Solving PCA using stochastic gradient descent.

n_latent = 10
n_feature
_data = None
spatial_loss = None
l_sp_loss = 0.1
U
dr_configs
dr_logs
load_adata(adata: anndata.AnnData, layer: str | None = None)

Load data to project.

Parameters:
  • adata (AnnData) – data to project.

  • layer (str) – layer to project. If None, use adata.X.

_gram_schmidt(U)

Project the PC basis matrix to the feasible space.

Parameters:

U (2D tensor) – PC basis matrix, num_feature x num_pc.

forward(x)

Project x to the lower PC space.

Parameters:

x (2D tensor) – data to project, num_feature x num_sample.

_init_with_svd(x)

Initialize model with svd solution.

Parameters:

x (2D tensor) – data to project, num_feature x num_sample.

get_latent_representation()

Project loaded data to the lower PC space and return the latent representation.

reduce(lr=1.0, max_epochs=1000, patience=10, tol=1e-05, init_with_svd=False, verbose=True, quite=False, clear_logs=True)

Reduce the dimension of the expression matrix.

Parameters:
  • lr (float) – The learning rate.

  • max_epochs (int) – The maximum number of epochs.

  • patience (int) – The patience for early stopping.

  • tol (float) – The tolerated convergence error.

  • init_with_svd (bool) – Whether to initialize with analytical solution calculated using torch.svd_lowrank().

  • verbose (bool) – If True, print out loss while training.

  • quite (bool) – If True, no output printed.

  • clear_logs (bool) – If True, clear logs before training.

classmethod from_rna_model(rna_model, st_adata: anndata.AnnData, layer: str | None = None, spatial_loss: smoother.SpatialLoss | None = None, lambda_spatial_loss=0.1)

Initialize a spatial model from a pre-trained RNA model.

classmethod from_scanpy(adata: anndata.AnnData, layer: str | None = None, spatial_loss: smoother.SpatialLoss | None = None, lambda_spatial_loss=0.1)

Initialize a spatial model from a pre-trained RNA model.