Skip to content

Commit

Permalink
Add auto to umap (#197)
Browse files Browse the repository at this point in the history
* adds auto to `init_pos`

* add auto to umap

* adds release notes

* adds note

* update note

* update note

* make nicer docstring
  • Loading branch information
Intron7 authored May 17, 2024
1 parent 10d52d5 commit a131b72
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/release-notes/0.10.4.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 0.10.3 {small}`2024-05-14`
### 0.10.4 {small}`2024-05-14`

```{rubric} Features
```
Expand Down
15 changes: 15 additions & 0 deletions docs/release-notes/0.10.5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### 0.10.5 {small}`the future`

```{rubric} Features
```

```{rubric} Performance
```

```{rubric} Bug fixes
```
* fixes an issue with `tl.umap` and `init_pos` {pr}`193` {smaller}`S Dicks`


```{rubric} Misc
```
2 changes: 2 additions & 0 deletions docs/release-notes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Release notes

## Version 0.10.0
```{include} /release-notes/0.10.5.md
```
```{include} /release-notes/0.10.4.md
```
```{include} /release-notes/0.10.3.md
Expand Down
18 changes: 14 additions & 4 deletions src/rapids_singlecell/tools/_umap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
if TYPE_CHECKING:
from anndata import AnnData

_InitPos = Literal["spectral", "random"]
_InitPos = Literal["auto", "spectral", "random"]


def umap(
Expand All @@ -27,7 +27,7 @@ def umap(
maxiter: int | None = None,
alpha: float = 1.0,
negative_sample_rate: int = 5,
init_pos: _InitPos = "spectral",
init_pos: _InitPos = "auto",
random_state=0,
a: float | None = None,
b: float | None = None,
Expand Down Expand Up @@ -72,8 +72,14 @@ def umap(
init_pos
How to initialize the low dimensional embedding. Called `init` in the
original UMAP. Options are:
* 'spectral': use a spectral embedding of the graph.
* 'random': assign initial embedding positions at random.
* 'auto': chooses 'spectral' for `'n_samples' < 1000000`, 'random' otherwise.
* 'spectral': use a spectral embedding of the graph.
* 'random': assign initial embedding positions at random.
.. note::
If your embedding looks odd it's recommended setting `init_pos` to 'random'.
random_state
`int`, `random_state` is the seed used by the random number generator
a
Expand Down Expand Up @@ -150,6 +156,10 @@ def umap(
pre_knn = (knn_indices, knn_dist)
else:
pre_knn = None

if init_pos == "auto":
init_pos = "spectral" if n_obs < 1000000 else "random"

umap = UMAP(
n_neighbors=n_neighbors,
n_components=n_components,
Expand Down

0 comments on commit a131b72

Please sign in to comment.