Skip to content

About

Bayesian MAP therapeutic drug monitoring and precision antimicrobial dosing engine in Python

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

DoseOptima

CI License: MIT Python: 3.10+ Pharmacometrics

DoseOptima is an advanced Bayesian Maximum A Posteriori (MAP) pharmacokinetic feedback and precision Therapeutic Drug Monitoring (TDM) dosing engine in Python. It integrates clinical patient covariates (renal CrCl, weight, age) with population pharmacokinetic priors and sparse drug serum observations to personalize narrow-therapeutic-index antimicrobial regimens (such as Vancomycin and Aminoglycosides) targeting precise $\text{AUC}_{24}/\text{MIC}$ and trough concentrations.


Pharmacometric & Mathematical Formalism

1. Two-Compartment Pharmacokinetic Model

For intravenous infusion at rate $R = \frac{\text{Dose}}{T_{\text{inf}}}$ into central volume $V_1$ with peripheral volume $V_2$, distribution clearance $Q$, and systemic clearance $\text{CL}$:

$$ \frac{dC_1}{dt} = \frac{R}{V_1} - (k_{10} + k_{12}) C_1 + k_{21} C_2 \frac{V_2}{V_1} $$

$$ \frac{dC_2}{dt} = k_{12} C_1 \frac{V_1}{V_2} - k_{21} C_2 $$

Where micro-rate constants are $k_{10} = \frac{\text{CL}}{V_1}$, $k_{12} = \frac{Q}{V_1}$, $k_{21} = \frac{Q}{V_2}$. The analytical solution during and post-infusion is governed by bi-exponential macro-constants $\alpha$ and $\beta$:

$$ \alpha, \beta = \frac{1}{2}\left( (k_{10} + k_{12} + k_{21}) \pm \sqrt{(k_{10} + k_{12} + k_{21})^2 - 4 k_{10} k_{21}} \right) $$

2. Population PK Prior & Renal Covariates

Creatinine clearance is estimated using the Cockcroft-Gault equation:

$$ \text{CrCl} = \frac{(140 - \text{Age}) \cdot \text{Weight}}{72 \cdot S_{\text{cr}}} \times (0.85 \text{ if female}) \quad [\text{mL/min}] $$

Log-normal population typical parameters:

$$ \text{CL}_{\text{pop}} = 0.048 \cdot \text{CrCl} + 0.5 \quad [\text{L/h}], \quad V_{\text{pop}} = 0.72 \cdot \text{Weight} \quad [\text{L}] $$

Individual parameters follow $\theta_{\text{ind}} = \theta_{\text{pop}} \cdot e^{\eta}$ with zero-mean inter-individual variability $\boldsymbol{\eta} \sim \mathcal{N}(0, \Omega)$.

3. Bayesian Maximum A Posteriori (MAP) Objective

Given measured serum concentrations $\mathbf{y} = [y_1, \dots, y_M]^T$ at times $\mathbf{t} = [t_1, \dots, t_M]^T$:

$$ \Phi_{\text{MAP}}(\boldsymbol{\eta}) = \sum_{j=1}^{M} \frac{\Big(y_j - \hat{C}(t_j, \boldsymbol{\theta}(\boldsymbol{\eta}))\Big)^2}{\sigma_j^2} + \boldsymbol{\eta}^T \Omega^{-1} \boldsymbol{\eta} $$

Where:

  • $\hat{C}(t_j, \boldsymbol{\theta})$: Superposed model predicted concentration.
  • $\sigma_j = \max(0.5, \sigma_{\text{prop}} \cdot \hat{C}_j)$: Combined proportional-additive residual unexplained error.
  • $\boldsymbol{\eta}^T \Omega^{-1} \boldsymbol{\eta} = \left(\frac{\eta_{\text{CL}}}{\omega_{\text{CL}}}\right)^2 + \left(\frac{\eta_V}{\omega_V}\right)^2$: Penalization from population prior.

The individual parameter vector $\hat{\boldsymbol{\eta}}{\text{MAP}}$ is found by minimizing $\Phi{\text{MAP}}$ using bounded L-BFGS-B optimization.

4. Precision Dosing Optimization

Targeting steady-state daily exposure $\text{AUC}_{24} \in [400, 600] \text{ (mg}\cdot\text{h)/L}$:

$$ \text{Dose}_{\text{ideal}} = \text{Target_AUC}_{24} \cdot \text{CL}_{\text{ind}} \cdot \left(\frac{\tau}{24}\right) $$

Regimens are evaluated across dosing intervals $\tau \in {8, 12, 24} \text{ h}$ with discrete clinical rounding (e.g. 250 mg steps) to ensure trough levels avoid nephrotoxicity ($C_{\text{trough}} \le 20 \text{ mg/L}$).


Clinical TDM Pipeline

flowchart TD
    subgraph Patient ["Patient Clinical Profile"]
        DEMO["Age, Weight, Sex, Serum Creatinine"] --> CRCL["Cockcroft-Gault CrCl"]
        CRCL --> POP["Population Prior (CL_pop, V_pop, Omega)"]
    end

    subgraph Sampling ["Therapeutic Monitoring"]
        HIST["Dosing History: Doses, Infusion Times"]
        LABS["Measured Serum Concentrations (Peak / Trough)"]
    end

    subgraph BayesianEngine ["Bayesian MAP Engine"]
        POP & HIST & LABS --> OBJ["MAP Objective Function: Residuals + Prior Penalty"]
        OBJ --> MIN["L-BFGS-B Numerical Optimization"]
        MIN --> IND["Individualized Parameters: CL_ind, V_ind, t_1/2"]
    end

    subgraph Dosing ["Adaptive Decision Support"]
        IND --> REG["Regimen Optimizer (AUC24 = 400 - 600)"]
        REG --> REPORT["Optimal Dose (mg), Interval tau (h), Predicted Peak/Trough"]
    end
Loading

Module Layout

src/dose_optima/
├── __init__.py      # Package re-exports and API definitions
├── models.py        # 1- and 2-compartment IV infusion PK models & superposition
├── population.py    # Cockcroft-Gault CrCl, Thomson-Goti Vancomycin priors, Omega matrix
├── bayesian.py      # Bayesian MAP objective function and L-BFGS-B optimizer
├── regimen.py       # Adaptive dosing regimen optimizer targeting AUC24 and trough
└── tdm.py           # Consolidated VancomycinTDM clinical report generator
tests/
├── test_pk_models.py      # Analytical peak, clearance, and superposition tests
├── test_bayesian_map.py   # Parameter recovery from synthetic noisy clinical samples
└── test_regimen.py        # Dosing optimization and end-to-end TDM execution

Quick Start & Testing

# Clone repository
git clone https://github.com/ZengLLQ/dose-optima.git
cd dose-optima

# Install in development mode
pip install -e .[dev]

# Run unit tests
pytest -v

License

This project is licensed under the MIT License.

About

Bayesian MAP therapeutic drug monitoring and precision antimicrobial dosing engine in Python

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages