smoother.models.reduction._spanvi

Attributes

logger

Classes

SPANVAE

Add spatial loss to the latent representation in the SCANVAE model.

SpatialANVI

Spatially-aware ANnotation Variational Inference model.

Module Contents

smoother.models.reduction._spanvi.logger
class smoother.models.reduction._spanvi.SPANVAE(n_input: int, spatial_loss: smoother.SpatialLoss | None = 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: scvi.module.SCANVAE

Add spatial loss to the latent representation in the SCANVAE model.

Parameters:
  • spatial_loss – Spatial loss to apply on the latent representation. If None, no spatial loss.

  • lambda_spatial_loss – Weight of the spatial loss.

  • 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.

spatial_loss = None
l_sp_loss = 0.1
sp_loss_as_kl = False
diag_sp_inv_cov = None
loss(tensors, inference_outputs, generative_ouputs, kl_weight=1, labelled_tensors=None, classification_ratio=None)

Compute the loss.

classmethod from_vae(vae_module: scvi.module.SCANVAE, spatial_loss: smoother.SpatialLoss | None = None, lambda_spatial_loss=0.1, sp_loss_as_kl: bool = False)
class smoother.models.reduction._spanvi.SpatialANVI(st_adata: anndata.AnnData, spatial_loss: smoother.SpatialLoss | None = 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: lightning.LightningDataModule | None = None, **model_kwargs)

Bases: scvi.model.SCANVI

Spatially-aware ANnotation Variational Inference model.

_data_splitter_cls
_module_cls
_training_plan_cls
_train_runner_cls
module
_model_summary_string
init_params_
dr_logs
train(max_epochs: int | None = None, accelerator: str = 'auto', devices: int | List[int] | str = 'auto', plan_kwargs: dict | None = None, **trainer_kwargs)

Unsupervised training of the spatial model without minibatches.

classmethod from_rna_model(st_adata: anndata.AnnData, sc_model: scvi.model.SCANVI, spatial_loss: smoother.SpatialLoss | None = 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)

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.

Parameters:
  • st_adata – registed anndata object

  • sc_model – pretrained SCANVI model