Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor neighbors-based metrics to use NeighborsResults #129

Merged
merged 24 commits into from
Jan 4, 2024
Merged

Conversation

adamgayoso
Copy link
Member

@adamgayoso adamgayoso commented Dec 27, 2023

  • Refactor neighbors-based metrics to use NeighborsResults, making it simpler for users as there is no confusion over passing distances or connectivities. Also reduces overhead of converting back and forth between sparse and dense representations of the neighbor results.
  • Compute umap-based connectivities in this package instead of scanpy, and make the implementation more efficient
  • Remove unnecessary vmap in pcr regression
  • Update notebooks
  • Drop usage of private scanpy functions. Scanpy can likely be dropped as a dependency in a future release if pca with implicit centering for sparse matrices makes it into sklearn
  • Bump to 0.5.0

Fixes #109 as lisi always uses the dense (indices, distances) representation for neighbors. The issue arose when the approximate neighbors method gave a distance of zero to non-self cells.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link

codecov bot commented Dec 28, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (9bd6efb) 93.77% compared to head (a22c3e7) 91.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #129      +/-   ##
==========================================
- Coverage   93.77%   91.00%   -2.77%     
==========================================
  Files          25       25              
  Lines         931      956      +25     
==========================================
- Hits          873      870       -3     
- Misses         58       86      +28     
Files Coverage Δ
src/scib_metrics/_graph_connectivity.py 100.00% <100.00%> (ø)
src/scib_metrics/_lisi.py 100.00% <100.00%> (ø)
src/scib_metrics/benchmark/_core.py 98.60% <100.00%> (-0.03%) ⬇️
src/scib_metrics/nearest_neighbors/__init__.py 100.00% <100.00%> (ø)
src/scib_metrics/nearest_neighbors/_jax.py 100.00% <100.00%> (ø)
src/scib_metrics/nearest_neighbors/_pynndescent.py 100.00% <100.00%> (ø)
src/scib_metrics/utils/_diffusion_nn.py 80.76% <100.00%> (-11.69%) ⬇️
src/scib_metrics/utils/_lisi.py 100.00% <100.00%> (ø)
src/scib_metrics/utils/_pcr.py 92.59% <100.00%> (-0.75%) ⬇️
src/scib_metrics/_nmi_ari.py 93.87% <88.88%> (+0.12%) ⬆️
... and 2 more

... and 1 file with indirect coverage changes

Copy link
Contributor

@jan-engelmann jan-engelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Looked through and ran the tests.

Now for 500 000 cells the main time used is spent in pynndescent (86%) and in fuzzy_simplical_set (4%) see profiling results below. Also, tests are passing. test_kmeans failed for me once locally but has been passing ever since.

Let me know if I should have a look at anything specific!

K = 90
N = 500_000
Q = 30
X = np.random.randn(N, Q)
neigh_result = pynndescent(X, n_neighbors=K)
neigh_result = neigh_result.subset_neighbors(n=K)
new_connect = neigh_result.knn_graph_connectivities
new_dist = neigh_result.knn_graph_distances
Profiling Results

test_adam_profiled

@adamgayoso
Copy link
Member Author

@jan-engelmann thanks! I will make a release soon

@adamgayoso adamgayoso merged commit 26bc3a5 into main Jan 4, 2024
7 checks passed
@adamgayoso adamgayoso deleted the neighbors branch January 4, 2024 17:32
adamgayoso added a commit that referenced this pull request Jan 4, 2024
Refactor neighbors-based metrics to use NeighborsResults, making it simpler for users as there is no confusion over passing distances or connectivities. Also reduces overhead of converting back and forth between sparse and dense representations of the neighbor results.
Compute umap-based connectivities in this package instead of scanpy, and make the implementation more efficient
Remove unnecessary vmap in pcr regression
Update notebooks
Drop usage of private scanpy functions. Scanpy can likely be dropped as a dependency in a future release if pca with implicit centering for sparse matrices makes it into sklearn
Bump to 0.5.0
Fixes #109 as lisi always uses the dense (indices, distances) representation for neighbors. The issue arose when the approximate neighbors method gave a distance of zero to non-self cells.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jan Engelmann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

different neighbors numbers for cells with clisi_knn
2 participants