smoother.models.reduction._sppca ================================ .. py:module:: smoother.models.reduction._sppca Classes ------- .. autoapisummary:: smoother.models.reduction._sppca.SpatialPCA Module Contents --------------- .. py:class:: SpatialPCA(adata: anndata.AnnData, layer: Optional[str] = None, n_latent: int = 10, spatial_loss: Optional[smoother.SpatialLoss] = None, lambda_spatial_loss=0.1) Bases: :py:obj:`torch.nn.Module` Solving PCA using stochastic gradient descent. .. py:attribute:: n_latent :value: 10 .. py:attribute:: n_feature .. py:attribute:: _data :value: None .. py:attribute:: spatial_loss :value: None .. py:attribute:: l_sp_loss :value: 0.1 .. py:attribute:: U .. py:attribute:: dr_configs .. py:attribute:: dr_logs .. py:method:: load_adata(adata: anndata.AnnData, layer: Optional[str] = None) Load data to project. :param adata: data to project. :type adata: AnnData :param layer: layer to project. If None, use adata.X. :type layer: str .. py:method:: _gram_schmidt(U) Project the PC basis matrix to the feasible space. :param U: PC basis matrix, num_feature x num_pc. :type U: 2D tensor .. py:method:: forward(x) Project x to the lower PC space. :param x: data to project, num_feature x num_sample. :type x: 2D tensor .. py:method:: _init_with_svd(x) Initialize model with svd solution. :param x: data to project, num_feature x num_sample. :type x: 2D tensor .. py:method:: get_latent_representation() Project loaded data to the lower PC space and return the latent representation. .. py:method:: 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. :param lr: The learning rate. :type lr: float :param max_epochs: The maximum number of epochs. :type max_epochs: int :param patience: The patience for early stopping. :type patience: int :param tol: The tolerated convergence error. :type tol: float :param init_with_svd: Whether to initialize with analytical solution calculated using `torch.svd_lowrank()`. :type init_with_svd: bool :param verbose: If True, print out loss while training. :type verbose: bool :param quite: If True, no output printed. :type quite: bool :param clear_logs: If True, clear logs before training. :type clear_logs: bool .. py:method:: from_rna_model(rna_model, st_adata: anndata.AnnData, layer: Optional[str] = None, spatial_loss: Optional[smoother.SpatialLoss] = None, lambda_spatial_loss=0.1) :classmethod: Initialize a spatial model from a pre-trained RNA model. .. py:method:: from_scanpy(adata: anndata.AnnData, layer: Optional[str] = None, spatial_loss: Optional[smoother.SpatialLoss] = None, lambda_spatial_loss=0.1) :classmethod: Initialize a spatial model from a pre-trained RNA model.