Skip to content

Compute UMAP from pre-existing distance matrix #2157

Description

@ivirshup

It should be easier to compute a UMAP layout from a pre-existing distance matrix. Currently, we only really support this for pre-existing connectivity matrices.

The missing step here is computing the umap weighted graph from a distance matrix.

The functionality for this largely already exists in the sc.neighbors module in private functions (example: #2139 (comment)). We would just need an API.

Previously discussed in: #1561

Activity

  1. added this to the 1.10.0 milestone on Feb 25, 2022
  2. ivirshup commented on Feb 19, 2024

    @ivirshup
    MemberAuthor

    @flying-sheep did this get implemented by your recent work with the neighbors function?

  3. flying-sheep commented on Feb 20, 2024

    @flying-sheep
    Member

    Not conveniently, no:

    @dataclass
    class DummyTranformer:
        distances: sparse.csr_matrix
    
        def get_params(self):
            return dict(n_neighbors=self.distances.getnnz(1)[0])
    
        def fit_transform(self, _):
            return self.distances
    
    pbmc3k = sc.datasets.pbmc3k()
    sc.pp.neighbors(
        pbmc3k,
        use_rep="X",  # prevent it from doing a PCA
        transformer=DummyTranformer(random_dist_mat(pbmc3k.n_obs)),
    )

    and this still computes connectivites.

    We’re much closer though!

  4. modified the milestones: 1.10.0, 1.11.0 on Feb 20, 2024
  5. added
    good first issue
    and removed on Dec 16, 2024
  6. modified the milestones: 1.11.0, 1.12.0 on Dec 20, 2024
  7. Reovirus commented on Apr 8, 2025

    @Reovirus

    @flying-sheep
    Hello. Should we implement separate method for connectivity matrix? Now connectivity matrix is strongly computed in umap AND in gauss methods. Compute it in gauss only will be inconsistent (I can be assignee)

  8. flying-sheep commented on Apr 10, 2025

    @flying-sheep
    Member

    Hm, maybe the best approach would be to rename the method parameter to connectivities, and allow specifying an array/matrix instead of a string for it.

    Then if an array/matrix is passed, only its dimensions are validated, but no connectivities are computed.

  9. Reovirus commented on Apr 11, 2025

    @Reovirus

    Ok. I'll commit in a few days

  10. modified the milestones: 1.12.0, 1.13.0 on Nov 10, 2025
  11. modified the milestones: 1.13.0, 1.14.0 on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area - Topology 🍩good first issue

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions