grassmann-ot
Cell-to-cell anchoring via Grassmann subspace distance + Optimal Transport,
now with fast, selectable construction backends for large n.
Install
pip install grassmann-ot
For the GPU backends:
pip install torch faiss-gpu # or faiss-cpu
Quick start
import numpy as np
from grassmann_ot import GrassmannOT
# H_X, H_Y come from any external tool (NMF, scVI, Harmony, ...)
# shape: (n_gene_programs, n_cells)
H_X, H_Y = np.random.rand(20, 300), np.random.rand(20, 250)
ot = GrassmannOT(k=30, p=3, reg=0.1, backend="batched")
gamma = ot.fit(H_X, H_Y) # soft coupling, shape (n_X, n_Y)
matches = ot.get_hard_anchors() # one-to-one anchors, shape (K, 2)
Backends (new in 0.3.0)
cells_to_grassmann and GrassmannOT now accept a backend parameter:
| Backend | Requirements | Use when |
|---|---|---|
loop |
numpy | Baseline / debugging |
batched |
torch | Default; medium datasets |
pca |
scipy, numpy | Want 10-20x speed, accept small precision loss |
subsampling |
sklearn, scipy | Very large n, tolerate interpolation |
faiss |
faiss + torch | Largest datasets, GPU available |
from grassmann_ot import cells_to_grassmann
U = cells_to_grassmann(H_X, k=30, p=3, backend="pca")
V = cells_to_grassmann(H_Y, k=30, p=3, backend="pca")
Extra options: batch_size, subsample_rate, inner_backend, device.
You can also skip construction and feed precomputed points directly:
ot = GrassmannOT(k=30, p=3, reg=0.1)
gamma = ot.fit_points(U_list, V_list)
Parameters
| Parameter | Default | Meaning |
|---|---|---|
k |
30 | Neighborhood size |
p |
3 | Subspace dimension |
metric |
cosine | Neighbor metric |
reg |
0.1 | Sinkhorn entropic regularization |
backend |
batched | Grassmann construction strategy |
batch_size |
512 | Batch size for torch SVD |
subsample_rate |
0.1 | Fraction exact-computed in subsampling |
inner_backend |
pca | Backend for seed cells in subsampling |
a, b |
None | Source / target marginals (uniform) |
Benchmark
python examples/benchmark_backends.py
Changelog
0.3.0
- New module
grassmann_ot._grassmann_fastwith five backends. GrassmannOTexposesbackend,batch_size,subsample_rate,inner_backend,device.- New
fit_points()to use precomputed Grassmann point lists. - Fixed
linear_sum_assignmentresult unpacking.
Metadata
Release files for grassmann-ot 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| grassmann_ot-0.3.0.tar.gz | 9.6 kB | Without provenance | Details for grassmann_ot-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| grassmann_ot-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for grassmann_ot-0.3.0-py3-none-any.whl |
Total release size: 20.3 kB
Release files / grassmann_ot-0.3.0.tar.gz
| Download URL | grassmann_ot-0.3.0.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab11fc6aff615b475a02a1033384e5e075a8e8ce5006840f7c1e36f12a801687
|
|
BLAKE2b-256 checksum How to use checksums |
56320c6dc9809c0affea020978cb67cf31bb98c1c31e7ead72cf797fb265da74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.18
|
Release files / grassmann_ot-0.3.0-py3-none-any.whl
| Download URL | grassmann_ot-0.3.0-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
29bac74f6de9493bc65b701a5bd749ca191340fa3fa8b3d52d321f44172896c8
|
|
BLAKE2b-256 checksum How to use checksums |
0aecb61e783370c1a382ec7c0cf20b549895f196085a5df3e46fb5206fd56c7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.18
|
Security for grassmann-ot 0.3.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.