Repository navigation
Update motionage to current PyHealth, fix MotionAge loss API, speed up tests - #1581
Closed
plabradorjr wants to merge 25 commits into
Closed
plabradorjr wants to merge 25 commits into
plabradorjr wants to merge 25 commits into
Conversation
Plant a second day-1 pattern on the died_within_5y participant: 120 zero minutes (16:30-18:30) with one lone spike of 50 at 17:30, bounded by counts of 150 so the authors' rule splits at the block edges. Both the published Choi rule and the authors' rule flag the whole block, giving the default rule a positive control on generated data. Tests: both detectors must flag the block (and not its edges), the default authors build keeps the adjacent-spike block worn and marks the bounded block as non-wear, and wear_truth consistency allows the new spike.
Adds API pages for NHANESDataset, NHANESMortalityPrediction and MotionAge/MotionAgeMapping, lists them in the datasets, tasks and models indexes, and exports the classes from the package __init__ files.
pyhealth/metrics/motionage.py: average window probabilities per participant, collect pass-through age/sex, age acceleration, the paper's C-index C(M, X) on the 5-year label, and train-fitted logistic AUROC for feature sets, following the authors' evaluation code. examples/nhanes_mortality_prediction_motionage.py: synthetic NHANES -> NHANESDataset -> NHANESMortalityPrediction -> MotionAge with Trainer -> participant risk -> MotionAgeMapping -> C-index, AUROC and optional Harrell's C, with --min-age and --out. Runs in about 2 minutes.
Add docs and imports for NHANES dataset, task and MotionAge
PatientKFold (a Split defined in the example) stratifies test folds on the task's 5-year label and takes a stratified 25% of the other folds as validation, following the authors' data/partitioning.py. --n-folds k > 1 runs each fold and reports the mean and SD across folds; the default 1 keeps the single 60/20/20 split.
died_within_5y now uses NHANESMortalityPrediction's rule: death with PERMTH_INT (months from interview) <= 60; survivors followed under 60 months are unknown. On the real NHANES 2003-2006 cohort PERMTH_INT gives the paper's 555 deaths in 8,979 participants; PERMTH_EXM gives 564. The interview-only edge case is now labeled, and a new test checks the generator against the task's rule.
…ample --no-wear-aware, --seq-len and --hidden-dim pass through to the task and model; --patience enables early stopping in Trainer.train (default None keeps every epoch). The AUROC table gains a "covariates" row: logistic regression on age, sex, BMI, waist, systolic and diastolic blood pressure and one-hot income, read from the dataset events, with train-fitted median imputation, missing flags and standardization.
--optimizer {adam,adamw}, --weight-decay and --max-grad-norm pass through
to Trainer.train. The defaults (Adam, 0.0, None) keep earlier runs
reproducible; the authors' paper configs use AdamW, weight decay 3e-4 and
gradient clipping at 1.0. The docstring notes the authors' ReduceLROnPlateau
schedule, which Trainer does not offer.
Mean and SD over 5 folds (test participants aged 40+) for the main run with Adam and with the authors' AdamW settings, the three ablations (no wear mask, 1-day window, hidden size 32) and the paper's Table 1, with notes on the cohort match and the remaining training differences.
format_run_time rounds to whole seconds before splitting, so 6359.6 s prints "106 min 0 s" instead of "105 min 60 s". Doctests cover the edge.
MotionAge evaluation and e2e example
Brings the team branch up to date with upstream PyHealth (135 commits, through 4b888c3) before opening the PR. Four conflicts, all one-line additions on both sides; kept upstream's lines and ours: docs/api/metrics.rst, pyhealth/{datasets,models,tasks}/__init__.py.
Upstream sunlabuiuc#1389 moved loss and activation from BaseModel onto the label processor and removed get_loss_function() and prepare_y_prob(), so MotionAge.forward failed after the merge. Use self.label_processor.loss() and .activation(), as the other models now do. Binary labels keep the same loss (BCE with logits) and sigmoid.
TestEndToEnd built the whole synthetic pipeline inside its test, so the test took 1.5-1.7 s, mostly PyHealth starting its Dask cluster. Build it once in setUpClass, as test_nhanes.py does; the test itself now only checks the participant table. In test_motionage.py, run one warm-up forward pass in setUpClass: on a cold start the first forward pass took up to 1.4 s inside whichever test ran first.
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.
opened by mistake