sispca.hcv_vi
Classes
Custom data class for supervision from an AnnData object. |
|
Add HSIC loss to the latent representation in the VAE model. |
|
Training a HSIC-regulated VAE model with scvi-tools. |
Module Contents
- class sispca.hcv_vi.SupervisionAnnData(target_key, field_type, target_type, target_n_dim=1)
Custom data class for supervision from an AnnData object.
- Parameters:
target_key (str) – key name of the target variable.
field_type (str) – field type of the AnnData object where the target variable is stored.
target_type (str) – ‘continuous’ or ‘categorical’. The type of the target variable.
target_n_dim (int) – The number of dimensions of the target variable. - If target_type == ‘categorical’, number of labels to predict. - If target_type == ‘continuous’, number of output dimensions in a regression model.
- target_key
- field_type
- target_type
- target_n_dim = 1
- _sanity_check()
- class sispca.hcv_vi.HCV(n_input: int, n_layers: int = 1, dropout_rate: float = 0.1, n_hidden: int = 128, gene_likelihood: Literal['zinb', 'nb', 'poisson', 'normal'] = 'normal', hsic_scale: float = 1.0, n_latent_sub=[10, 10], predict_target_from_latent_sub: bool = False, target_supervision_list: list[SupervisionAnnData] | None = None, **model_kwargs)
Bases:
scvi.module.VAEAdd HSIC loss to the latent representation in the VAE model.
- Parameters:
hsic_scale (float) – Scalar multiplier of the HSIC penalty.
n_latent_sub (list of int) – Number of latent dimensions for each subspace.
predict_target_from_latent_sub (bool) – Whether to predict target variables from the latent space.
target_supervision_list (list of SupervisionAnnData) – List of SupervisionAnnData objects if predict_target_from_latent_sub is True.
- gene_likelihood = 'normal'
- hsic_scale = 1.0
- n_latent_sub = [10, 10]
- n_subspace
- predict_target_from_latent_sub = False
- target_supervision_list = None
- predict(x, use_posterior_mean=False)
Forward passing through the encoder and run prediction.
- Parameters:
x (tensor) – input tensor
use_posterior_mean (bool) – whether to use the posterior mean of the latent distribution for prediction
- prediction_loss(labelled_dataset: dict[str, torch.Tensor])
Calculate the mean squared error loss for the QC signal prediction.
- generative(z, library, batch_index, cont_covs=None, cat_covs=None, size_factor=None, y=None, transform_batch=None)
Run the generative process.
- class sispca.hcv_vi.HCVI(adata: anndata.AnnData, n_hidden: int = 128, n_layers: int = 1, dropout_rate: float = 0.1, gene_likelihood: Literal['zinb', 'nb', 'poisson', 'normal'] = 'normal', hsic_scale: float = 1.0, n_latent_sub=[10, 10], predict_target_from_latent_sub: bool = False, target_supervision_list: list[SupervisionAnnData] | None = None, **model_kwargs)
Bases:
scvi.model.SCVITraining a HSIC-regulated VAE model with scvi-tools.
- Parameters:
hsic_scale (float) – Scalar multiplier of the HSIC penalty.
n_latent_sub (list of int) – Number of latent dimensions for each subspace.
predict_target_from_latent_sub (bool) – Whether to predict target variables from the latent space.
target_supervision_list (list of SupervisionAnnData) – List of SupervisionAnnData objects if predict_target_from_latent_sub is True.
- _module_cls
- predict_target_from_latent_sub = False
- n_latent_sub = [10, 10]
- n_subspace
- target_key_and_type = None
- n_target
- module
- unsupervised_history_ = None
- semisupervised_history_ = None
- _model_summary_string = Multiline-String
Show Value
"""HCVI model with the following parameters: ------------------------------------------ *(architecture): n_layers = 1, dropout_rate = 0.1, gene_likelihood = normal *(subspace) n_subspace = Uninferable, n_latent_sub = List.list(ctx=<Context.Load: 1>, elts=[ <Const.int l.353 at 0x7045541400a0>, <Const.int l.353 at 0x7045541400d0>]), hsic_scale = 1.0 *(supervision) predict_target = False, n_target = Uninferable"""
- init_params_
- was_pretrained = False
- train(max_epochs: int | None = None, n_samples_per_label: float | None = None, check_val_every_n_epoch: int | None = None, train_size: float = 0.9, validation_size: float | None = None, shuffle_set_split: bool = True, batch_size: int = 128, accelerator: str = 'auto', devices: int | list[int] | str = 'auto', datasplitter_kwargs: dict | None = None, plan_kwargs: dict | None = None, **trainer_kwargs)
Trains the model using SCVI.
- classmethod setup_anndata(adata: anndata.AnnData, layer: str | None = None, target_supervision_list: list[SupervisionAnnData] | None = None, batch_key: str | None = None, labels_key: str | None = None, size_factor_key: str | None = None, categorical_covariate_keys: list[str] | None = None, continuous_covariate_keys: list[str] | None = None, **kwargs)
%(summary)s.
- Parameters:
%(param_adata)s
%(param_layer)s
%(param_batch_key)s
%(param_labels_key)s
%(param_size_factor_key)s
%(param_cat_cov_keys)s
%(param_cont_cov_keys)s