Repository navigation
bugfix for #1725 - #1732
bugfix for #1725#1732
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1732 +/- ##
==========================================
- Coverage 71.31% 71.31% -0.01%
==========================================
Files 91 91
Lines 11114 11113 -1
==========================================
- Hits 7926 7925 -1
Misses 3188 3188
|
ivirshup
left a comment
There was a problem hiding this comment.
Thanks for the fix!
Could this get a test, and a note in the 1.7.2 changelog?
| "`flavor='seurat_v3'` expects raw count data, but non-integers were found.", | ||
| UserWarning, | ||
| ) | ||
| mean_fulldataset, var_fulldataset = _get_mean_var(X) |
There was a problem hiding this comment.
Could remove the variables if they're not used anywhere else:
df["mean"], df["var"] = _get_mean_var(X)|
I updated release notes and added a test for this specific case. I did not write many tests before, so I looked at the other tests and tried to stick to what I saw there. I noted something unexpected when writing the test: When used Is it ok to use that instead? Is it expected that numpy and Test code with numpy ground truth: Test output: |
very interesting, just checked |
I'm not experienced enough to say if what currently happens is maybe more efficient than I think the deviating values I reported above come from what happens in the sparse case ( PS: As I said before, not even sure if these deviations are maybe even expected because of the different way of computing the variance here?! |
|
Calculating the variance on 32 bit floats, especially in the value ranges you have for counts, will result in a fair bit of inaccuracy. Because of this, we calculate variance with 64 bit values internally. To demonstrate: import scanpy as sc, numpy as np
from scanpy.pp._utils import _get_mean_var
pbmc = sc.datasets.pbmc3k()
var_np32 = np.var(pbmc.X.toarray(), axis=0, ddof=1)
var_np64 = np.var(pbmc.X.toarray(), axis=0, ddof=1, dtype=np.float64)
_, var_scanpy = _get_mean_var(pbmc.X)
# These are close
np.testing.assert_allclose(var_np64, var_scanpy)
# Same values are different
assert (np.isclose(var_np32, var_np64) == np.isclose(var_np32, var_scanpy)).all()We don't use the numpy function for variance because then we'd need to create a dense intermediate array. We've previously used |
|
Thanks for the demo code! now its clear to me. I adapted the test to use Any other requests? I think everything else is ready :) |
ivirshup
left a comment
There was a problem hiding this comment.
Looks good to me, thanks!
I'm just going to make a little clean up of the existing code, but this should be good to go.
* fixes scverse#1725 * removed unneeded mean_fulldataset/var_fulldataset variables * release note and tests * making variance dtype explicit in test * Minor cleanup -- ivirshup Co-authored-by: Isaac Virshup <[email protected]>
Fixed by computing global mean/variance outside the batch for loop :)
Verification code (same as in #1725):
Verification code output: