Skip to main content

LiVAE: Lorentz-regularized Interpretable Variational Autoencoder

PyPI DOI Python 3.10+ PyTorch CI License

LiVAE (Lorentz-regularized Interpretable Variational Autoencoder) is a dual-pathway architecture for learning interpretable latent representations from single-cell transcriptomic and epigenomic data. It applies hyperbolic geometry as soft regularization over standard Euclidean latent spaces to balance local fidelity with global coherence.

Installation

# Install from PyPI (recommended)
pip install livae-sc

# Or install from source for development
git clone https://github.com/PeterPonyu/LiVAE.git
cd LiVAE
pip install -e .

From version 0.2.3 the package is published on PyPI as livae-sc; the import name is still livae. The earlier livae project on PyPI stays at 0.2.1 and is no longer updated.

Core Requirements

torch>=2.3
numpy>=1.26
scikit-learn>=1.5
anndata>=0.10
tqdm>=4.66

These are what the livae package imports. The notebooks need more: pip install "livae-sc[notebooks]". The web interface runs from a source checkout (see Web Interface): pip install -e ".[app]".

Python Quick Start

import scanpy as sc
from livae import agent

# Load your single-cell data
adata = sc.read_h5ad('your_data.h5ad')

# Initialize LiVAE agent
model = agent(
    adata=adata,
    layer='counts',         # Data layer to use
    latent_dim=10,          # Primary latent dimension
    i_dim=2,                # Interpretable latent dimension
    hidden_dim=128,         # Hidden layer dimension
    lr=1e-4,                # Learning rate
    # Regularization weights
    beta=1.0,               # β-VAE weight
    lorentz=1.0,            # Lorentzian regularization
    irecon=1.0,             # Interpretable reconstruction
)

# Train the model
model.fit(epochs=100)

# Extract embeddings
latent = model.get_latent()          # Primary latent representation
interpretable = model.get_iembed()   # Interpretable embedding (i_dim)

# Access results
print(f"Latent shape: {latent.shape}")
print(f"Interpretable embedding shape: {interpretable.shape}")

Web Interface

LiVAE includes an integrated web interface for interactive training and visualization.

Launch the Application

# The web app runs from a source checkout; install its extra packages first
pip install -e ".[app]"

# Start the FastAPI server (serves both API and frontend)
uvicorn api.main:app --host 0.0.0.0 --port 8000

Access the web interface at http://localhost:8000

Features

  • Data Upload: Upload single-cell datasets (H5AD format)
  • Training Configuration: Configure model parameters and hyperparameters
  • Real-time Monitoring: Track loss curves and metrics during training
  • Results Visualization: Download embeddings and view training summaries

API Endpoints

  • POST /upload-data - Upload an .h5ad dataset
  • GET /data-summary - Get a summary of the loaded dataset
  • POST /start-training - Start training
  • GET /training-progress - Get training progress and metrics (averaged over the last 10 epochs)
  • POST /stop-training - Stop training
  • GET /embeddings/interpretable - Get the shape of the interpretable embedding
  • GET /embeddings/latent - Get the shape of the latent embedding
  • GET /download/embeddings/{embedding_type} - Download an embedding (interpretable or latent) as CSV
  • GET /status - Get application status

Architecture Overview

LiVAE consists of three main components working in concert:

1. Encoder Network

Input (gene expression) → Hidden → Hidden → μ, σ (latent parameters)
  • Maps high-dimensional gene expression to latent distribution parameters
  • Uses reparameterization trick for differentiable sampling

2. Hyperbolic Transformation

Latent Sample → Tangent Space → Exponential Map → Lorentzian Manifold
  • Projects latent vectors onto hyperbolic manifold
  • Enables natural representation of hierarchical relationships

3. Dual Decoder Pathway

Primary:      Latent → Decoder → Reconstruction
Interpretable: Latent → Compress → Decompress → Decoder → Reconstruction
  • Dual reconstruction paths for enhanced representation learning
  • Compression bottleneck encourages essential feature extraction

Loss Function

LiVAE optimizes a composite loss function:

L_total = L_recon + L_irecon + L_lorentz + L_KL

Where:

  • L_recon: Negative binomial reconstruction loss
  • L_irecon: Interpretable reconstruction loss
  • L_lorentz: Lorentz distance regularization
  • L_KL: KL divergence

Evaluation Metrics

Every training step scores the latent representation of the current mini-batch without using cell labels. Reference labels come from k-means clustering (latent_dim clusters) of the log1p-transformed input layer, computed once when the agent is created; the mini-batch latent representation is clustered with k-means (latent_dim clusters). fit shows the latest scores every 10 epochs:

  • ARI: computed with adjusted_mutual_info_score, i.e. the adjusted mutual information between the reference labels and the latent clusters (not the adjusted Rand index)
  • NMI: normalized mutual information between the reference labels and the latent clusters
  • ASW: silhouette score of the latent clusters
  • C_H: Calinski-Harabasz score of the latent clusters
  • D_B: Davies-Bouldin score of the latent clusters (lower is better)
  • P_C: mean, over latent dimensions, of the summed absolute Pearson correlation with the other latent dimensions

Performance Tips

Memory Optimization

# For large datasets, reduce batch size
model = agent(adata, percent=0.005)  # Use 0.5% of data per batch (default is 1%)

# Use CPU if GPU memory is limited
import torch
model = agent(adata, device=torch.device('cpu'))

Training Efficiency

# Progressive training with increasing regularization
model = agent(adata, beta=0.1, lorentz=0.0)
model.fit(epochs=500)

# Increase regularization for fine-tuning
model.beta = 1.0
model.lorentz = 0.1
model.fit(epochs=500)

Citation

If you use LiVAE in your research, please cite the following paper:

@ARTICLE{10.3389/fgene.2025.1713727,
    AUTHOR={Fu, Zeyu and Fu, Jiawei and Chen, Chunlin and Zhang, Keyang and Wang, Song},
    TITLE={Lorentz-regularized interpretable VAE for multi-scale single-cell transcriptomic and epigenomic embeddings},
    JOURNAL={Frontiers in Genetics},
    VOLUME={16},
    PAGES={1713727},
    YEAR={2026},
    URL={https://www.frontiersin.org/journals/genetics/articles/10.3389/fgene.2025.1713727},
    DOI={10.3389/fgene.2025.1713727},
    ISSN={1664-8021}
}

Contributing

Contributions are welcome! Please ensure tests pass before submitting PRs:

pytest -q

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for livae-sc 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for livae-sc 0.2.5
File Size Uploaded Provenance Actions
livae_sc-0.2.5.tar.gz 19.4 kB With provenance Details for livae_sc-0.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for livae-sc 0.2.5
File Interpreter ABI Platform Actions
livae_sc-0.2.5-py3-none-any.whl Python 3 none any Details for livae_sc-0.2.5-py3-none-any.whl

Total release size: 37.4 kB

Release files / livae_sc-0.2.5.tar.gz

Download URL livae_sc-0.2.5.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e74a2ff918ef55723200f5c60174ee2a0e3e89f541251e81c8aff92207010ed4
BLAKE2b-256 checksum
How to use checksums
64582afbe44d09fa185f36b2a495e9eecc349362e0736b9368714af8e44ff830
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / livae_sc-0.2.5-py3-none-any.whl

Download URL livae_sc-0.2.5-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
424e71ded7c4ecf202c4440ec8123dd9552d22d6aa35fc74ad3947e64e1c127c
BLAKE2b-256 checksum
How to use checksums
672d66e4fe727d373efe3455efe3d0340cda79e2289c02210ed1e0a776e8c3b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Security for livae-sc 0.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for livae_sc-0.2.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page