multiHIVEvae API#

class multiHIVE.module._multiHIVEvae.multiHIVEvae(n_input_genes: int = 0, n_input_regions: int = 0, n_input_proteins: int = 0, n_batch: int = 0, n_labels: int = 0, n_hidden: int = 256, n_latent: int = 20, n_layers_encoder: int = 2, n_layers_decoder: int = 2, n_continuous_cov: int = 0, n_cats_per_cov: Iterable[int] | None = None, dropout_rate: float = 0.2, region_factors: bool = True, gene_likelihood: Literal['zinb', 'nb'] = 'nb', gene_dispersion: Literal['gene', 'gene-batch', 'gene-label'] = 'gene', use_batch_norm: Literal['encoder', 'decoder', 'none', 'both'] = 'both', use_layer_norm: Literal['encoder', 'decoder', 'none', 'both'] = 'none', latent_distribution: Literal['normal', 'ln'] = 'normal', deeply_inject_covariates: bool = False, encode_covariates: bool = True, protein_background_prior_mean: ndarray | None = None, protein_background_prior_scale: ndarray | None = None, protein_dispersion: Literal['protein', 'protein-batch', 'protein-label'] = 'protein', protein_batch_mask: Dict[str | int, ndarray] = None, log_variational: bool = True, library_log_means: ndarray | None = None, library_log_vars: ndarray | None = None, kl_dot_product: bool = False, deep_network: bool = False, use_size_factor_key: bool = False, use_observed_lib_size: bool = True)#
forward(tensors, get_inference_input_kwargs: dict | None = None, get_generative_input_kwargs: dict | None = None, inference_kwargs: dict | None = None, generative_kwargs: dict | None = None, loss_kwargs: dict | None = None, compute_loss=True, swap=False) tuple[Tensor, Tensor] | tuple[Tensor, Tensor, LossOutput]#

Forward pass through the network.

Parameters:
  • tensors – tensors to pass through

  • get_inference_input_kwargs – Keyword args for _get_inference_input()

  • get_generative_input_kwargs – Keyword args for _get_generative_input()

  • inference_kwargs – Keyword args for inference()

  • generative_kwargs – Keyword args for generative()

  • loss_kwargs – Keyword args for loss()

  • compute_loss – Whether to compute loss on forward pass. This adds another return value.

generative(z: Tensor, zr: Tensor, zp: Tensor | None, za: Tensor | None, library_gene: Tensor, batch_index: Tensor, label: Tensor, cont_covs=None, cat_covs=None, size_factor=None, transform_batch: int | None = None) Dict[str, Tensor | Dict[str, Tensor]]#

Run the generative step.

get_reconstruction_loss_accessibility(x, p, d)#

Computes the reconstruction loss for the accessibility data.

get_reconstruction_loss_expression(x, px_rate, px_r, px_dropout)#

Computes the reconstruction loss for the expression data.

get_reconstruction_loss_protein(y, py_, pro_batch_mask_minibatch=None)#

Get the reconstruction loss for protein data.

get_sample_dispersion(x: Tensor, y: Tensor | None = None, batch_index: Tensor | None = None, label: Tensor | None = None, n_samples: int = 1) Tuple[Tensor, Tensor]#

Returns the tensors of dispersions for genes and proteins.

Parameters:
  • x – tensor of values with shape (batch_size, n_input_genes)

  • y – tensor of values with shape (batch_size, n_input_proteins)

  • batch_index – array that indicates which batch the cells belong to with shape batch_size

  • label – tensor of cell-types labels with shape (batch_size, n_labels)

  • n_samples – number of samples

Returns:

tensors of dispersions of the negative binomial distribution

Return type:

type

inference(x: Tensor, y: Tensor, c: Tensor, batch_index: Tensor | None = None, label: Tensor | None = None, n_samples=1, cont_covs=None, cat_covs=None) Dict[str, Tensor | Dict[str, Tensor]]#

Internal helper function to compute necessary inference quantities.

We use the dictionary px_ to contain the parameters of the ZINB/NB for genes. The rate refers to the mean of the NB, dropout refers to Bernoulli mixing parameters. scale refers to the quanity upon which differential expression is performed. For genes, this can be viewed as the mean of the underlying gamma distribution.

We use the dictionary py_ to contain the parameters of the Mixture NB distribution for proteins. rate_fore refers to foreground mean, while rate_back refers to background mean. scale refers to foreground mean adjusted for background probability and scaled to reside in simplex. back_alpha and back_beta are the posterior parameters for rate_back. fore_scale is the scaling factor that enforces rate_fore > rate_back.

px_["r"] and py_["r"] are the inverse dispersion parameters for genes and protein, respectively.

Parameters:
  • x – tensor of values with shape (batch_size, n_input_genes)

  • y – tensor of values with shape (batch_size, n_input_proteins)

  • batch_index – array that indicates which batch the cells belong to with shape batch_size

  • label – tensor of cell-types labels with shape (batch_size, n_labels)

  • n_samples – Number of samples to sample from approximate posterior

  • cont_covs – Continuous covariates to condition on

  • cat_covs – Categorical covariates to condition on

loss(tensors, inference_outputs, generative_outputs, pro_recons_weight=1.0, kl_weight=1.0) Tuple[FloatTensor, FloatTensor, FloatTensor, FloatTensor]#

Returns the reconstruction loss and the Kullback divergences.

Parameters:
  • x – tensor of values with shape (batch_size, n_input_genes)

  • y – tensor of values with shape (batch_size, n_input_proteins)

  • batch_index – array that indicates which batch the cells belong to with shape batch_size

  • label – tensor of cell-types labels with shape (batch_size, n_labels)

Returns:

the reconstruction loss and the Kullback divergences

Return type:

type

sample(tensors, n_samples=1, swap_latent=False)#

Sample from the generative model.