Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ API Reference
models/pyhealth.models.survival_mdn
models/pyhealth.models.TrajSurv
models/pyhealth.models.KnowRare
models/pyhealth.models.APRICOTM
models/pyhealth.models.ProtoECGNet
models/pyhealth.models.HeartLang
models/pyhealth.models.APN
Expand Down
54 changes: 54 additions & 0 deletions docs/api/models/pyhealth.models.APRICOTM.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
pyhealth.models.APRICOTM
========================

Overview
--------

APRICOT-M (Contreras et al., `Real-time prediction of intensive care unit
patient acuity and therapy requirements using state-space modelling
<https://doi.org/10.1038/s41467-025-62121-1>`_, Nature Communications 16,
7315, 2025) predicts, every 4 hours of an ICU stay, the patient's acuity in
the next 4 hours (discharge, stable, unstable or deceased), transitions
between stable and unstable, and the onset or stop of mechanical
ventilation, vasopressors and continuous renal replacement therapy.

The model reads the clinical events of the last 4 hours as (time, variable,
value) triplets, so sparse, irregular measurements need no resampling or
imputation. Time and value pass through position-wise layers, the variable
through an embedding; a stack of Mamba (selective state-space) blocks
contextualizes the events, top-k pooling over time and an MLP summarize
them, a static-feature embedding is added, and one head per label gives its
probability.

This is a clean reimplementation from the paper. The authors' code
(https://github.com/iheallab/apricotM) is GPL-3.0, so none of it was
copied; it was only read to confirm details. The Mamba blocks are
:class:`~pyhealth.models.SelectiveSSM`, the pure PyTorch block shared with
:class:`~pyhealth.models.ARMR`, run with its chunked parallel selective scan,
so the CUDA ``mamba_ssm`` package is not needed and the model runs on CPU.

Inputs and outputs
------------------

The input is a ``sequence_v2`` series with one token and one value per
event, such as the ``events`` field of
:class:`~pyhealth.tasks.ICUAcuityMIMIC4`, plus an optional static tensor
field. The label is a tensor of ``K`` binary labels (12 for that task, in the
order of ``ICUAcuityMIMIC4.LABELS``). ``mode`` is ``"multilabel"``; the model
returns ``logit``, ``y_prob`` and, with labels, ``loss`` (binary
cross-entropy) and ``y_true``. Pass ``pos_weight="balanced"`` with the
training split for the class weighting of the paper. The example notebook
``examples/apricotm_mimic4_acuity.ipynb`` trains it on MIMIC-IV.

API
---

.. autoclass:: pyhealth.models.APRICOTM
:members:
:show-inheritance:

.. autoclass:: pyhealth.models.SelectiveSSM
:members:
:show-inheritance:

.. autofunction:: pyhealth.models.selective_ssm.selective_scan
1 change: 1 addition & 0 deletions docs/api/tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,5 @@ Available Tasks
Cancer Survival Prediction (TCGA) <tasks/pyhealth.tasks.CancerSurvivalPrediction>
In-Hospital Survival (MIMIC-IV) <tasks/pyhealth.tasks.InHospitalSurvivalMIMIC4>
Rare-Condition ICU Mortality (KnowRare, MIMIC-IV) <tasks/pyhealth.tasks.KnowRareICUMortalityMIMIC4>
ICU Acuity and Therapies (MIMIC-IV) <tasks/pyhealth.tasks.ICUAcuityMIMIC4>
Cancer Mutation Burden (TCGA) <tasks/pyhealth.tasks.CancerMutationBurden>
14 changes: 14 additions & 0 deletions docs/api/tasks/pyhealth.tasks.ICUAcuityMIMIC4.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pyhealth.tasks.ICUAcuityMIMIC4
==============================

Real-time ICU acuity on MIMIC-IV, the setting of APRICOT-M (Contreras et al.,
Nature Communications 2025): every 4 hours, the events of the past 4 hours
predict the next 4 hours' acuity state (discharge, stable, unstable,
deceased), stable/unstable transitions and the stop or onset of mechanical
ventilation, vasopressors and CRRT. Pairs with
:class:`~pyhealth.models.APRICOTM`.

.. autoclass:: pyhealth.tasks.ICUAcuityMIMIC4
:members:
:undoc-members:
:show-inheritance:
401 changes: 401 additions & 0 deletions examples/apricotm_mimic4_acuity.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pyhealth/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
from .survival_mdn import SurvivalMDN as SurvivalMDN
from .trajsurv import TrajSurv as TrajSurv
from .knowrare import KnowRare as KnowRare
from .apricotm import APRICOTM as APRICOTM
from .selective_ssm import SelectiveSSM as SelectiveSSM
from .heartlang import (
HeartLang as HeartLang,
HeartLangBackbone as HeartLangBackbone,
Expand Down
Loading
Loading