Yi Zhang, William R. Gillespie
Metrum Research Group
Objectives: Stan is a widely used, open-source, probabilistic programming language and Bayesian inference engine [1]. It provides a general model specification lan- guage and uses HMC simulation for fully Bayesian data analysis. Torsten is a library of Stan functions that simplifies implementation of pharmacometric (PMX) models and extends the range of models that may be implemented [2]. The objective of this presentation is to summarize and demonstrate the recent developments of Torsten.
Methods: Mainly implmented in C++, Torsten’s PMX functions are collected in a submodule to Stan Math library. It is licensed under BSD-3 and publically hosted on GitHub. For Windows, Linux, and MacOS platforms it provides binaries of Stan-to-C++ transpilers that converts Stan model script to C++ code, based on Stan’s stanc3 project. Torsten’s functions are tested on all three platforms.
Torsten’s parallel capabilities are based on message-passing interface (MPI), and are tested using two of the main MPI implementations OpenMPI and MPICH.
Results: Torsten supports the following PMX models
-
One-compartment model based on analytical solution
-
Two-compartment model based on analytical solution
-
One-compartment PK coupled with effect-compartment model based on analytical solution
-
Two-compartment PK coupled with effect-compartment model based on analytical solution
-
Linear ODE model based on matrix exponential solution
-
General ODE model based on numerical solution
-
Coupled model based on analytical PK solution and numerical PD solution.
-
ODE-based population models based on within-chain parallel solution.
Improved events handling
Torsten support NM-TRAN compatible event specification arguments (TIME, AMT, RATE, II, EVID, CMT, ADDL, SS). Among them all the real[] ar- guments are allowed to be parameters in a Stan model. In addition, ODE model parameters theta, bioavailability fraction F, and lag time tlag can be event/time dependent. F and tlag are also optional.
New coupled PK-effect-compartment solvers
The latest PMX additions are PKPD solvers that analytically solve one- & two-compartment PK model coupled with an effect-compartment. They are 20%-30% more efficient than using matrix exponetial.
New ODE integration function
To Stan upstream we have contributed a new explicit Runge-Kutta integra- tor. The new Cash-Karp method is shown to be more performant for ODEs with mildly stiffness and near discontinuity.
Improved steady state solution
General ODE model now support steady state dosing events, and allows infusion duration to be greater than II. The new implementation of the steady state solution is based on KINSOL, a quasi-Newton and modified- Newton nonlinear solver from SUNDIALS suite. User can also access some convergence controls of the nonlinear solver.
Improved workflow in R
The latest Torsten moves from RStan to cmdstanr as its new R interface. The new R interface is a light-weight wrapper of cmdstan, Stan’s com- mand line interface. Here we demonstrate the workflow using a simple PKPD model that combines one-compartment PK model and a sigmoid Emax model. The Emax model depends on an effective compartment that is coupled to the central compartment of the PK model. The linear ODE system of one-compartment & effective compartment is solved by the newly added function pmx_solve_onecpt_effcpt.
Experimental feature of parallel warmup
Torsten provides an experiment feature of cross-chain warmup scheme that performs dynamic warmup adaptation by chain aggregation [4]: during warmup, the joint log posterior sampled from parallel chains are collected and used to calculate potential scale reduction coefficients (Rhat) and effec- tive sample sizes (ESS) [3]. When they meet predetermined target values warmup is terminated to avoid unncessary computation. The algorithm relieves user from trial-and-error practice to determine the sufficiency of warmup iterations. It also reduce wall-time as the number of both the warmup iterations and and sampling iterations can be reduced in order to achieve the number of effective sample size comparable to standard Stan practices where one runs 4 chains with 1000-iterations in warmup and sam- pling, respectively.
Conclusions: Torsten functions prove to be valuable addons to Stan for PMX modeling within Bayesian framework. It also allows us to explore experimental fea- tures and algorithms. Adopting a light-weight R interface enables Torsten to support the major OS platforms, and simplifies installation process.
References:
[1] B. Carpenter, A. Gelman, M. Hoffman, D. Lee, B. Goodrich, M. Be- tancourt, M. Brubaker, J. Guo, P. Li, , and A. Riddell. Stan: A probabilistic programming language. Journal of Statistical Software, 76(1):132, 2017.
[2] https://github.com/metrumresearchgroup/Torsten
[3] A. Vehtari, A. Gelman, D. Simpson, B. Carpenter, and P. Bürkner. Rank-normalization, folding, and localization: An improved Rhat for assessing convergence of MCMC
[4] Y. Zhang, W.R. Gillespie, B. Bales, A. Vehtari. Speed up population Bayesian inference by combining cross-chain warmup and within-chain parallelization.
Reference: PAGE 29 (2021) Abstr 9804 [www.page-meeting.org/?abstract=9804]
Poster: Methodology - Estimation Methods