Skip to content

Commit 44cfc6e

Browse files
docs: clarify method vs transformer in sc.pp.neighbors (#4079)
Co-authored-by: Philipp A. <flying-sheep@web.de>
1 parent d6f2c51 commit 44cfc6e

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
@@ -102,12 +102,12 @@ def neighbors( # noqa: PLR0913
102102
) -> AnnData | None:
103103
"""Compute the nearest neighbors distance matrix and a neighborhood graph of observations :cite:p:`McInnes2018`.
104104
105-
The neighbor search efficiency of this heavily relies on UMAP :cite:p:`McInnes2018`,
106-
which also provides a method for estimating connectivities of data points -
107-
the connectivity of the manifold (`method=='umap'`).
108-
If `method=='gauss'`, connectivities are computed according to :cite:t:`Coifman2005`,
109-
in the adaption of :cite:t:`Haghverdi2016`.
110-
If `method=='jaccard'`, connectivities are computed as in PhenoGraph :cite:p:`Levine2015`.
105+
The computation proceeds in two independent stages.
106+
First, a k-nearest neighbor (kNN) search produces the distance matrix via the estimator passed as ``transformer``.
107+
Second, connectivities are derived from the kNN search output by the kernel selected via ``method``.
108+
The two stages are controlled by independent parameters:
109+
``transformer`` selects the kNN search backend,
110+
``method`` selects the connectivity kernel.
111111
112112
.. array-support:: pp.neighbors
113113
@@ -133,12 +133,14 @@ def neighbors( # noqa: PLR0913
133133
Kernel to assign low weights to neighbors more distant than the
134134
`n_neighbors` nearest neighbor.
135135
method
136+
Kernel that derives connectivities from the kNN search output.
137+
The choice is independent of the kNN search backend,
138+
which is controlled by ``transformer``.
136139
Use 'umap' :cite:p:`McInnes2018`,
137140
'gauss' (Gauss kernel following :cite:t:`Coifman2005` with adaptive width :cite:t:`Haghverdi2016`),
138-
or 'jaccard' (Jaccard kernel as in PhenoGraph, :cite:t:`Levine2015`)
139-
for computing connectivities.
141+
or 'jaccard' (Jaccard kernel as in PhenoGraph, :cite:t:`Levine2015`).
140142
transformer
141-
Approximate kNN search implementation following the API of
143+
kNN search backend following the API of
142144
:class:`~sklearn.neighbors.KNeighborsTransformer`.
143145
See :doc:`/how-to/knn-transformers` for more details.
144146
Also accepts the following known options:

0 commit comments

Comments
 (0)