scxpand.autoencoders.ae_modules#
Functions
|
Apply inverse transforms to decoder mean output to match row-normalized target scale. |
Activation function for dropout probability parameter. |
|
Activation function for theta dispersion parameter in negative binomial regression. |
Classes
|
Base class for autoencoder models. |
|
|
|
|
|
|
|
- class scxpand.autoencoders.ae_modules.BaseAutoencoder(data_format, latent_dim=32, encoder_hidden_dims=(64,), decoder_hidden_dims=(64,), classifier_hidden_dims=(16,), dropout_rate=0.3)#
Base class for autoencoder models.
- __init__(data_format, latent_dim=32, encoder_hidden_dims=(64,), decoder_hidden_dims=(64,), classifier_hidden_dims=(16,), dropout_rate=0.3)#
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- decode(latent_vec)#
Decode latent representation to output parameters.
- Parameters:
latent_vec (
Tensor) – Latent vector, shape [batch_size, latent_dim]- Returns:
mu: Mean parameter after inverse transforms to match row-normalized target scale, shape [batch_size, n_genes], non-negative
pi: Zero-inflation parameter, shape [batch_size, n_genes] (None if not needed, in [0, 1])
theta: Dispersion parameter, shape [batch_size, n_genes] (None if not needed, positive values)
- Return type:
DecoderOutput containing
Note
The decoder handles activation and inverse transforms internally.
- encode(x)#
Encode input data to latent representation.
- Parameters:
x (
Tensor) – Input data tensor, shape [batch_size, n_genes]- Returns:
Latent representation, shape [batch_size, latent_dim]
- Return type:
latent_vec
- forward(x)#
Forward pass through the autoencoder model.
- Return type:
- class scxpand.autoencoders.ae_modules.CategoricalHead(latent_dim=32, hidden_dims=(16,), dropout_rate=0.3, n_classes=2, feature_name=None)#
- __init__(latent_dim=32, hidden_dims=(16,), dropout_rate=0.3, n_classes=2, feature_name=None)#
Initialize a classification head for a categorical feature.
- Parameters:
latent_dim (
int(default:32)) – Input dimension (latent vector size)hidden_dims (
tuple[int,...] (default:(16,))) – Dimensions of hidden layersdropout_rate (
float(default:0.3)) – Dropout probabilityn_classes (
int(default:2)) – Number of classes for this categorical featurefeature_name (
str|None(default:None)) – Name of the feature this head predicts (for debugging)
- class scxpand.autoencoders.ae_modules.ClassificationHead(latent_dim=32, hidden_dims=(16,), dropout_rate=0.3)#
- __init__(latent_dim=32, hidden_dims=(16,), dropout_rate=0.3)#
Initialize classification head network.
- class scxpand.autoencoders.ae_modules.Decoder(latent_dim=32, hidden_dims=(64,), dropout_rate=0.3, n_genes=None, needs_pi=True, needs_theta=True, data_format=None)#
- __init__(latent_dim=32, hidden_dims=(64,), dropout_rate=0.3, n_genes=None, needs_pi=True, needs_theta=True, data_format=None)#
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(latent_vec)#
Forward pass through the decoder.
- Parameters:
latent_vec (
Tensor) – Latent vector from encoder- Returns:
mu: Mean parameter after inverse transforms to match row-normalized target scale
pi: Dropout probability (None if not needed), in [0, 1]
theta: Dispersion parameter (None if not needed)
- Return type:
DecoderOutput containing
- class scxpand.autoencoders.ae_modules.Encoder(in_dim, latent_dim=32, hidden_dims=(64,), dropout_rate=0.3)#
- __init__(in_dim, latent_dim=32, hidden_dims=(64,), dropout_rate=0.3)#
Initialize encoder network.
- forward(x)#
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.- Return type:
- scxpand.autoencoders.ae_modules.apply_inverse_transforms_to_mean(raw_mu, data_format)#
Apply inverse transforms to decoder mean output to match row-normalized target scale.
Applies inverse transforms in reverse order: 1. Inverse z-score normalization 2. Inverse log transform (if used)
- Parameters:
raw_mu (
Tensor) – Decoder mean output (raw logits from the model)data_format (
DataFormat) – Data format containing normalization parameters
- Return type:
- Returns:
Transformed mean that matches row-normalized target scale
- scxpand.autoencoders.ae_modules.dropout_activation(x)#
Activation function for dropout probability parameter.
Range: (0, 1) as appropriate for probabilities.
- Return type: