Skip to main content

Liora: Lorentz Interpretable ODE-Regularized Attention-based VAE

Project description

Liora: Lorentz Interpretable ODE-Regularized Attention-based VAE

A deep learning framework for single-cell RNA-seq analysis combining geometric manifold learning, latent dynamics, and comprehensive interpretability.

License: MIT Python 3.9+ PyPI

Liora is a PyTorch-based variational autoencoder (VAE) for single-cell RNA-seq (AnnData) that learns low-dimensional embeddings from raw count matrices using count-likelihood objectives (NB/ZINB/Poisson/ZIP). It integrates (1) Lorentz/hyperbolic manifold regularization for hierarchical structure, (2) latent Neural ODE dynamics for continuous trajectory inference, and (3) an extensive interpretability suite for gene-to-latent attribution.

Key Features

  • Advanced VAE Architecture: Dimensionality reduction with count-based likelihoods (NB, ZINB, Poisson, ZIP)
  • Geometric Manifold Learning: Lorentz (hyperbolic) or Euclidean regularization for hierarchical structure
  • Neural ODE Trajectories: Latent dynamics solved with torchdiffeq (CPU by design). Supports ODE function types legacy, time_mlp (time-conditioned), and gru.
  • Comprehensive Interpretability: Attribution analysis for Genes → Latents (discriminative) and Latents → Genes (reconstructive) pathways.
  • Flexible Encoders: Standard MLP or Transformer-based with self-attention for capturing complex feature dependencies.
  • Information Bottleneck: Hierarchical representation with controllable compression via the i_dim parameter.

Data Requirements

  • adata.layers[layer] must contain raw, non-negative integer-like counts (UMI counts).
    Liora checks this heuristically and raises a ValueError if the layer looks normalized/log-transformed.
  • Liora applies its own log1p + clipping / adaptive normalization internally for training.

Installation

pip install liora

Or install from source:

git clone https://github.com/PeterPonyu/Liora.git
cd Liora
pip install -e .

Quick Start

Basic Usage

import scanpy as sc
from liora import Liora

# Load your data
adata = sc.read_h5ad('data.h5ad')

# Train with default settings
model = Liora(
    adata,
    layer='counts',
    hidden_dim=128,
    latent_dim=10,
    i_dim=2,
)
model.fit(epochs=100)

# Extract embeddings
latent = model.get_latent()

Advanced Configuration

# Transformer encoder + Neural ODE trajectory inference
model = Liora(
    adata,
    layer='counts',
    hidden_dim=128,
    latent_dim=10,
    i_dim=2,
    # Encoder configuration
    encoder_type='transformer',
    attn_embed_dim=64,
    attn_num_heads=4,
    attn_num_layers=2,
    attn_seq_len=32,
    # ODE configuration
    use_ode=True,
    ode_type='time_mlp',
    ode_time_cond='concat',
    ode_hidden_dim=64,
    ode_solver_method='dopri5',
    ode_rtol=1e-5,
    ode_atol=1e-7,
    # Loss weights
    lorentz=5.0,
    beta=1.0,
)
model.fit(epochs=200, patience=20)

# Extract results
latent = model.get_latent()           # Latent embeddings
bottleneck = model.get_bottleneck()   # Information bottleneck
pseudotime = model.get_time()         # Predicted pseudotime
transitions = model.get_transition()  # Transition matrix

Note: get_time() and get_transition() require use_ode=True.

Configuration Guide

Architecture Parameters

Parameter Type Default Description
hidden_dim int 128 Hidden layer dimension
latent_dim int 10 Primary latent space size
i_dim int 2 Information bottleneck dimension

Encoder Options

Parameter Type Default Description
encoder_type str 'mlp' 'mlp' or 'transformer'
attn_embed_dim int 64 Transformer embedding dimension
attn_num_heads int 4 Number of attention heads
attn_num_layers int 2 Transformer encoder layers
attn_seq_len int 32 Token sequence length

ODE Configuration

Parameter Type Default Description
use_ode bool False Enable Neural ODE
ode_type str 'time_mlp' 'legacy', 'time_mlp', or 'gru'
ode_time_cond str 'concat' 'concat', 'film', or 'add'
ode_hidden_dim int None ODE network hidden size
ode_solver_method str 'rk4' Solver: 'rk4', 'dopri5', 'adams', etc.
ode_step_size float None Fixed-step size or 'auto'
ode_rtol float None Relative tolerance (adaptive solvers)
ode_atol float None Absolute tolerance (adaptive solvers)

Loss Configuration

Parameter Type Default Description
recon float 1.0 Reconstruction loss weight
irecon float 0.0 Bottleneck reconstruction weight
lorentz float 0.0 Manifold regularization weight
beta float 1.0 KL divergence weight (β-VAE)
dip float 0.0 DIP-VAE loss weight
tc float 0.0 Total Correlation loss weight
info float 0.0 MMD loss weight
loss_type str 'nb' 'nb', 'zinb', 'poisson', or 'zip'

Training Parameters

Parameter Type Default Description
lr float 1e-4 Learning rate
batch_size int 128 Mini-batch size
train_size float 0.7 Training set proportion
val_size float 0.15 Validation set proportion
test_size float 0.15 Test set proportion

Methods

Training

model.fit(epochs=400, patience=25, val_every=5, early_stop=True)

Extraction

latent = model.get_latent()           # Latent representations
bottleneck = model.get_bottleneck()   # Information bottleneck embeddings
pseudotime = model.get_time()         # Pseudotime (ODE mode)
transitions = model.get_transition()  # Transition probabilities (ODE mode)

Citation

If you use Liora in your research, please cite:

@software{liora2025,
  title = {Liora: Lorentz Information ODE-Regularized Variational Autoencoder},
  author = {Zeyu Fu},
  year = {2025},
  url = {https://github.com/PeterPonyu/Liora}
}

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

liora-0.4.3.tar.gz (99.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

liora-0.4.3-py3-none-any.whl (121.1 kB view details)

Uploaded Python 3

File details

Details for the file liora-0.4.3.tar.gz.

File metadata

  • Download URL: liora-0.4.3.tar.gz
  • Upload date:
  • Size: 99.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for liora-0.4.3.tar.gz
Algorithm Hash digest
SHA256 ce87532d223ec237d29a1e4243e0a0a58b8704a6b4fe919408af63ee96de275a
MD5 b623089c4fc0e4cfc35d07c835eaa4eb
BLAKE2b-256 73485d8f79faa63aed715c2ca1b23ed941fdd9c4e902f98c82806adfa649bdff

See more details on using hashes here.

File details

Details for the file liora-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: liora-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 121.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for liora-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 131f2fe0941cff0eac2cdec6c2669e9768727a478a1eaf2d294ef6f0a5a7551f
MD5 17047bf2b931168e025b27415576a369
BLAKE2b-256 720515cdeab8509ba1b03bb6302249dc5ade6223e6cdee3057bcdc28acd74bfa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page