Repository navigation
Describe the EM mixture fit and run guide assignment on the full Papalexi dataset - #79
Merged
Merged
Conversation
…lexi dataset The mixture model section claimed an optax fit that matches crispat's output and subsetted the data to 5,000 cells and 10 guides for speed. With scverse/pertpy#1172 the fit is a multi-start EM over all guides and takes a few seconds on CPU, so the tutorial now fits all 20,729 cells and 111 guides, describes the model and threshold rule accurately, and compares the result with the maximum assignment. The notebook was re-executed with that branch.
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Zethson
added a commit
to scverse/pertpy
that referenced
this pull request
Oct 20, 2026
scverse/pertpy-tutorials#79 describes the EM fit and runs the mixture model on the full Papalexi dataset.
Zethson
added a commit
to scverse/pertpy
that referenced
this pull request
Oct 20, 2026
…e assignment (#1172) * Fit the guide RNA mixture model by multi-start EM and fix sparse guide assignment The Poisson-Gaussian mixture behind `assign_mixture_model` was fit by 500 Adam steps from one prior-median start. That left 17 of 102 Papalexi thresholds unconverged, swapped the Gaussian and Poisson components on high-MOI guides so every cell was assigned, and lost small guides to a vanishing Gaussian weight. The model, priors and threshold rule are unchanged. The MAP is now found by EM on the distinct count values of each guide from prior-median and quantile-split starts, keeping the lowest-loss solution that is neither label-switched nor pinned at the weight or scale floor. On Papalexi the result equals crispat run to convergence on all 106 commonly fitted guides (same loss on 106, same threshold on 105), while crispat's default of 500 SVI steps is under-converged on 77 of them and its SVI diverges to NaN on 2 guides when run longer. Also fixed: - `assign_by_threshold` and `assign_to_max_guide` rejected CSC and sparse-array input, which is how the Papalexi dataset ships; the documented example failed on both the positional threshold and the CSC matrix. - Explicitly stored zeros in sparse input entered the mixture fit as log2(0) and silently returned the initial parameters. - `plot_heatmap` saved the permutation instead of the cell positions, so reusing `key_to_save_order` plotted the inverse order. - The sparse threshold kernel was numba-parallel for an elementwise comparison (20x slower than numpy plus compile time) and aliased the input's index buffers. - `only_return_results=True` still wrote the fit to `adata.var`. `learning_rate` is deprecated and ignored. `n_iter` is now the EM iteration cap. Benchmarks on CPU, steady state: Papalexi (20,729 cells x 111 guides) 2.9 s -> 0.14 s; 100k cells x 500 guides 12.6 s and 3.5 GB peak RSS -> 1.0 s and 1.1 GB; crispat serial takes 180 s on Papalexi. * Bump the tutorials submodule for the updated guide assignment notebook scverse/pertpy-tutorials#79 describes the EM fit and runs the mixture model on the full Papalexi dataset. * Require Python 3.13, fix the Read the Docs build and trim guide assignment tests anndata main requires Python 3.13, so the 3.12 test environment and the mypy hook's fresh resolution cannot be solved anymore. The docs build fails on the mocked ete4.Tree reference, which is now ignored like the other ete4 classes. The two regression tests for explicit sparse zeros and the saved heatmap order are dropped and the mixture model docstring is shortened. * Pin Python 3.14 for the mypy hook environment Without a pin uv picks the newest interpreter it can download, currently 3.15, where h5py has no wheel and the source build fails on CI.
Zethson
added a commit
to scverse/pertpy
that referenced
this pull request
Oct 20, 2026
…er (#1173) * Fit the guide RNA mixture model by multi-start EM and fix sparse guide assignment The Poisson-Gaussian mixture behind `assign_mixture_model` was fit by 500 Adam steps from one prior-median start. That left 17 of 102 Papalexi thresholds unconverged, swapped the Gaussian and Poisson components on high-MOI guides so every cell was assigned, and lost small guides to a vanishing Gaussian weight. The model, priors and threshold rule are unchanged. The MAP is now found by EM on the distinct count values of each guide from prior-median and quantile-split starts, keeping the lowest-loss solution that is neither label-switched nor pinned at the weight or scale floor. On Papalexi the result equals crispat run to convergence on all 106 commonly fitted guides (same loss on 106, same threshold on 105), while crispat's default of 500 SVI steps is under-converged on 77 of them and its SVI diverges to NaN on 2 guides when run longer. Also fixed: - `assign_by_threshold` and `assign_to_max_guide` rejected CSC and sparse-array input, which is how the Papalexi dataset ships; the documented example failed on both the positional threshold and the CSC matrix. - Explicitly stored zeros in sparse input entered the mixture fit as log2(0) and silently returned the initial parameters. - `plot_heatmap` saved the permutation instead of the cell positions, so reusing `key_to_save_order` plotted the inverse order. - The sparse threshold kernel was numba-parallel for an elementwise comparison (20x slower than numpy plus compile time) and aliased the input's index buffers. - `only_return_results=True` still wrote the fit to `adata.var`. `learning_rate` is deprecated and ignored. `n_iter` is now the EM iteration cap. Benchmarks on CPU, steady state: Papalexi (20,729 cells x 111 guides) 2.9 s -> 0.14 s; 100k cells x 500 guides 12.6 s and 3.5 GB peak RSS -> 1.0 s and 1.1 GB; crispat serial takes 180 s on Papalexi. * Bump the tutorials submodule for the updated guide assignment notebook scverse/pertpy-tutorials#79 describes the EM fit and runs the mixture model on the full Papalexi dataset. * Require Python 3.13, fix the Read the Docs build and trim guide assignment tests anndata main requires Python 3.13, so the 3.12 test environment and the mypy hook's fresh resolution cannot be solved anymore. The docs build fails on the mocked ete4.Tree reference, which is now ignored like the other ete4 classes. The two regression tests for explicit sparse zeros and the saved heatmap order are dropped and the mixture model docstring is shortened. * Pin Python 3.14 for the mypy hook environment Without a pin uv picks the newest interpreter it can download, currently 3.15, where h5py has no wheel and the source build fails on CI. * Save the binary guide assignment matrix of the mixture model as a layer The per-cell string in obs joins guide names with a separator and caps the number of guides per cell, which loses information in high-MOI designs. The full cell-by-guide binary matrix is now also written to adata.layers[output_layer], sparse for sparse input, mirroring assign_by_threshold.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updates the guide RNA assignment tutorial for scverse/pertpy#1172: the mixture model section now describes the Poisson-Gaussian model and crispat's threshold rule accurately instead of an optax fit, runs on the full Papalexi dataset instead of a 5,000 cell by 10 guide subset, and compares the mixture assignment with the maximum assignment. The notebook was re-executed with that branch, so it should be merged after the pertpy PR.