Pharmacodynamic State Space Models for Disease Progression
MIT 6.874 · Lecture 23: EHRs, Disease Registries, and Neural PK-PD Modeling
Between 2008 and 2015, the share of U.S. non-federal acute-care hospitals adopting at least a Basic Electronic Health Record (EHR) rose from 9.4% to 83.8% (Slide 3, [01:47]; Henry et al., ONC Data Brief, May 2016), turning routine clinical care into longitudinal trajectories of labs, diagnoses, and prescriptions. Yet when modeling a rare cancer such as multiple myeloma (1,143 patients in the curated cohort; Slide 19, [29:18]), unconstrained neural state-space transitions (51K–77K parameters) overfit badly, whereas linear state space models (7K parameters) cannot track nonlinear biomarker curves.
MIT 6.874 Lecture 23 (Spring 2021; listed as Lecture 23, EHRs and data mining, on the course schedule, while the linked recording is titled Electronic health records - Lecture 22 on YouTube) features guest lecturer Rahul G. Krishnan (Microsoft Research New England; incoming University of Toronto & Vector Institute) presenting Neural Pharmacodynamic State Space Models (SSM_PK-PD) (Hussain, Krishnan, & Sontag, ICML 2021; Slide 6). The core design principle is a structured middle ground: keep a continuous latent Markov state space model, encode clinical lines of therapy with global and local clocks, and parameterize the latent transition with an attention-weighted bank of three pharmacodynamic mechanism functions (\(g_1, g_2, g_3\)).
Clinical registries and longitudinal challenges
While hospital-wide electronic health records (EHRs) pool heterogeneous patients across many diseases, foundation-curated disease registries track a single disease cohort across three aligned data modalities (Slide 5, [03:53]):
- Static baseline covariates (\(B \in \mathbb{R}^{16}\) in the myeloma cohort): Demographics and baseline genetic features (PCA projections of RNA/SNP profiles; Slide 19).
- Longitudinal treatments (\(\mathbf{U}\), \(U_t \in \mathbb{R}^{9}\) in the myeloma cohort): Prescribed drugs (such as
LenalidomideandBortezomibon Slide 5) paired with clinical lines of therapy (Line 1,Line 2,Line 3+), which switch when a regimen fails or becomes toxic ([05:21]). - Longitudinal clinical biomarkers (\(\mathbf{X}\), \(X_t \in \mathbb{R}^{16}\) in the myeloma cohort): Time-varying lab measurements such as
Serum IgG,serum albumin, and blood counts (Slides 5, 22).
Krishnan frames disease progression modeling as unsupervised conditional density estimation of longitudinal biomarkers given baseline covariates and observed treatments (Slide 7, [08:08]):
\[ \max_{\theta} \sum_{i=1}^{N} \log p_\theta(\mathbf{X}^i \mid \mathbf{U}^i, B^i). \]
Five properties of clinical data make this estimation problem difficult (Slide 8, [10:46]):
- High-dimensional nonlinear variation: Multiple interacting biomarkers evolve nonlinearly across visits.
- Missingness in \(\mathbf{X}\): Labs are skipped when clinicians do not order a test (
66%of biomarker entries missing in theML-MMRFcohort perHussain et al., ICML 2021, Sec. 5.1). - Left and right censorship: Patients enter registries at varying stages or withdraw consent mid-study (
[11:13]). - Treatment-induced dynamics (\(\mathbf{U}\)): Multi-drug cocktails and regimen switches drive abrupt shifts in biomarker trajectories.
- Small sample sizes: Rare diseases like multiple myeloma yield only \(\sim 10^3\) patients, amplifying overfitting.
During lecture Q&A ([16:29]–[19:56]), Krishnan highlights a critical subtlety regarding missing-not-at-random (MNAR) lab measurements: clinicians order labs when they suspect abnormality, and subsequent treatments \(\mathbf{U}_t\) depend on observed biomarkers \(\mathbf{X}_{\le t}\). Conditioning on the observed treatment schedule \(\mathbf{U}\) blocks the indirect treatment pathway discussed in Q&A ([18:05]), and under the diagonal Gaussian emission model (ICML 2021, Sec. 3), dropping missing coordinates yields the exact observed-data emission likelihood. However, the model specifies no explicit likelihood for the informative lab-ordering mechanism itself, and the variational inference network still conditions on complete sequences using imputation heuristics—Krishnan mentions both mean fill and forward fill in Q&A ([19:26]), while Hussain et al. (ICML 2021, Sec. 3) specifically reports using forward fill—leaving potential variational posterior bias as an open research question.
From RNNs and linear SSMs to Deep Markov Models
Two classical families sit at opposite ends of the bias–variance spectrum (Slides 9, 12, [12:32], [21:42]):
- Autoregressive RNNs: Factorize \(p(\mathbf{X} \mid \mathbf{U}, B) = \prod_{t=1}^{T} p(X_t \mid X_{<t}, U_{<t}, B)\) using deterministic hidden states \(h_t\). They capture arbitrary nonlinearities but overfit small clinical cohorts.
- Linear Gaussian State Space Models (
SSMs): Introduce a low-dimensional Markov latent state \(Z_t\) with linear Gaussian transitions. They generalize reliably on small data and handle missingness cleanly, but cannot represent curved relapse and treatment-response dynamics.
Deep Markov Models (DMMs) (Krishnan, Shalit, & Sontag, AAAI 2017; Slide 10, [14:16]) replace the linear transition and emission maps with neural networks while keeping the continuous latent Markov factorization (with initial-state prior \(p_\theta(Z_1 \mid B)\) and transitions starting at \(t=2\) in ICML 2021 Supplement Eq. 7, written concisely as \(\prod_{t=1}^T\) on Slide 10):
\[ p(\mathbf{X} \mid \mathbf{U}, B) = \int_Z \prod_{t=1}^{T} p_\theta(Z_t \mid Z_{t-1}, U_{t-1}, B)\, p_\theta(X_t \mid Z_t)\, dZ, \]
with diagonal Gaussian transition and emission densities:
\[ \begin{aligned} Z_t \mid Z_{t-1}, U_{t-1}, B &\sim \mathcal{N}\!\Big(\mu_\theta(Z_{t-1}, U_{t-1}, B),\; \Sigma_\theta^t(Z_{t-1}, U_{t-1}, B)\Big), \\ X_t \mid Z_t &\sim \mathcal{N}\!\Big(\kappa_\theta(Z_t),\; \Sigma_\theta^e(Z_t)\Big). \end{aligned} \]
Because marginalizing \(Z = \{Z_1, \dots, Z_T\}\) is intractable for nonlinear \(\mu_\theta\) and \(\kappa_\theta\), parameters \(\theta\) are trained via variational inference by minimizing the negative evidence lower bound (NELBO) using a structured bidirectional recurrent inference network ([15:50]; Hussain et al., ICML 2021, Sec. 3). Yet replacing a linear \(\mu_\theta\) with an unconstrained MLP (SSM_NL) still overfits when \(N \sim 100\text{–}1,000\) ([21:55]).
Domain-informed transition: clocks and neural PK-PD mechanisms
To curb overfitting without sacrificing nonlinear expressivity, SSM_PK-PD builds clinical and pharmacological structure directly into the transition mean \(\mu_\theta(Z_{t-1}, U_{t-1}, B)\) (Slides 13–18, [22:53]):
1. Global and local therapy clocks (Slide 14)
A neural transition function must know both total time on therapy and how long the patient has remained on the current regimen before or after progression. SSM_PK-PD augments the intervention vector \(U_t\) with scalar clocks (Slide 14, [23:40]; exact indexing in Hussain et al., ICML 2021, Sec. 4.4):
- Global clock (
gc_t = t): Time elapsed since the start of therapy (t = 0). - Local clock (
lc_t = t - p_t): Time elapsed since the most recent change in line of therapy (\(p_t\)), resetting to0at every progression transition. (WhileICMLSec. 4.4 introduces both clocks in the general formulation,ICMLSec. 5.1 specifies that theML-MMRFU_t \in \mathbb{R}^9vector uses1local clock +3-dimensional one-hot line of therapy +5binary drug indicators,1 + 3 + 5 = 9.)
2. Three neural intervention effect functions (Slide 17)
Traditional pharmacokinetic–pharmacodynamic (PK-PD) differential equations model a single biomarker under a single drug (Slide 16, [26:20]). Because myeloma regimens combine multiple drugs across high-dimensional latent states, SSM_PK-PD defines three parallel neural mechanism functions \(g_1, g_2, g_3\) operating elementwise over latent representations \(Z_{t-1} \in \mathbb{R}^Q\) (Slide 17, [27:51]):
Baseline-conditional variation (\(g_1\)): Bounded modulation of latent state by drugs and baseline genetics/demographics: \[ g_1(Z_{t-1}, U_{t-1}, B) = Z_{t-1} \odot \tanh\!\big(b_{\text{lin}} + W_{\text{lin}}[U_{t-1}, B]\big). \]
Neural Log-Cell Kill (\(g_2\), inspired by
West & Newton, 2017): Models sharp initial tumor-burden suppression followed by slow gradual relapse as the local clock \(\text{lc}_{t-1}\) increases: \[ g_2(Z_{t-1}, U_{t-1}, B) = Z_{t-1} \odot \Big(1 - \rho \log(Z_{t-1}^2) - \beta \exp(-\delta \cdot \text{lc}_{t-1})\Big), \] where \(\beta = \tanh(W_{\text{lc}} U_{t-1} + b_{\text{lc}})\) (Hussain et al., ICML 2021, Eq. 5). At a line transition, the local clock \(\text{lc}_{t-1}\) resets to0(while learned \(\beta(U_{t-1})\) also shifts with the new regimen without a prescribed reset value). Note that although \(\log(z^2)\) diverges as \(z \to 0\), the product \(z \log(z^2) \to 0\) (assuming non-zero or stabilized coordinates when computing gradients).Neural Treatment Exponential (\(g_3\), inspired by
Xu et al., 2016): Captures rapid treatment onset up to local duration \(\gamma_l\) and regression toward baseline for \(\text{lc}_{t-1} \ge \gamma_l\): \[ g_3(Z_{t-1}, U_{t-1}, B) = \begin{cases} b_0 + \dfrac{\alpha_{1,t-1}}{1 + \exp\!\big(-\alpha_{2,t-1}(\text{lc}_{t-1} - \frac{\gamma_l}{2})\big)}, & 0 \le \text{lc}_{t-1} < \gamma_l, \\[10pt] b_l + \dfrac{\alpha_{0,t-1}}{1 + \exp\!\big(\alpha_{3,t-1}(\text{lc}_{t-1} - \frac{3\gamma_l}{2})\big)}, & \text{lc}_{t-1} \ge \gamma_l. \end{cases} \] Here \(\alpha_{1,t-1} = W_d[Z_{t-1}, U_{t-1}, B] + b_d\) sets response direction/magnitude, while \([\alpha_2, \alpha_3, \gamma_l]_{t-1} = \sigma(W_e \cdot U_{t-1,\text{line}} + b_e)\) maps the 3-dimensional one-hot line-of-therapy block in \(U_{t-1}\) (written shorthand asU_{t-1}[0]with \(W_e \in \mathbb{R}^{3 \times 3}\) inICML 2021, Sec. 4.5) to steepness and duration.Continuity check on
ICML 2021, Eq. 6: The paper prints \(\alpha_{0,t-1} = (\alpha_{1,t-1} + 2b_0 - b_l) / (1 + \exp(-\alpha_{3,t-1}\gamma_l/2))\). Writing \(D_j = 1 + \exp(-\alpha_{j,t-1}\gamma_l/2)\) for \(j \in \{2, 3\}\), matching the left limit \(b_0 + \alpha_{1,t-1}/D_2\) to the right value \(b_l + \alpha_{0,t-1}/D_3\) at \(\text{lc}_{t-1} = \gamma_l\) independently requires: \[ \alpha_{0,t-1} = D_3\!\left(b_0 - b_l + \frac{\alpha_{1,t-1}}{D_2}\right). \] Because the paper’s printed formula divides by \(D_3\) rather than multiplying by it, it produces a small step discontinuity at \(\text{lc}_{t-1} = \gamma_l\) (for example,0.9734down to0.8406in our constructed check below, where \(\alpha_{0,\text{printed}} = 0.9168\) vs. \(\alpha_{0,\text{continuous}} = 1.0617\)).
3. Soft attention over mechanisms (Slide 18)
Rather than committing a patient to a single fixed mechanism, PK-PD^Neural computes soft-attention weights over \(\{g_1, g_2, g_3\}\) using the patient’s latent state \(Z_{t-1}\) as the query and the mechanism outputs as keys/values (Slide 18, [28:08]; ICML 2021, Eq. 3). Writing row vectors \(Z_{t-1} \in \mathbb{R}^{1 \times Q}\) (so \(q = Z_{t-1} W_q \in \mathbb{R}^{1 \times Q}\), transposed to \(Q \times 1\) for elementwise broadcasting across the \(d = 3\) columns of \(\tilde{K}, \tilde{V} \in \mathbb{R}^{Q \times 3}\)):
\[ \tilde{K} = [g_1; g_2; g_3]^\top W_k, \qquad \tilde{V} = [g_1; g_2; g_3]^\top W_v, \]
\[ \text{Effect}(Z_{t-1}, U_{t-1}, B) = \left(\sum_{i=1}^{3} \operatorname{softmax}\!\left(\frac{q \odot \tilde{K}}{\sqrt{Q}}\right)_i \odot \tilde{V}_i\right) W_o, \]
where \(W_q, W_k, W_v, W_o \in \mathbb{R}^{Q \times Q}\) and \(\operatorname{softmax}\) runs across the three mechanism columns \(i \in \{1, 2, 3\}\) for each latent coordinate (ICML 2021, Sec. 4.3, noting the paper’s printed shorthand [g_1; ...; g_d]^\top writes the resulting \(\tilde{K}, \tilde{V}\) as \(Q \times d\) matrices and sets \(\mu_\theta\) directly to Eq. 3, whereas Slide 18 and ICML Fig. 2 draw an additional residual skip \(+ Z_{t-1}\)).
Constructed 1D numerical check (not cohort data)
To verify how the three mechanism terms and Slide 18’s residual update combine numerically, take a constructed 1D scalar example (\(Q = 1\)) with \(Z_{t-1} = 1.5\), \(\text{lc}_{t-1} = 2.0\), \(b_{\text{lin}} + W_{\text{lin}}[U_{t-1}, B] = 0.25\), and freely chosen illustrative Eq. 5–6 parameters (not outputs of an unscaled logistic \(\sigma(\cdot) \in (0, 1)\)):
- Mechanism \(g_1\): \(1.5 \cdot \tanh(0.25) = 1.5 \times 0.2449 = 0.3674\).
- Mechanism \(g_2\) (setting \(\rho = 0.15, \beta = 0.80, \delta = 0.45\)): \(1 - 0.15\ln(1.5^2) - 0.80 e^{-0.90} = 1 - 0.1216 - 0.3253 = 0.5531\), so \(g_2 = 1.5 \times 0.5531 = 0.8297\).
- Mechanism \(g_3\) (setting \(b_0 = b_l = 0, \alpha_1 = 1.0, \alpha_2 = 1.8, \alpha_3 = 1.2, \gamma_l = 4.0\), so \(\text{lc}_{t-1} = 2.0 = \gamma_l/2\)): \(g_3 = 1.0 / (1 + e^0) = 0.5000\).
- Manually weighted Slide 18 combination (
0.4, 0.3, 0.3, identity \(W_v, W_o\)): Supplying Slide 18’s illustrative attention weights(0.4, 0.3, 0.3)directly—noting that for \(Q = 1\) with linear \(q, \tilde{K}\) projections, distinct \(g_2 \ne g_3\) could only receive equal weights via zero key projection (\(s_i = 0 \implies 1/3\) for all three)—gives \(\text{Effect} = 0.4(0.3674) + 0.3(0.8297) + 0.3(0.5000) = 0.5458\), and adding Slide 18’s residual \(Z_{t-1}\) yields \(\mu_\theta = 1.5 + 0.5458 = 2.0458\).
Generalization on synthetic and multiple myeloma data
Lecture 23 evaluates SSM_PK-PD against four state-space baselines (Slide 20, [29:47]):
SSM_Linear(Perotte et al., 2015): Linear transition function \(\mu_\theta(Z_{t-1}, U_{t-1}, B)\).SSM_NL(Krishnan et al., 2017): Nonlinear 2-layer MLP transition (DMM).SSM_MOE(Jacobs et al., 1991;Jordan & Jacobs, 1994): Replaces \(g_1, g_2, g_3\) with three unconstrained MLPs in a Mixture-of-Experts transition, isolating the benefit of pharmacodynamic functional forms over generic multi-branch capacity.SSM_Attn.Hist.(Alaa & van der Schaar, 2019): State-space transition attending over concatenated history.
Sample complexity on synthetic trajectories (Slide 21, top)
Slide 21 labels the top benchmark Semi-synthetic data (Hussain et al., ICML 2021 Sec. 5.1 & Table 1 refer to the exact same benchmark numbers as Synthetic data, evaluated over five held-out sets of 50,000 samples), comparing 100 vs. 1,000 training samples on test NELBO (nats, \(\downarrow\) lower is better):
| Training Set Size | SSM_Linear |
SSM_NL |
SSM_MOE |
SSM_Attn.Hist. |
SSM_PK-PD |
SSM_PK-PD (w/o TExp) |
|---|---|---|---|---|---|---|
100 |
58.57 ± 0.06 |
69.04 ± 0.11 |
60.98 ± 0.04 |
76.94 ± 0.02 |
55.34 ± 0.03 |
58.39 ± 0.05 |
1,000 |
53.84 ± 0.02 |
44.75 ± 0.02 |
51.57 ± 0.03 |
73.80 ± 0.03 |
39.84 ± 0.02 |
38.93 ± 0.01 |
At N = 100, the unconstrained SSM_NL (69.04) overfits severely—performing 10.47 nats worse than SSM_Linear (58.57) and 13.70 nats worse than SSM_PK-PD (55.34). At N = 1,000, SSM_NL recovers to 44.75, yet still trails SSM_PK-PD (39.84) and SSM_PK-PD (w/o TExp) (38.93, 0.91 nats lower than full SSM_PK-PD at \(N = 1,000\); Slide 21).
Multiple myeloma cohort (ML-MMRF, Slide 21, bottom)
On the real 1,143-patient multiple myeloma dataset (~75/25 split yielding 282 held-out test patients in Hussain et al., ICML 2021, Table 1), SSM_PK-PD (23K parameters) achieves 61.54 nats test NELBO, beating every baseline in both aggregate likelihood and per-patient pairwise comparisons:
Comparison (SSM_PK-PD vs. Baseline) |
Pairwise Fraction Lower NELBO (Mean (SD), \(\uparrow\)) | Patients with \(>10\)-nat NLL Gain (out of 282) |
Test NELBO (\(\downarrow\), nats) | Model Parameters |
|---|---|---|---|---|
vs. SSM_Linear |
0.796 (0.400) |
PK-PD: 158, LIN: 6 |
61.54 vs. 74.22 |
23K vs. 7K |
vs. SSM_NL |
0.760 (0.426) |
PK-PD: 130, NL: 12 |
61.54 vs. 79.10 |
23K vs. 51K |
vs. SSM_MOE |
0.714 (0.450) |
PK-PD: 94, MOE: 8 |
61.54 vs. 73.44 |
23K vs. 77K |
vs. SSM_Attn.Hist. |
0.934 (0.247) |
PK-PD: 272, Attn.Hist.: 0 |
61.54 vs. 105.04 |
23K vs. 17K |
Parameter count alone does not explain these gains ([32:18]): SSM_NL (51K parameters, 2.2x larger) and SSM_MOE (77K parameters, 3.3x larger) have substantially more capacity than SSM_PK-PD (23K), yet generalize worse by 17.56 and 11.90 nats respectively. During Q&A ([40:05]–[41:38]), Krishnan notes that replicating the mechanism bank (6, 9, or 12 copies instead of 3) first plateaus and then degrades generalization, whereas trimming from 3 down to 2 mechanisms causes a modest drop while still beating SSM_Linear.
Biomarker ablations, latent structure, and forward forecasting
Slides 22–26 (pp. 22–26, [33:03]–[36:04]) dissect where SSM_PK-PD’s gains originate:
- Per-biomarker NLL (
Slide 22): Importance-sampled negative log-likelihoods across all16clinical biomarkers show visibly larger median gaps on markers such asserum lambdaandserum albumin, while Krishnan ([33:44]) notes that clinical collaborators specifically highlighted howSSM_PK-PDcaptures the nonlinear dynamics ofserum igg. - Local-clock ablation (
Slide 23): On a two-biomarker synthetic patient trajectory (ICML 2021, Fig. 3) where treatment begins near \(t = 9\text{–}10\),PK-PDtracks both the drop inBiomarker 1and rise inBiomarker 2, whereasLinearandPK-PD w/o lc(without the local clock) diverge. - Latent-space trajectories (
Slide 24,[34:08]): Visualizing learned latent states across \(T = 0, 4, 9, 14, 18, 19, 24, 29\) (line1,line2,line3plus,noRx) shows two distinct clusters separating across \(T = 9\text{–}24\) before converging into one cluster by \(T = 29\) ([34:57];ICMLSec. 5.5.3 attributes the two clusters to treated vs. untreated patients). - Forecasting from baseline biomarkers vs. 15 months (
Slides 25–26,[35:05]): Conditioning on baseline biomarkers ([35:18]) and treatment plan, forward samples fromSSM_PK-PDtrack nonlinear markers such asserum lambdamore closely thanSSM_Linear, and conditioning on15months of observed visits further anchors future biomarker trajectories.
Takeaways and open clinical directions
Krishnan closes (Slides 28–31, [36:05]–[39:58]) with two broader lessons for clinical machine learning:
- Encode domain structure into generative transitions: When clinical cohorts are small (
~10^3patients) and sparsely observed, embedding pharmacodynamic functional forms (\(g_1, g_2, g_3\)) and clinical protocol clocks (gc,lc) prevents overfitting far more effectively than adding raw neural parameters. - From prediction to decision support: Ongoing directions include independent validation on larger Veterans Affairs (
VA) cohorts, multimodal fusion (genetics + labs + imaging + clinical notes), counterfactual trajectory estimation under alternative treatment schedules, and model-based reinforcement learning.
Lecture and sources
- MIT 6.874 Spring 2021 official schedule (Lecture 23, EHRs and data mining) and official lecture recording (
41:55; titled Electronic health records - Lecture 22 on YouTube; verified with timestamped captions). - Rahul G. Krishnan, Machine Learning for Healthcare: Disease progression modeling (32 pp.), especially Slides 3–26 and 28–31.
- Primary paper cited in Lecture 23 for exact equation notation (
gc_t,lc_t, \(b_{\text{lin}}, W_{\text{lin}}, W_q, W_k, W_v, W_o\),ML-MMRF282test patients,66%missingness, and forward-fill imputation): Zeshan Hussain, Rahul G. Krishnan, and David Sontag, Neural Pharmacodynamic State Space Modeling (ICML 2021, PMLR 139). - Original explanatory figures and verified arithmetic: create_figures.py and manifest.json. Constructed worked checks (1D scalar
PK-PDtransition check and the18-step clock / \(g_2/Z, g_3\) curve illustration) are explicitly labeled and separated from lecture-reported data.


