Prediction reports: training-set membership, novelty and conformal intervals (v4.4.0) - #118
Open
RobbinBouwmeester wants to merge 4 commits into
Open
Prediction reports: training-set membership, novelty and conformal intervals (v4.4.0)#118RobbinBouwmeester wants to merge 4 commits into
RobbinBouwmeester wants to merge 4 commits into
Conversation
Member
Author
|
Index size addressed in 39b621e: the artifact is now a single 105 MB |
A prediction is a number with no way to tell whether the model has seen the peptidoform, merely something like it, or nothing like it, and no statement of how far off it may be. prediction_report answers all three per PSM. Membership and novelty: exact match against the calibration reference and the Levenshtein distance to its closest sequence, always; with a TrainingIndex also exact match against the 10,105,640-peptidoform corpus behind the bundled multitask model, membership within the training sets of the setups the calibration selected, and the distance to the closest training sequence (exact to ten edits, capped beyond; the error is flat in this distance, so the cap costs nothing but keeps the search fast). Canonical keys reproduce the corpus format: peprec positions, Unimod accessions, lowercased unmapped names. Uncertainty: cross-fitted split-conformal intervals on the reference. Each reference fold is predicted by a calibration fitted on the other folds and the half-width is a finite-sample quantile of those honest residuals per predicted-RT bin. On eight held-out PRIDE setups the 90 % interval covered 0.88 to 0.97 per setup (median 0.91), 4 % of the gradient wide on well-behaved setups and honestly wide (79 %) on a run that pools fractions. Chosen over quantile regression because it needs no retraining and carries a finite-sample guarantee; coverage is marginal, not per-peptide. The TrainingIndex (~400 MB: sorted key hashes, per-setup membership CSR, unique sequences) is built offline from the training cache and distributed separately; the report works without it and then carries the reference columns only. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The directory form was 400 MB across seven files, most of it uncompressed structure: raw 64-bit hashes, int64 pointers, plain text. The packed .dlcidx is a stdlib LZMA zip that exploits what each component actually is. Sorted hashes are truncated to 40 bits and stored as 2^24 bucket counts plus 16-bit remainders, which costs a false positive about once per 100,000 membership queries and nothing else; a provenance flag does not need exactness beyond that. CSR pointers become uint16 row lengths (5x under LZMA), the setup lists and the sorted sequences compress 2.8x and 3.1x. Loading rebuilds the sorted hash array in about a second; answers are bit-identical to the directory form on membership, per-setup membership and distances, which the tests now check by running every index test against both formats. TrainingIndex reads both forms; the builder emits both. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
RobbinBouwmeester
force-pushed
the
feat/prediction-report
branch
from
September 2, 2026 09:29
39b621e to
50c3608
Compare
The conformal half-width was a per-RT-bin quantile, so a setup received five distinct widths and two peptides predicted at the same retention time always got the same interval. A multi-head calibration combines heads that each estimate the same retention time, and how far those estimates lie apart varies per peptide. Calibration instances can now report that as disagreement(); the conformal interval divides the honest residuals by it before taking the per-bin quantile and multiplies it back at prediction time, which keeps the coverage guarantee and the RT structure while making the width follow the peptide. Measured through the public API on the six held-out PRIDE setups, against the per-bin widths: worst conditional slice 0.851 -> 0.882, Spearman of width against absolute error 0.151 -> 0.248, coverage 0.909 -> 0.919, relative width 0.0436 -> 0.0478, distinct widths 5 -> 877. The gains are largest where the per-bin width was weakest (PXD080826 0.818 -> 0.888, PXD081924 0.814 -> 0.845). Edit distance to the reference was tested as the scale instead and rejected: three times the width, coverage 0.977 and no correlation with the error. per_peptide_width=False restores the previous behaviour, which also remains the behaviour of single-head calibrations. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What
prediction_report(psm_list, psm_list_reference=..., coverage=0.90, training_index=...)returns predictions together with what a bare number cannot say, one row per PSM:predicted_rtpredict_and_calibrateci_lower,ci_upperin_referencedist_to_referencein_training*in_selected_heads_training*dist_to_training** with a
TrainingIndex, a ~400 MB memory-mapped artifact (sorted key hashes, per-setup membership CSR, 6.16 M unique sequences) built offline from the training cache bybuild_training_index.pyin the research repo. The report works without it. Hosting to be decided (HF hub?).The interval
Cross-fitted split-conformal on the reference: five folds, each predicted by a calibration fitted on the other four, half-width = finite-sample quantile of those honest |residuals| per predicted-RT bin (peak width varies along a gradient). No retraining, works for any model and calibration, finite-sample marginal coverage guarantee. Chosen over quantile regression (pinball) for exactly those reasons.
Validated on the eight held-out PRIDE setups (Figure 1b corpus), nominal 90 %:
End-to-end through this API on three held-out setups: coverage@90 = 0.914 / 0.898 / 0.974, and the membership columns behave (PXD079927: 60 % of test peptidoforms in the corpus but only 1.2 % in the 80 selected setups; PXD081880: 100 % / 95 %).
Per-peptide widths (added after review of the first version)
A per-RT-bin quantile gives a setup five distinct widths, so two peptides predicted at the same retention time always got the same interval — a fair complaint about a "confidence interval". A multi-head calibration combines heads that each estimate the same retention time, and their spread differs per peptide, so
Calibration.disagreementnow exposes it and the interval divides the honest residuals by it before taking the per-bin quantile (the quantile is multiplied back at prediction time). Ratios are clipped to 0.2-5x the median reference peptide; when the spread carries no signal the ratios collapse to 1 and the method degenerates to the previous behaviour.Measured through the public API on the six included held-out setups (
per_peptide_widthTrue vs False), nominal 90 %:The gains are largest where the RT-only width was weakest (PXD080826 0.818 → 0.888, PXD081924 0.814 → 0.845); the cost is 10 % wider intervals and mild overcoverage. Edit distance to the reference was tested as the scale instead and rejected again: three times the width, coverage 0.977, no correlation with the error.
per_peptide_width=Falserestores the previous behaviour, which also stays the behaviour of single-head calibrations.Canonical keys
canonical_peptidoform_keyreproduces the corpus key format (peprec positions,U:<unimod id>, lowercased unmapped names, position-sorted, charge ignored) — verified against real corpus keys, including modified ones.Verification
tests/test_report.pyandtests/test_multihead_calibration.py(key format, interval coverage / adaptivity / thin-bin fallback on synthetic data, per-input widths and their coverage, an interval refusing to drop the score it was fitted with, head disagreement per input and its collapse when heads agree, index membership global and per-setup, capped distances, non-index directory refused, report end-to-end with and without index, per-peptide against per-bin widths, pre-fitted calibration refused, multi-head head listing).ruff check/formatclean on the new files.rapidfuzz(pure wheel).🤖 Generated with Claude Code