smoother.models.reduction._spanvi ================================= .. py:module:: smoother.models.reduction._spanvi Attributes ---------- .. autoapisummary:: smoother.models.reduction._spanvi.logger Classes ------- .. autoapisummary:: smoother.models.reduction._spanvi.SPANVAE smoother.models.reduction._spanvi.SpatialANVI Module Contents --------------- .. py:data:: logger .. py:class:: SPANVAE(n_input: int, spatial_loss: Optional[smoother.SpatialLoss] = None, lambda_spatial_loss=0.1, sp_loss_as_kl: bool = False, n_batch: int = 0, n_labels: int = 0, n_hidden: int = 128, n_latent: int = 10, n_layers: int = 1, n_continuous_cov: int = 0, n_cats_per_cov: Iterable[int] | None = None, dropout_rate: float = 0.1, dispersion: Literal['gene', 'gene-batch', 'gene-label', 'gene-cell'] = 'gene', log_variational: bool = True, gene_likelihood: Literal['zinb', 'nb'] = 'zinb', use_observed_lib_size: bool = True, y_prior: torch.Tensor | None = None, labels_groups: Sequence[int] = None, use_labels_groups: bool = False, linear_classifier: bool = False, classifier_parameters: dict | None = None, use_batch_norm: Literal['encoder', 'decoder', 'none', 'both'] = 'both', use_layer_norm: Literal['encoder', 'decoder', 'none', 'both'] = 'none', **vae_kwargs) Bases: :py:obj:`scvi.module.SCANVAE` Add spatial loss to the latent representation in the SCANVAE model. :param spatial_loss: Spatial loss to apply on the latent representation. If None, no spatial loss. :param lambda_spatial_loss: Weight of the spatial loss. :param sp_loss_as_kl: Whether to treat the spatial loss as a KL divergence term. If True, the spatial loss will replace the original KL divergence term in the loss function. If False, the spatial loss will be added to the original loss function. .. py:attribute:: spatial_loss :value: None .. py:attribute:: l_sp_loss :value: 0.1 .. py:attribute:: sp_loss_as_kl :value: False .. py:attribute:: diag_sp_inv_cov :value: None .. py:method:: loss(tensors, inference_outputs, generative_ouputs, kl_weight=1, labelled_tensors=None, classification_ratio=None) Compute the loss. .. py:method:: from_vae(vae_module: scvi.module.SCANVAE, spatial_loss: Optional[smoother.SpatialLoss] = None, lambda_spatial_loss=0.1, sp_loss_as_kl: bool = False) :classmethod: .. py:class:: SpatialANVI(st_adata: anndata.AnnData, spatial_loss: Optional[smoother.SpatialLoss] = None, lambda_spatial_loss=0.1, sp_loss_as_kl: bool = False, n_hidden: int = 128, n_latent: int = 10, n_layers: int = 1, dropout_rate: float = 0.1, dispersion: Literal['gene', 'gene-batch', 'gene-label', 'gene-cell'] = 'gene', gene_likelihood: Literal['zinb', 'nb', 'poisson'] = 'nb', latent_distribution: Literal['normal', 'ln'] = 'normal', use_observed_lib_size: bool = True, linear_classifier: bool = False, datamodule: Optional[lightning.LightningDataModule] = None, **model_kwargs) Bases: :py:obj:`scvi.model.SCANVI` Spatially-aware ANnotation Variational Inference model. .. py:attribute:: _data_splitter_cls .. py:attribute:: _module_cls .. py:attribute:: _training_plan_cls .. py:attribute:: _train_runner_cls .. py:attribute:: module .. py:attribute:: _model_summary_string .. py:attribute:: init_params_ .. py:attribute:: dr_logs .. py:method:: train(max_epochs: Optional[int] = None, accelerator: str = 'auto', devices: Union[int, List[int], str] = 'auto', plan_kwargs: Optional[dict] = None, **trainer_kwargs) Unsupervised training of the spatial model without minibatches. .. py:method:: from_rna_model(st_adata: anndata.AnnData, sc_model: scvi.model.SCANVI, spatial_loss: Optional[smoother.SpatialLoss] = None, lambda_spatial_loss=0.1, sp_loss_as_kl: bool = False, unfrozen: bool = False, freeze_dropout: bool = False, freeze_expression: bool = True, freeze_decoder_first_layer: bool = True, freeze_batchnorm_encoder: bool = True, freeze_batchnorm_decoder: bool = False, freeze_classifier: bool = True, **spanvae_kwargs) :classmethod: Alternate constructor for exploiting a pre-trained model on RNA-seq data. Note that because of the dropout layer, even though the new instance is initialized with the same parameters as the pre-trained model, new_instance.get_latent_representation() may not return the same latent representation as the pre-trained model. :param st_adata: registed anndata object :param sc_model: pretrained SCANVI model