Skip to content

Commit a4ebf32

Browse files
Backport PR #4079 on branch 1.12.x (docs: clarify method vs transformer in sc.pp.neighbors) (#4086)
Co-authored-by: Cuiwei Gao <48gaocuiwei@gmail.com>
1 parent 1733663 commit a4ebf32

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

docs/release-notes/4079.docs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clarify that `method` selects the connectivity kernel and `transformer` selects the kNN search backend in {func}`~scanpy.pp.neighbors` {smaller}`C Gao`

src/scanpy/neighbors/__init__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ def neighbors( # noqa: PLR0913
9696
) -> AnnData | None:
9797
"""Compute the nearest neighbors distance matrix and a neighborhood graph of observations :cite:p:`McInnes2018`.
9898
99-
The neighbor search efficiency of this heavily relies on UMAP :cite:p:`McInnes2018`,
100-
which also provides a method for estimating connectivities of data points -
101-
the connectivity of the manifold (`method=='umap'`).
102-
If `method=='gauss'`, connectivities are computed according to :cite:t:`Coifman2005`,
103-
in the adaption of :cite:t:`Haghverdi2016`.
104-
If `method=='jaccard'`, connectivities are computed as in PhenoGraph :cite:p:`Levine2015`.
99+
The computation proceeds in two independent stages.
100+
First, a k-nearest neighbor (kNN) search produces the distance matrix via the estimator passed as ``transformer``.
101+
Second, connectivities are derived from the kNN search output by the kernel selected via ``method``.
102+
The two stages are controlled by independent parameters:
103+
``transformer`` selects the kNN search backend,
104+
``method`` selects the connectivity kernel.
105105
106106
.. array-support:: pp.neighbors
107107
@@ -127,12 +127,14 @@ def neighbors( # noqa: PLR0913
127127
Kernel to assign low weights to neighbors more distant than the
128128
`n_neighbors` nearest neighbor.
129129
method
130+
Kernel that derives connectivities from the kNN search output.
131+
The choice is independent of the kNN search backend,
132+
which is controlled by ``transformer``.
130133
Use 'umap' :cite:p:`McInnes2018`,
131134
'gauss' (Gauss kernel following :cite:t:`Coifman2005` with adaptive width :cite:t:`Haghverdi2016`),
132-
or 'jaccard' (Jaccard kernel as in PhenoGraph, :cite:t:`Levine2015`)
133-
for computing connectivities.
135+
or 'jaccard' (Jaccard kernel as in PhenoGraph, :cite:t:`Levine2015`).
134136
transformer
135-
Approximate kNN search implementation following the API of
137+
kNN search backend following the API of
136138
:class:`~sklearn.neighbors.KNeighborsTransformer`.
137139
See :doc:`/how-to/knn-transformers` for more details.
138140
Also accepts the following known options:

0 commit comments

Comments
 (0)