neural-network-hyperparameter-optimization
Summary
Optimize the architecture and training parameters of a conditional VAE model for joint spatial transcriptomics and metabolomics alignment. This skill tunes latent dimension, encoder/decoder layer sizes, and conditional layer dimensions to maximize the model's ability to learn shared representations across modalities.
When to use
When you have preprocessed joint ST/SM AnnData objects (output from joint_adata_sm_st and normalize_total_joint_adata_sm_st) and need to fit a ConditionalVAESTSM model to unify spatial transcriptomics and spatial metabolomics data to a common resolution. Use this skill when you are uncertain about appropriate architecture parameters or when the default initialization produces poor alignment or unstable training.
When NOT to use
- Input data is not jointly preprocessed or normalized using the SpatialMETA pipeline (joint_adata_sm_st and normalize_total_joint_adata_sm_st).
- You have only single-modality data (ST only or SM only); ConditionalVAESTSM is designed for multi-modal alignment.
- Spatial resolution alignment has already been performed by another method; this skill is redundant if ST and SM are already at unified resolution.
Inputs
- Preprocessed joint ST/SM AnnData object with normalized expression data
- ConditionalVAESTSM model architecture specification (latent dimension, layer sizes, conditional layer dimension)
Outputs
- Trained ConditionalVAESTSM model state
- Latent embeddings (stored in AnnData.obsm)
- Normalized expression predictions for validation
How to apply
Initialize ConditionalVAESTSM with candidate architecture parameters: latent dimension (typically 10–50), encoder/decoder layer sizes (e.g., 256, 128 units per layer), and conditional layer dimension. Call ConditionalVAESTSM.fit() on the normalized joint expression data, monitoring the conditional VAE objective function across epochs to detect convergence or overfitting. Extract latent embeddings via ConditionalVAESTSM.get_latent_embedding() and validate alignment by comparing normalized expression predictions (ConditionalVAESTSM.get_normalized_expression()) against the input data; inspect whether ST and SM modalities occupy the same latent space by examining embedding distributions and cross-modal spatial pattern consistency. Adjust parameters iteratively if embeddings collapse to low rank, if the objective plateaus prematurely, or if predicted expression diverges significantly from the input.
Related tools
- spatialMETA (Provides ConditionalVAESTSM model class, joint data preparation (joint_adata_sm_st, normalize_total_joint_adata_sm_st), and latent embedding extraction methods) — https://github.com/WanluLiuLab/SpatialMETA
Examples
from spatialmeta.model import ConditionalVAESTSM; model = ConditionalVAESTSM(latent_dim=32, encoder_dims=[256, 128], decoder_dims=[128, 256], conditional_dim=64); model.fit(adata_joint, epochs=100); latent = model.get_latent_embedding(); adata_joint.obsm['latent_embedding'] = latent
Evaluation signals
- Conditional VAE objective function converges smoothly without early plateau or divergence during training.
- Latent embeddings are non-degenerate (rank > 1 and variance explained across latent dimensions is distributed, not concentrated in one dimension).
- Reconstructed normalized expression (via get_normalized_expression) exhibits low mean squared error or correlation > 0.8 with input expression data.
- Spatial transcriptomics and metabolomics samples cluster together in latent space (low inter-modality distance), indicating successful alignment.
- Extracted latent embeddings stored in AnnData.obsm match expected shape (n_spots, latent_dimension) and contain no NaNs or infinities.
Limitations
- Model convergence and embedding quality depend on the choice of latent dimension and layer sizes; no automatic hyperparameter search is documented in the README.
- ConditionalVAESTSM requires normalized joint ST/SM data; poor preprocessing or batch effects upstream will degrade alignment.
- The article does not provide explicit guidance on hyperparameter ranges, learning rate, or stopping criteria; practitioners must experiment or rely on defaults.
- Validation relies on comparing reconstructed vs. input expression; systematic evaluation against ground truth cross-modal spatial patterns is not documented.
Evidence
- [other] Initialize ConditionalVAESTSM with architecture parameters (latent dimension, encoder/decoder layer sizes, conditional layer dimension).: "Initialize ConditionalVAESTSM with architecture parameters (latent dimension, encoder/decoder layer sizes, conditional layer dimension)."
- [other] Call ConditionalVAESTSM.fit() to train the model on normalized expression data, optimizing the conditional VAE objective to learn shared latent representations across ST and SM modalities.: "Call ConditionalVAESTSM.fit() to train the model on normalized expression data, optimizing the conditional VAE objective to learn shared latent representations across ST and SM modalities."
- [other] Extract latent embeddings using ConditionalVAESTSM.get_latent_embedding() and store in AnnData.obsm.: "Extract latent embeddings using ConditionalVAESTSM.get_latent_embedding() and store in AnnData.obsm."
- [other] Retrieve normalized expression predictions via ConditionalVAESTSM.get_normalized_expression() for validation.: "Retrieve normalized expression predictions via ConditionalVAESTSM.get_normalized_expression() for validation."
- [readme] Update
spatialmeta.model.ConditionalVAESTSM: "Update spatialmeta.model.ConditionalVAESTSM"
- [other] SpatialMETA implements an alignment mechanism that unifies ST and SM data to a common spatial resolution as a core component of its multi-omics integration workflow.: "SpatialMETA implements an alignment mechanism that unifies ST and SM data to a common spatial resolution as a core component of its multi-omics integration workflow."
1---2name: neural-network-hyperparameter-optimization3description: Use when when you have preprocessed joint ST/SM AnnData objects (output from joint_adata_sm_st and normalize_total_joint_adata_sm_st) and need to fit a ConditionalVAESTSM model to unify spatial transcriptomics and spatial metabolomics data to a common resolution.4license: CC-BY-4.05---67# neural-network-hyperparameter-optimization89## Summary1011Optimize the architecture and training parameters of a conditional VAE model for joint spatial transcriptomics and metabolomics alignment. This skill tunes latent dimension, encoder/decoder layer sizes, and conditional layer dimensions to maximize the model's ability to learn shared representations across modalities.1213## When to use1415When you have preprocessed joint ST/SM AnnData objects (output from joint_adata_sm_st and normalize_total_joint_adata_sm_st) and need to fit a ConditionalVAESTSM model to unify spatial transcriptomics and spatial metabolomics data to a common resolution. Use this skill when you are uncertain about appropriate architecture parameters or when the default initialization produces poor alignment or unstable training.1617## When NOT to use1819- Input data is not jointly preprocessed or normalized using the SpatialMETA pipeline (joint_adata_sm_st and normalize_total_joint_adata_sm_st).20- You have only single-modality data (ST only or SM only); ConditionalVAESTSM is designed for multi-modal alignment.21- Spatial resolution alignment has already been performed by another method; this skill is redundant if ST and SM are already at unified resolution.2223## Inputs2425- Preprocessed joint ST/SM AnnData object with normalized expression data26- ConditionalVAESTSM model architecture specification (latent dimension, layer sizes, conditional layer dimension)2728## Outputs2930- Trained ConditionalVAESTSM model state31- Latent embeddings (stored in AnnData.obsm)32- Normalized expression predictions for validation3334## How to apply3536Initialize ConditionalVAESTSM with candidate architecture parameters: latent dimension (typically 10–50), encoder/decoder layer sizes (e.g., 256, 128 units per layer), and conditional layer dimension. Call ConditionalVAESTSM.fit() on the normalized joint expression data, monitoring the conditional VAE objective function across epochs to detect convergence or overfitting. Extract latent embeddings via ConditionalVAESTSM.get_latent_embedding() and validate alignment by comparing normalized expression predictions (ConditionalVAESTSM.get_normalized_expression()) against the input data; inspect whether ST and SM modalities occupy the same latent space by examining embedding distributions and cross-modal spatial pattern consistency. Adjust parameters iteratively if embeddings collapse to low rank, if the objective plateaus prematurely, or if predicted expression diverges significantly from the input.3738## Related tools3940- **spatialMETA** (Provides ConditionalVAESTSM model class, joint data preparation (joint_adata_sm_st, normalize_total_joint_adata_sm_st), and latent embedding extraction methods) — https://github.com/WanluLiuLab/SpatialMETA4142## Examples4344```45from spatialmeta.model import ConditionalVAESTSM; model = ConditionalVAESTSM(latent_dim=32, encoder_dims=[256, 128], decoder_dims=[128, 256], conditional_dim=64); model.fit(adata_joint, epochs=100); latent = model.get_latent_embedding(); adata_joint.obsm['latent_embedding'] = latent46```4748## Evaluation signals4950- Conditional VAE objective function converges smoothly without early plateau or divergence during training.51- Latent embeddings are non-degenerate (rank > 1 and variance explained across latent dimensions is distributed, not concentrated in one dimension).52- Reconstructed normalized expression (via get_normalized_expression) exhibits low mean squared error or correlation > 0.8 with input expression data.53- Spatial transcriptomics and metabolomics samples cluster together in latent space (low inter-modality distance), indicating successful alignment.54- Extracted latent embeddings stored in AnnData.obsm match expected shape (n_spots, latent_dimension) and contain no NaNs or infinities.5556## Limitations5758- Model convergence and embedding quality depend on the choice of latent dimension and layer sizes; no automatic hyperparameter search is documented in the README.59- ConditionalVAESTSM requires normalized joint ST/SM data; poor preprocessing or batch effects upstream will degrade alignment.60- The article does not provide explicit guidance on hyperparameter ranges, learning rate, or stopping criteria; practitioners must experiment or rely on defaults.61- Validation relies on comparing reconstructed vs. input expression; systematic evaluation against ground truth cross-modal spatial patterns is not documented.6263## Evidence6465- [other] Initialize ConditionalVAESTSM with architecture parameters (latent dimension, encoder/decoder layer sizes, conditional layer dimension).: "Initialize ConditionalVAESTSM with architecture parameters (latent dimension, encoder/decoder layer sizes, conditional layer dimension)."66- [other] Call ConditionalVAESTSM.fit() to train the model on normalized expression data, optimizing the conditional VAE objective to learn shared latent representations across ST and SM modalities.: "Call ConditionalVAESTSM.fit() to train the model on normalized expression data, optimizing the conditional VAE objective to learn shared latent representations across ST and SM modalities."67- [other] Extract latent embeddings using ConditionalVAESTSM.get_latent_embedding() and store in AnnData.obsm.: "Extract latent embeddings using ConditionalVAESTSM.get_latent_embedding() and store in AnnData.obsm."68- [other] Retrieve normalized expression predictions via ConditionalVAESTSM.get_normalized_expression() for validation.: "Retrieve normalized expression predictions via ConditionalVAESTSM.get_normalized_expression() for validation."69- [readme] Update `spatialmeta.model.ConditionalVAESTSM`: "Update `spatialmeta.model.ConditionalVAESTSM`"70- [other] SpatialMETA implements an alignment mechanism that unifies ST and SM data to a common spatial resolution as a core component of its multi-omics integration workflow.: "SpatialMETA implements an alignment mechanism that unifies ST and SM data to a common spatial resolution as a core component of its multi-omics integration workflow."