Base componenets#
- class multiHIVE.nn._base_components.Encoder(n_input_genes: int, n_input_proteins: int, n_input_regions: int, n_input: int, n_batch: int, n_continuous_cov: int, n_latent: int = 20, n_cat_list: Iterable[int] = None, n_hidden: int = 256, dropout_rate: float = 0.1, distribution: str = 'ln', kl_dot_product: bool = False, deep_network: bool = False, encode_covariates: bool = False, n_cats_per_cov: Iterable[int] | None = None, latent_distribution: Literal['normal', 'ln'] = 'normal', use_layer_norm: bool = True, use_batch_norm: bool = True, deeply_inject_covariates: bool = False)#
A helper class to build blocks of fully-connected, normalization and dropout layers.
- forward(gene: Tensor, protein: Tensor, acc: Tensor, data: Tensor, *cat_list: int)#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class multiHIVE.nn._base_components.Decoder(n_input: int, n_output_genes: int, n_output_proteins: int = 0, n_output_regions: int = 0, n_cat_list: Iterable[int] = None, n_layers: int = 1, n_hidden: int = 256, dropout_rate: float = 0, use_batch_norm: float = True, use_layer_norm: float = False, scale_activation: Literal['softmax', 'softplus'] = 'softmax')#
A helper class to build custom decoders depending on which loss was passed.
- forward(z: Tensor, zr: Tensor, zp: Tensor, za: Tensor, library_gene: Tensor, *cat_list: int)#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class multiHIVE.nn._base_components.EncoderAcc(n_input: int, n_output: int, n_cat_list: Iterable[int] = None, n_layers: int = 1, n_hidden: int = 128, dropout_rate: float = 0.1, distribution: str = 'normal', var_eps: float = 0.0001, var_activation: Callable | None = None, return_dist: bool = False, **kwargs)#
Encode data of
n_inputdimensions into a latent space ofn_outputdimensions.Uses a fully-connected neural network of
n_hiddenlayers.- Parameters:
n_input – The dimensionality of the input (data space)
n_output – The dimensionality of the output (latent space)
n_cat_list – A list containing the number of categories for each category of interest. Each category will be included using a one-hot encoding
n_layers – The number of fully-connected hidden layers
n_hidden – The number of nodes per hidden layer
dropout_rate – Dropout rate to apply to each of the hidden layers
distribution – Distribution of z
var_eps – Minimum value for the variance; used for numerical stability
var_activation – Callable used to ensure positivity of the variance. Defaults to
torch.exp().return_dist – Return directly the distribution of z instead of its parameters.
**kwargs – Keyword args for
FCLayers
- forward(x: Tensor, *cat_list: int)#
The forward computation for a single sample.
Encodes the data into latent space using the encoder network
Generates a mean \( q_m \) and variance \( q_v \)
Samples a new value from an i.i.d. multivariate normal \( \sim Ne(q_m, \mathbf{I}q_v) \)
- Parameters:
x – tensor with shape (n_input,)
cat_list – list of category membership(s) for this sample
- Returns:
tensors of shape
(n_latent,)for mean and var, and sample- Return type:
3-tuple of
torch.Tensor