Expand calibration into a first-class subsystem - #16
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Makes calibration recordable, replayable and inspectable, and adds the method the direct transformation cannot express.
calibration.pybecomes a package (_direct,_spec,_diagnostics).setqca.calibrationand every existing import keep working — 478 tests passed unchanged through the move.Specifications
Four methods:
direct,crisp,indirectandidentity. Specs are validated when written, not when they eventually meet data, so badly ordered anchors raise at the point the mistake is made. Thenotesurvives serialisation, because the reason for a calibration is part of it.Indirect calibration takes an explicit monotone mapping, for shapes the three-anchor form cannot express — a plateau, a step, an asymmetric ramp. Non-monotone mappings are rejected: a calibration that reverses direction is a different concept, not a calibration.
Diagnostics
Five ways a calibration can be arithmetically valid and analytically useless:
Reported, not enforced.
diagnose_framegives one row per condition.Quantile helpers that refuse to be a calibration
suggest_anchorsreports quantiles with the caveat attached to the returned object, and nothing in the package will apply them for you. A set defined by its own distribution cannot support a claim about set membership: if the crossover is the sample median, "more in than out" means "above average for these cases", which changes when you add a case and says nothing about the concept.478 tests at 100% coverage; mypy strict and docs build clean.
Summary by cubic
Elevates calibration to a first-class subsystem with reproducible specs, diagnostics, and a new indirect method, while keeping existing imports working. Adds JSON-serializable
CalibrationSpecand acalibrateentrypoint that returns values, spec, and diagnostics together.New Features
CalibrationSpecfordirect,crisp,indirect, andidentity; validated on write;to_json/from_json; keepsnote.calibrate(values, spec)returnsCalibrationResultwithvalues,spec, anddiagnostics;to_frame()helper.diagnose_calibrationanddiagnose_frameflag crossover ties, pile-up, extreme compression, low variance, and never present/absent.suggest_anchorsreturnsAnchorSuggestionwith a caveat; helpers do not apply anchors.Refactors
calibration.pyintosetqca.calibrationpackage (_direct,_spec,_diagnostics) and re-export new APIs from the package root.calibrate_direct/calibrate_crispremain intact; no migration required.Written for commit d0be0e9. Summary will update on new commits.