Skip to content

neighbors(method="gauss") returns a non-symmetric connectivity matrix on the sparse (pynndescent / transformer) path #4416

Description

@ChenziqiAdam

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the main branch of scanpy.

What happened?

The Gaussian kernel of Coifman & Lafon / Haghverdi et al. used by method="gauss" is symmetric, W[i, j] = W[j, i], and _connectivity.gauss explicitly symmetrises the kNN pattern ("compute the symmetric weight matrix"). sc.tl.diffmap / sc.tl.dpt build transitions_sym from these connectivities and assume a symmetric kernel.

Minimal code sample

import numpy as np, scanpy as sc
from anndata import AnnData

x = np.random.default_rng(0).normal(size=(9000, 10)).astype(np.float32)
for transformer in ("sklearn", None):        # None -> pynndescent for n_obs >= 8192
    a = AnnData(x.copy())
    sc.pp.neighbors(a, n_neighbors=15, method="gauss", use_rep="X",
                    transformer=transformer, random_state=0)
    w = a.obsp["connectivities"]
    print(transformer, "max|W - W.T| =", abs(w - w.T).max())

Error output

sklearn max|W - W.T| = 0.0
None max|W - W.T| = 0.65536994

Versions

Details
scanpy 1.14.0
Python 3.13

Activity

  1. added theissue type on Oct 11, 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

    Triage 🩺This issue needs to be triaged by a maintainer

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions