Metadata-Version: 2.4
Name: poma-bio
Version: 1.0.0
Summary: POMA: Probabilistic Output-Space Multimodal Alignment for Biological Foundation Models
Author-email: Aurelien Pelissier <aurelien.pelissier.38@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/AI-SysBio/POMA
Project-URL: Repository, https://github.com/AI-SysBio/POMA
Project-URL: Issues, https://github.com/AI-SysBio/POMA/issues
Project-URL: LogiCA, https://github.com/AI-SysBio/LogiCA
Keywords: biological-foundation-models,multimodal-alignment,probabilistic-modeling,uncertainty-quantification,bayesian-experimental-design,spectroscopy,protein-engineering,single-cell,antibody-design
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: scipy>=1.10
Requires-Dist: pandas>=2.0
Requires-Dist: scikit-learn>=1.3
Requires-Dist: torch>=2.1
Requires-Dist: transformers>=4.40
Requires-Dist: huggingface-hub>=0.20
Requires-Dist: pyyaml>=6.0
Requires-Dist: matplotlib>=3.7
Provides-Extra: chem
Requires-Dist: rdkit>=2023.9; extra == "chem"
Requires-Dist: selfies>=2.1; extra == "chem"
Requires-Dist: pyarrow>=14.0; extra == "chem"
Requires-Dist: openpyxl>=3.1; extra == "chem"
Provides-Extra: singlecell
Requires-Dist: anndata>=0.10; extra == "singlecell"
Provides-Extra: antibody
Requires-Dist: ablang2>=0.1.2; extra == "antibody"
Requires-Dist: kagglehub>=0.3.0; extra == "antibody"
Provides-Extra: logica
Requires-Dist: logica-bio>=0.1.0; extra == "logica"
Provides-Extra: dev
Requires-Dist: pytest>=7.4; extra == "dev"
Requires-Dist: seaborn>=0.12; extra == "dev"
Requires-Dist: build>=1.0; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Provides-Extra: all
Requires-Dist: rdkit>=2023.9; extra == "all"
Requires-Dist: selfies>=2.1; extra == "all"
Requires-Dist: pyarrow>=14.0; extra == "all"
Requires-Dist: openpyxl>=3.1; extra == "all"
Requires-Dist: anndata>=0.10; extra == "all"
Requires-Dist: ablang2>=0.1.2; extra == "all"
Requires-Dist: kagglehub>=0.3.0; extra == "all"
Requires-Dist: pytest>=7.4; extra == "all"
Requires-Dist: seaborn>=0.12; extra == "all"
Dynamic: license-file

# POMA: Probabilistic Output-Space Multimodal Alignment for Biological Foundation Models

[![PyPI](https://img.shields.io/pypi/v/poma-bio.svg)](https://pypi.org/project/poma-bio/)
[![Manuscript](https://img.shields.io/badge/Manuscript-PDF-red.svg)](https://github.com/AI-SysBio/POMA/blob/main/manuscript/POMA_manuscript.pdf)
[![Lean 4](https://img.shields.io/badge/Lean%204-130%2F130%20theorems%20%C2%B7%200%20sorries-blueviolet.svg)](https://github.com/AI-SysBio/POMA/blob/main/lean/README.md)
[![Companion: LogiCA](https://img.shields.io/badge/LogiCA-AI--SysBio%2FLogiCA-purple.svg)](https://github.com/AI-SysBio/LogiCA)
[![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://github.com/AI-SysBio/POMA/blob/main/pyproject.toml)
[![PyTorch 2.1+](https://img.shields.io/badge/PyTorch-2.1%2B-ee4c2c.svg)](https://pytorch.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/AI-SysBio/POMA/blob/main/LICENSE)

<p align="center">
  <img src="https://raw.githubusercontent.com/AI-SysBio/POMA/main/figures/POMA_Figure1.png" width="96%" alt="POMA: Probabilistic Output-Space Multimodal Alignment for Biological Foundation Models"/>
</p>

**POMA** (*Probabilistic Output-Space Multimodal Alignment*) generalizes the conditional likelihood objective underlying masked language modeling (MLM) to native continuous biological measurements. Rather than replacing calibrated sequence likelihoods with pointwise MSE regression, numerical tokenization, or representation-only latent projections, POMA equips pretrained discrete and continuous biological foundation models with **structured predictive densities in their native output spaces**, connected through **unit-invariant, context-matched likelihood-ratio alignment**.

Because one learned statistical object preserves calibrated densities directly over native observables, **a single trained POMA checkpoint** exposes six unified capabilities without task-specific retraining:
- **Probabilistic Adaptation & Uncertainty Quantification** across nine structured output families (`LowRankMVN`, heavy-tailed `LowRankMVT`, multimodal `CoupledGMM`, zero-inflated `HurdleContinuous`, `CoupledTobit`, `BandedLowRank`, `Gaussian`, `Kumaraswamy`, `ZINB`);
- **Zero-Retraining Analytical Conditional Inference** via exact Woodbury/Schur conditioning (`76×–752×` per-update speedup on frozen `scGPT`, `>2,800×` vs. `117M DreaMS` re-encoding, `6.4×10⁻⁶` sequential-vs-joint Bayesian coherence);
- **Shortcut-Resistant Cross-Modal Alignment** via context-matched mixture-reference likelihood ratios and adaptive bidirectional weighting;
- **Continuous & Cross-Modal Dependency Maps** extracting exact Woodbury precision / partial-correlation matrices and cross-modal KL perturbation maps;
- **Bayesian Epistemic Closure & Experimental Design** (`POMA-Laplace`, Rao-Blackwellized joint feasibility, and cost-budgeted `EVSI/cost` acquisition);
- **Exact-Target Property-Conditioned Generation** (`Exact Local MH`, `Factor-Augmented MH`, and `Coordinate Gibbs`) preserving $\pi_\beta(x) \propto p_0(x)\exp(\beta U(x))$.

---

## Repository Structure

```text
POMA/
├── src/poma/                            # Modular Python library (`pip install -e .`)
│   ├── backbones.py                     # Universal wrappers for discrete (HF MLM) & continuous (DreaMS, scGPT, custom) BioFMs
│   ├── model.py                         # Unified `POMA` (9 density families + Schur conditioning) & `CrossModalPOMA`
│   ├── bayesian.py                      # `BayesianPOMA` (last-layer Laplace, uncertainty decomposition, joint feasibility, EVSI/cost)
│   ├── dependency.py                    # `DependencyMapper` (Woodbury precision/partial-corr & cross-modal KL maps)
│   ├── generation.py                    # `POMAGenerator` (Exact Local MH & Coordinate Gibbs sequence design)
│   ├── logica_bridge.py                 # Drop-in `LogiCAPOMABridge` for AI-SysBio/LogiCA backbones
│   └── models/                          # Core density heads, spectral heads, bioFM alignment blocks & losses
├── example/                             # Quickstart + all manuscript reproduction scripts (Main & Supp. E1–E15)
│   ├── quickstart.py                    # End-to-end runnable showcase of all 6 POMA capabilities
│   ├── README.md                        # Complete mapping from manuscript tables/experiments to scripts
│   └── 01_download_datasets.py .. 53_run_e15_unified_checkpoint.py
├── manuscript/                          # Latest manuscript PDF, LaTeX source & publication figures
│   ├── POMA_manuscript.pdf              # Full compiled manuscript + supplementary
│   ├── main.tex                         # Standalone LaTeX source
│   └── figures/                         # POMA_Figure1.pdf, POMA_Figure2.pdf, POMA_FigureS1.pdf
├── lean/                                # Complete Lean 4 formalization (130/130 theorems, 0 sorries)
│   ├── Poma.lean                        # Root Lean 4 library entry point
│   ├── AxiomCheck.lean                  # Machine-checked axiom audit
│   └── Poma/                            # Formal proofs of invariance, Schur coherence, Laplace, EVSI & MH theorems
├── figures/                             # Top-level rendered figures (POMA_Figure1.png, POMA_Figure2.png)
├── results/                             # Aggregated benchmark tables & audit summaries
└── tests/                               # Unit test suite covering the library API, heads, Bayes & samplers
```

---

## Installation

Python 3.10 or later is recommended. Install directly from PyPI:

```bash
# Core library (`import poma`)
pip install poma-bio

# With chemistry (RDKit + SELFIES), single-cell (anndata), antibody (AbLang2), or all extras
pip install "poma-bio[chem]"
pip install "poma-bio[all]"
```

Or install from source in editable mode:

```bash
git clone https://github.com/AI-SysBio/POMA.git
cd POMA
pip install -e ".[all]"

# Run the unit test suite & end-to-end quickstart
pytest tests/ -v
python example/quickstart.py
```

---

## Quickstart: Using the Modular `poma` Library

### 1. Plug in Any Pretrained Discrete or Continuous Foundation Model

```python
import torch
from poma import ContinuousBackbone, CrossModalPOMA, DiscreteBackbone, POMA

# Discrete BioFM (any Hugging Face Masked LM: ChemBERTa, ESM-2, SELFormer, Nucleotide Transformer)
mol_fm = DiscreteBackbone.from_pretrained("DeepChem/ChemBERTa-77M-MLM", freeze=True)

# Continuous BioFM (official 117M DreaMS, frozen scGPT, or any custom PyTorch encoder)
spec_fm = ContinuousBackbone.from_dreams(num_tokens=8, freeze=True)
# scgpt_fm, gene_vocab = ContinuousBackbone.from_scgpt(freeze=True)

# Cross-modal output-space alignment with shortcut-resistant context-matched PMI (E12)
aligner = CrossModalPOMA(
    primary_dim=mol_fm.hidden_dim,
    partner_dim=spec_fm.hidden_dim,
    adapter_dim=128,
    num_heads=4,
)
# Contrastive loss using context-matched mixture reference log(q(x|y) / E_{y'}[q(x|y')])
loss = aligner.alignment_loss(ll_x_given_y, ll_y_given_x, temperature=0.15, context_matched=True)
```

### 2. Probabilistic Prediction & Zero-Retraining Analytical Conditioning

```python
from poma import POMA

# Choose from: "mvn", "mvt", "gmm", "hurdle", "tobit", "banded_lowrank", "gaussian", "kumaraswamy", "zinb"
model = POMA(hidden_dim=64, distribution="mvn", rank=3)

h = torch.randn(16, 6, 64)                  # (batch, K coordinates/assays, hidden_dim)
y = torch.randn(16, 6)                      # continuous measurements
obs_mask = torch.rand(16, 6) > 0.25         # arbitrary missingness pattern
obs_mask[:, 0] = True

# Exact O(|S| r^2 + r^3) Woodbury masked negative log-likelihood
loss = model.nll(h, y, obs_mask=obs_mask)
pred = model.predict(h[:4])                 # pred.mean, pred.variance, pred.lower95, pred.upper95

# Exact analytical Schur conditioning given newly observed coordinates (zero retraining!)
triage_mask = torch.tensor([[False, False, True, True, True, True]] * 4)
cond = model.condition(h[:4], y[:4], triage_mask)
```

### 3. Bayesian Epistemic Uncertainty, Dependency Maps & Exact-Target Generation

```python
from poma import BayesianPOMA, DependencyMapper, POMAGenerator

# Closed-form last-layer Laplace epistemic uncertainty, joint feasibility & EVSI/cost
bayes = BayesianPOMA(model, prior_precision=3.0).fit(h, y, obs_mask=obs_mask)
unc = bayes.decompose_uncertainty(h[:4])    # aleatoric_var, epistemic_var, total_var
feas = bayes.joint_feasibility(h[:4], lower=torch.full((6,), -1.0), upper=torch.full((6,), 1.0))
evsi = bayes.evsi_per_cost(h[:4], lower=torch.full((6,), -1.0), upper=torch.full((6,), 1.0),
                           assay_costs=torch.tensor([10., 8., 1., 1., 2., 2.]))

# Continuous covariance, correlation, exact Woodbury precision & partial-correlation dependency maps
dep = DependencyMapper.continuous_dependency_map(model, h[:2])
# dep.covariance, dep.correlation, dep.precision, dep.partial_correlation

# Property-conditioned discrete sequence generation preserving pi_beta(x) propto p_0(x) exp(beta U(x))
generator = POMAGenerator(log_prior_fn=prior_fn, log_utility_fn=utility_fn, beta=1.0)
gen_out = generator.sample_exact_local_mh(init_seq="ACDEFGH", editable_positions=[1, 2, 3, 4], n_steps=100)
```

---

## Manuscript Reproduction (`example/`) & Lean 4 Formalization (`lean/`)

- **Reproducing Manuscript Results:** See [`example/README.md`](example/README.md) for the complete index of all 63 scripts reproducing every main-text benchmark and supplementary validation experiment (**E1–E15**), including large-scale `ChemBERTa-77M` $\leftrightarrow$ `117M DreaMS` alignment, 500-unique-molecule retrieval, shortcut-resistant context-matched alignment, representation leakage audits, mask-matched neural vs. analytical Schur conditioning, and unified single-checkpoint evaluation.
- **Machine-Checked Formalization (`lean/`):** All mathematical statements in the manuscript—likelihood-ratio unit invariance, Woodbury/Schur sequential-vs-joint coherence, Laplace epistemic closure, decision-aware acquisition bounds, and exact MH stationary invariance—are formally verified in Lean 4 (**130/130 theorems, zero `sorry`s**; see [`lean/README.md`](lean/README.md)).

---

## Citation

```bibtex
@article{pelissier2026poma,
  title   = {Probabilistic Output-Space Multimodal Alignment for Biological Foundation Models},
  author  = {Pelissier, Aurelien},
  journal = {Preprint},
  year    = {2026},
  url     = {https://github.com/AI-SysBio/POMA}
}
```
