smoother.models.reduction._spvae

Classes

SPVAE

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

SpatialVAE

Spatially-aware Variational Autoencoder model.

Module Contents

class smoother.models.reduction._spvae.SPVAE(n_input: int, 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', 'normal'] = 'nb', latent_distribution: Literal['normal', 'ln'] = 'normal', **model_kwargs)

Bases: scvi.module.VAE

Add spatial loss to the latent representation in the VAE 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_outputs, kl_weight: float = 1.0)

Compute the loss.

classmethod from_vae(vae_module: scvi.module.VAE, spatial_loss: smoother.SpatialLoss | None = None, lambda_spatial_loss=0.1, sp_loss_as_kl: bool = False)

Alternate constructor to create a SPVAE model from a pretrained VAE model.

class smoother.models.reduction._spvae.SpatialVAE(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.0, dispersion: Literal['gene', 'gene-batch', 'gene-label', 'gene-cell'] = 'gene', gene_likelihood: Literal['zinb', 'nb', 'poisson', 'normal'] = 'nb', latent_distribution: Literal['normal', 'ln'] = 'normal', **model_kwargs)

Bases: scvi.model.SCVI

Spatially-aware Variational Autoencoder model.

_data_splitter_cls
_module_cls
module
_model_summary_string
init_params_
dr_logs
train(max_epochs: int = 400, lr: float = 0.01, accelerator: str = 'auto', devices: int | List[int] | str = 'auto', plan_kwargs: dict | None = None, **kwargs)

Trains the model without mini-batch.

classmethod from_rna_model(st_adata: anndata.AnnData, sc_model: scvi.model.SCVI, 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, **spvae_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 SCVI model