Skip to contents

Differentiate and expand a matrix exponential model with forward sensitivities

Usage

rxSensMatExp(
  model,
  calcSens,
  calcSens2 = NULL,
  calcSens3 = NULL,
  doConst = FALSE,
  env = NULL
)

Arguments

model

rxode2 model, text, or function

calcSens

A character vector of parameter names for which sensitivities should be calculated.

calcSens2

character vector (or NULL) requesting second-order (Hessian-path) matrix-exponential sensitivities rx__sens_<x>_BY_<p>_BY_<q>__, where p ranges over calcSens and q over calcSens2. Every element of calcSens2 must also appear in calcSens (its own first-order sensitivity compartment must already exist for the cross terms to reference). Mirrors rxode2(calcSens2=) for ordinary ODE models (?rxode2); unlike that path (which reuses the generic .rxSens()/rxExpandSens2_() machinery), matExp()/indLin() models cannot contain d/dt() lines, so the second-order sensitivity ODEs are expressed the same way as the first-order ones: as k_from_to micro-constant transfers into the rx__sens_<x>_BY_<p>_BY_<q>__ compartments. Ignored (with no compartments generated) for any state that is part of a linCmt() compartment – linCmt sensitivities come from Stan forward-AD, not this Jacobian-based expansion.

calcSens3

character vector (or NULL) requesting third-order sensitivities rx__sens_<x>_BY_<p>_BY_<q>_BY_<r>__, where p ranges over calcSens, q over calcSens2, and r over calcSens3. Requires calcSens2 to be supplied; every element of calcSens3 must also appear in calcSens2. Same linCmt exclusion as calcSens2.

doConst

Replace constants with values; By default this is FALSE.

env

A pre-loaded symengine environment (as returned by .rxLoadPrune()) to reuse instead of reloading model from scratch. When NULL (the default), the environment is built internally from model/doConst. Passing an existing env lets callers that have already loaded/pruned the model (e.g. to inject matrix-exponential d/dt() terms or other model modifications) feed that same environment in, so the sensitivity expansion sees those modifications instead of re-deriving them from the original model text.

Value

A character string representing the matrix exponential sensitivity-expanded model code

Author

Matthew L. Fidler & Antigravity