pytyche.analysis.apply_calibration¶
- pytyche.analysis.apply_calibration(posterior, calibration)[source]¶
Return a new posterior of the same type with calibration attached.
Attach, don’t transform: the artifact’s corrections are query-time interval remappings, so the returned posterior shares every field of the original by reference (
dataclasses.replacewith onlyis_calibrated=Trueandcalibrationchanged) — no array is copied or re-derived, and the original posterior is untouched.The correction currently applies to intervals only: probabilities and expected losses are computed on the raw draws and are identical pre/post calibration; corrected CIs appear where the interval summaries are built (
analyze). K = 2 experiments only — per-contrast recalibration for K >= 3 is not yet implemented.- Parameters:
posterior (
TypeVar(AnyBCFResultT,HurdleBCFResult,ContinuousBCFResult,BinaryBCFResult)) – One of the three posterior result types, carrying observed data (raises otherwise).calibration (
Calibration) – SBC-fitted artifact whose fitted regime (metric,n_treatments) must match the posterior’s observed data.
- Return type:
TypeVar(AnyBCFResultT,HurdleBCFResult,ContinuousBCFResult,BinaryBCFResult)- Returns:
A new instance of the same result type with
is_calibrated=Trueandcalibrationattached by identity.- Raises:
TypeError – When calibration is
None— an artifact is required; an uncalibrated posterior is one you never applied a calibration to. (The fit entry points’calibration=kwarg only delegates here when non-None, so the default fit path never produces this error.)ValueError – When
posterior.observedisNone(no regime to check against), whencalibration.applies_to(observed)isFalse(the message names each mismatched dimension), or when a hurdle posterior’spoolingdiffers from the artifact’s (a correction fitted on one pooling mode’s miscalibration profile must not silently apply to the other).NotImplementedError – When the (regime-matching) posterior has K >= 3 variants — per-contrast recalibration is not yet shipped.