Repository navigation
Conversation
Test CoverageTotal: 74.27% (20594 / 27729 lines)
|
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.
Adds EnbPI from Xu and Xie, "Conformal prediction interval for dynamic time-series", ICML 2021, as the first time series conformal method in
pyhealth.calib. It builds prediction intervals for time series regression and updates them online as labels are revealed, without assuming exchangeability. ACI and AgACI will follow on the same interface.Changes
pyhealth.calib.predictionset.EnbPItrains a bootstrap ensemble from amodel_fnfactory, fills a sliding window with out-of-bag absolute residuals, and returns the center plus or minus the conformal(1 - alpha)quantile of the window.reset()restores the calibration window, andstate_dict()carries the full calibration state for checkpoints.IntervalPredictorinpyhealth/calib/base_classes.pydeclarescalibrate,forwardandupdate, likeSetPredictor.pyhealth/metrics/prediction_interval.pyaddsmiscoverage_pi,interval_widthandrolling_miscoverage_pi@W, available throughregression_metrics_fn(..., y_lower=..., y_upper=...).examples/conformal_timeseries/enbpi_synthetic.pyand tests.Key decisions
phiover the out-of-bag predictions, as in the paper's experiments and MAPIE.center="quantile"reproduces Algorithm 1 line 12, whose(1 - alpha)quantile biases the point prediction upward.model_fnfactory, following MAPIE's clone-per-bootstrap convention, so the bootstrap bags always match the models. No calibrator in PyHealth trained models before, so there was no in-repo convention.IntervalPredictorfixes only the public interface. Each method implements its own online loop, because ACI and AgACI update in ways a shared loop would constrain.forwardis stateless and works insideTrainer.inference, andupdateslides the window.predict_sequentialis a convenience method for evaluation that runs the paper's loop over a labeled test stream.calibratecall trains a new ensemble on the data passed in, like other calibrators recompute from their data.reset()restores the calibration window without retraining, so evaluations can be rerun from the same start.state_dict()saves the whole predictor, including the bootstrap indices and the residual window, through PyTorch's extra state hooks, soload_state_dictandTrainercheckpoints restore calibrated inference and resume online updates. The hooks sit in a separate checkpointing section at the end ofEnbPI, apart from the algorithm.calibrateraises when no training point has an out-of-bag model, since every interval would be NaN. The paper does not address this case, and with the recommendedB = 20to30it essentially never happens.regressionmode with one stream in time order and absolute residuals, as in the ICML paper. Many series at once (timeseries_regression) and signed residuals are follow-ups.