gedi2py.tools.svd

gedi2py.tools.svd(adata, *, key='gedi', copy=False)[source]

Compute factorized SVD from GEDI decomposition.

Computes SVD while preserving GEDI’s factorized structure: SVD(Z) × SVD(middle) × SVD(DB). This maintains biological interpretability by respecting the decomposition structure.

Parameters:
  • adata (AnnData) – Annotated data matrix with GEDI results in .uns[key].

  • key (str, default: 'gedi') – Key in adata.uns where GEDI results are stored.

  • copy (bool, default: False) – If True, return the SVD result as a dict instead of storing in adata.

Return type:

dict | None

Returns:

  • If ``copy=True``, returns dict with keys ````’d’:py:class:``, :py:class:``’u’:py:class:``, :py:class:``’v’:py:class:`.`

  • Otherwise, stores results in ``adata.uns[key][``’svd’:py:class:`]` and returns ``None`.`

  • The SVD components are

    • d: Singular values (K,)

    • u: Left singular vectors (n_genes, K) - gene loadings

    • v: Right singular vectors (n_cells, K) - cell embeddings

Examples

>>> import gedi2py as gd
>>> gd.tl.gedi(adata, batch_key="sample", n_latent=10)
>>> gd.tl.svd(adata)
>>> adata.uns["gedi"]["svd"]["d"]  # singular values