Repository navigation
Conversation
cosine and pearson flatten their inputs and return one distance, so scoring many chromatograms against one profile takes a Python loop. An optional axis now broadcasts the arrays and compares them along it, returning one distance per position of the other axes, and pearson centers each array along the same axis. Without axis the functions flatten and return a float, as before.
This branch has not been deployed
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.
Description
deimos.deconvolution.cosineanddeimos.deconvolution.pearsonflatten their inputs and return one distance. Scoring many extracted-ion chromatograms against one elution profile, as a co-elution test does, then needs a Python loop over rows, so code with that need writes a separate row-wise correlation.This PR adds an optional
axistocosineandpearson:axis(the default), the functions flatten their inputs and return a float, unchanged, soMS2Deconvolution.applyand existing callers give the same results.axis, the arrays are broadcast together and compared along that axis, and the result has one distance per position of the other axes.pearsoncenters each array on its mean along the same axis before comparing, so each row of a 2D array is centered separately. A 2D array of profiles against a 1D profile withaxis=-1gives one distance per row.cosine) or constant (pearson) gives NaN with aRuntimeWarning, as the flattened form already does.Verification
tests/test_deconvolution.py:cosinealong the last axis.pearsonrow distances, including rows offset from each other, and NaN for a constant row.axis0, 1, and -1 and each function, every entry equals a separate flattened call on the corresponding vector.python -m pytest: 391 tests, 5 failing, the same 5 that fail on master in this environment (pandas 3.0.3, NumPy 2.5.2). They areget_1D_profilesandapplycases where this environment's SciPy raises_dfitpack.errorfor a spline with too few points.ruff checkandruff format --checkpass, andpyrightreports the same 7 errors in the two changed files as on master. I have not run the suite under pandas 2.3.3, the version CI installs.1 - pearson(rows, profile, axis=-1)differs from a direct row-wise Pearson correlation ((a @ b) / sqrt(sum(a**2) * sum(b**2))on centered rows) by at most 4.4e-16, once flat rows are mapped from NaN to the direct form's 0. No row crosses a 0.8 correlation threshold between the two.Notes for reviewers
cosineandpearsonare general similarity measures but live indeimos.deconvolution. I left them there. Moving them to a general module with aliases at the old names would be a separate change.np.dot. The two can differ in the last bit of a distance.No related issue.
Quality assurance and AI policy
To maintain project quality and respect maintainer bandwidth, please confirm the following about this pull request (PR):
python -m pytestpasses locally.Status
Developer Certificate of Origin
Note to contributors: We reserve the right to close PRs without review if they appear to lack human validation or do not meet the quality standards described in our contributing guide.