module Sensitivity:sig..end
(Forward) Sensitivity analysis of ODEs with respect to their parameters.
Formalizes the dependency of a set of ODEs on $N_p$ parameters $p$ and calculates the sensitivities $s$ of the solution $y$ to a subset of $N_s \leq N_p$ of those parameters; $s(t) = \frac{\partial y(t)}{\partial p}$.
The solution sensitivity with respect to a single parameter $p_i$ satisfies the (forward) sensitivity equations $\dot{s}_i = \frac{\partial f}{\partial y}s_i + \frac{\partial f}{\partial p_i}$ and $s_i(t_0) = \frac{\partial y_0(p)}{\partial p_i}$, where $f$ and $y$ are from the $N$ equations of the original model.
This documented interface is structured as follows.
type 'd sensrhsfn_args = {
|
t : |
(* | The value of the independent variable. | *) |
|
y : |
(* | The vector of dependent-variable values $y(t)$. | *) |
|
y' : |
(* | The value of the right-hand side of the state equations $\dot{y} = f(t, y, p)$. | *) |
|
tmp : |
(* | Temporary storage vectors. | *) |
}
Common arguments to Cvodes.Sensitivity.sensrhsfn1 and Cvodes.Sensitivity.sensrhsfn_all.
type'dsensrhsfn_all ='d sensrhsfn_args -> 'd array -> 'd array -> unit
Sensitivity functions that calculate the right-hand sides of all sensitivity equations. They are passed the arguments:
args, the current values of state variables (see Cvodes.Sensitivity.sensrhsfn_args),s, an array of vectors holding the current values of sensitivity
variables, and,s', an array of vectors to be filled with the derivatives
of the sensitivity variables.Within the function, raising a Sundials.RecoverableFailure exception
indicates a recoverable error. Any other exception is treated as an
unrecoverable error.
type'dsensrhsfn1 =int -> 'd sensrhsfn_args -> 'd -> 'd -> unit
Sensitivity functions that calculate the right-hand side of a single sensitivity equation. They are passed the arguments:
i, the index of the sensitivity equation to compute,args, the current values of state variables
(see Cvodes.Sensitivity.sensrhsfn_args),s, a vector holding the current value of the ith
sensitivity variable, ands', a vector to be filled with the current value of the ith
sensitivity variable's derivative.Within the function, raising a Sundials.RecoverableFailure exception
indicates a recoverable error. Any other exception is treated as an
unrecoverable error.
type 'd sensrhsfn =
| |
AllAtOnce of |
(* | Calculate sensitivity functions all at once. The argument
| *) |
| |
OneByOne of |
(* | Calculate sensitivity functions one parameter at a time. The
argument
| *) |
Specify a sensitivity function.
type ('d, 'k) sens_method =
| |
Simultaneous of |
(* | Correct state and sensitivity variables at the same time. (CV_SIMULTANEOUS) | *) |
| |
Staggered of |
(* | The correction step for the sensitivity variables takes place at the same time for all sensitivity equations, but only after the correction of the state variables has converged and the state variables have passed the local error test. (CV_STAGGERED) | *) |
| |
Staggered1 of |
(* | All corrections are done sequentially, first for the state variables
and then for the sensitivity variables, one parameter at a time. If
the sensitivity variables are not included in the error control,
this approach is equivalent to | *) |
Specifies a sensitivity solution method. The method specification may optionally include the nonlinear solver to be used for corrections.
type sens_params = {
|
pvals : |
(* | An array of $N_p$ parameters $p$ in $f(t, y, p)$. If specified, this array is updated by the solver to pass perturbed parameter values to the original right-hand side and root functions. Those functions must (re-)read parameter values from this array on every invocation. | *) |
|
pbar : |
(* | An array of $N_s$ positive scaling factors. These are needed when estimating tolerances or using the internal difference quotient function. | *) |
|
plist : |
(* | An array of $N_s$ ($< N_p$) indices into | *) |
}
Specifies problem parameter information for sensitivity calculations. Which fields are required varies as follows:
pvals is mandatory if Cvodes.Sensitivity.init and/or
Cvodes.Sensitivity.Quadrature.init is not given a
user-defined callback. Otherwise, it is ignored.plist is optional if pvals is given. Otherwise, it is
ignored.pbar is always meaningful and optional.val no_sens_params : sens_paramsEmpty pvals, plist, and pbar fields.
type ('d, 'k) tolerance =
| |
SStolerances of |
(* |
| *) |
| |
SVtolerances of |
(* |
| *) |
| |
EEtolerances |
(* | Calculate the integration tolerances for sensitivities from those for state variables and the scaling factors in pbar. | *) |
Tolerances for calculating sensitivities.
val init : ('d, 'k) Cvode.session ->
('d, 'k) tolerance ->
('d, 'k) sens_method ->
?sens_params:sens_params ->
'd sensrhsfn -> ('d, 'k) Nvector.t array -> unitActivates the calculation of forward sensitivities. The call
init s tol sens_method ~sens_params fs ys0, has as arguments:
s, a session created with Cvode.init,tol, the tolerances desired,sens_method, the solution method,sens_params, the parameter information (see Cvodes.Sensitivity.sens_params),fs, the sensitivity function, and,ys0, initial values of the sensitivities for each parameter.If fs is not given, an internal difference quotient routine
is used. In that case, or if the internal difference quotient
routine will be specified in a subsequent call to
Cvodes.Sensitivity.Quadrature.init, then sens_params must be
given with pvals set to non-None.
val reinit : ('d, 'k) Cvode.session ->
('d, 'k) sens_method -> ('d, 'k) Nvector.t array -> unitReinitializes the forward sensitivity computation.
val toggle_off : ('d, 'k) Cvode.session -> unitDeactivates forward sensitivity calculations without deallocating
memory. Sensitivities can be reactivated with Cvodes.Sensitivity.reinit.
val turn_off : ('d, 'k) Cvode.session -> unitDeactivates forward sensitivity calculations with memory deallocation.
module Quadrature:sig..end
Support for quadrature sensitivity equations.
val get : ('d, 'k) Cvode.session -> ('d, 'k) Nvector.t array -> floatReturns the sensitivity solution vectors after a successful solver
step. The given vectors are filled with values calculated during
either Cvode.solve_normal or Cvode.solve_one_step and the
value of the independent variable is returned.
val get_dky : ('d, 'k) Cvode.session -> ('d, 'k) Nvector.t array -> float -> int -> unitReturns the interpolated solution or derivatives of the sensitivity solution vectors.
get_dky s dks t k computes the kth derivative at time t, i.e.,
$\frac{d^\mathtt{k}s(\mathtt{t})}{\mathit{dt}^\mathtt{k}}$,
and stores it in dks. The arguments must satisfy $t_n - h_u \leq
\mathtt{t} \leq t_n$—where $t_n$ denotes Cvode.get_current_time
and $h_u$ denotes Cvode.get_last_step,— and
$0 \leq \mathtt{k} \leq q_u$—where
$q_u$ denotes Cvode.get_last_order.
This function may only be called after a successful return from either
Cvode.solve_normal or Cvode.solve_one_step.
BadT t is not in the interval $[t_n - h_u, t_n]$.BadK k is not in the range 0, 1, ..., $q_u$.val get1 : ('d, 'k) Cvode.session -> ('d, 'k) Nvector.t -> int -> floatReturns a single sensitivity solution vector after a successful solver
step. The given vector is filled with values calculated for the ith
sensitivity vector during either Cvode.solve_normal or
Cvode.solve_one_step and the value of the independent variable is
returned.
BadIS The index i is not in the allowed range.val get_dky1 : ('d, 'k) Cvode.session -> ('d, 'k) Nvector.t -> float -> int -> int -> unitReturns the interpolated solution or derivatives of a single
sensitivity solution vector. get_dky s dks t k i is like Cvodes.Sensitivity.get_dky
but restricted to the ith sensitivity solution vector.
BadIS The index i is not in the allowed range.BadK k is not in the range 0, 1, ..., qlast.BadT t is not in the allowed range.val set_tolerances : ('d, 'k) Cvode.session -> ('d, 'k) tolerance -> unitSets the integration tolerances for sensitivities.
NB: Unlike the other set_tolerances functions in Cvodes, this
one does not call Cvodes.Sensitivity.set_err_con (which defaults to false).
val set_err_con : ('d, 'k) Cvode.session -> bool -> unitSets whether sensitivity variables are used in the error control
mechanism. The default is false.
type dq_method =
| |
DQCentered |
(* | (CV_CENTERED) | *) |
| |
DQForward |
(* | (CV_FORWARD) | *) |
A difference quotient strategy. See Cvodes.Sensitivity.set_dq_method.
val set_dq_method : ('d, 'k) Cvode.session -> dq_method -> float -> unitSets the difference quotient strategy when sensitivity equations
are computed internally by the solver rather than via callback. A
method and dqrhomax value must be given. The latter determines when
to switch between simultaneous or separate approximations of the two
terms in the sensitivity right-hand side.
val set_max_nonlin_iters : ('d, 'k) Cvode.session -> int -> unitSets the maximum number of nonlinear solver iterations for sensitivity variables permitted per step.
val get_num_rhs_evals : ('d, 'k) Cvode.session -> intReturns the number of calls to the sensitivity function.
val get_num_rhs_evals_sens : ('d, 'k) Cvode.session -> intReturns the number of calls to the right-hand side function due to the internal finite difference approximation of the sensitivity equations.
val get_num_err_test_fails : ('d, 'k) Cvode.session -> intReturns the number of local error test failures for the sensitivity variables that have occurred.
val get_num_lin_solv_setups : ('d, 'k) Cvode.session -> intReturns the number of calls made to the linear solver's setup function due to forward sensitivity calculations.
type sensitivity_stats = {
|
num_sens_evals : |
(* | Number of calls to the sensitivity function. | *) |
|
num_rhs_evals : |
(* | Number of calls to the right-hand side function to calculate sensitivities. | *) |
|
num_err_test_fails : |
(* | Number of local error test failures for sensitivity variables. | *) |
|
num_lin_solv_setups : |
(* | Number of setups calls to the linear solver for sensitivity calculations. | *) |
}
Summaries of sensitivity stats.
val get_stats : ('d, 'k) Cvode.session -> sensitivity_statsReturns the sensitivity-related statistics as a group.
val get_err_weights : ('d, 'k) Cvode.session -> ('d, 'k) Nvector.t array -> unitReturns the sensitivity error weights at the current time.
val get_num_nonlin_solv_iters : ('d, 'k) Cvode.session -> intReturns the cumulative number of nonlinear iterations performed for sensitivity calculations.
val get_num_nonlin_solv_conv_fails : ('d, 'k) Cvode.session -> intReturns the cumulative number of nonlinear convergence failures during sensitivity calculations.
val get_nonlin_solv_stats : ('d, 'k) Cvode.session -> int * intReturns both the numbers of nonlinear iterations performed nniters
and nonlinear convergence failures nncfails during sensitivity
calculations.
nniters, nncfails)val get_num_stgr_nonlin_solv_iters : ('d, 'k) Cvode.session -> Sundials.LintArray.t -> unitReturns the cumulative number of nonlinear (functional or Newton)
iterations for each sensitivity equation separately in the Staggered1
case.
val get_num_stgr_nonlin_solv_conv_fails : ('d, 'k) Cvode.session -> Sundials.LintArray.t -> unitReturns the cumulative number of nonlinear convergence failures
for each sensitivity equation separately in the Staggered1 case.
val get_current_state_sens : ('d, 'k) Cvodes.session -> 'd arrayReturns the current sensitivity state vector array. The vectors in the returned array provide direct access to the data within the integrator.
type 'd nonlin_system_data = {
|
tn : |
(* | Independent variable value $t_n$ . | *) |
|
yspred : |
(* | Predicted state vectors $\mathit{yS}_{i,\mathit{pred}}$ at $t_n$ for $i = 0,\ldots,N_s-1$ . This data must not be changed. | *) |
|
ysn : |
(* | State vectors $\mathit{yS}^n_i$ for $i = 0,\ldots,N_s-1$ . This data may not be current and may need to be filled. | *) |
|
gamma : |
(* | Current value of $\gamma$ . | *) |
|
rls1 : |
(* | A scaling factor used to compute $\tilde{a}_n = \mathtt{rls1}\cdot\mathtt{zns1}$ . | *) |
|
zns1 : |
(* | Vectors used to compute $\tilde{a}_n = \mathtt{rl1}\cdot\mathtt{zn1}$ . | *) |
}
Internal data required to construct the current nonlinear implicit system within a nonlinear solver.
val get_nonlin_system_data : ('d, 'k) Cvodes.session -> 'd nonlin_system_dataGives direct access to the internal data required to construct the
current nonlinear system within a nonlinear solver. This
function should be called inside the nonlinear system function.
The vectors ysn are provided as additional workspace and do not need
to be filled in. They are only current after an evaluation of the
nonlinear system function.
val compute_state : ('d, 'k) Cvodes.session ->
('d, 'k) Nvector.t array -> ('d, 'k) Nvector.t array -> unitComputes the current sensitivity vector for all sensitivities using
the stored prediction and the supplied correction vectors from the
nonlinear solver. The call
compute_state s i yscor ysn computes
$\mathit{yS}^n = \mathit{yS}_{\mathit{pred}}
+ \mathit{yS}_{\mathit{cor}}$ .
val compute_state1 : ('d, 'k) Cvodes.session ->
int -> ('d, 'k) Nvector.t -> ('d, 'k) Nvector.t -> unitComputes the current sensitivity vector for the sensitivity at the given
index using the stored prediction and the supplied correction vector
from the nonlinear solver. The call
compute_state s i yscor1 ysn1 computes
$\mathit{yS}^n_i = \mathit{yS}_{i,\mathit{pred}}
+ \mathit{yS}_{i,\mathit{cor}}$ .
val get_current_sens_solve_index : ('d, 'k) Cvodes.session -> intReturns the index of the current sensitivity solve when using the Staggered1 method.
exception SensNotInitialized
Sensitivity analysis was not initialized.
exception SensRhsFuncFailure
The sensitivity function failed in an unrecoverable manner.
exception FirstSensRhsFuncFailure
The sensitivity function had a recoverable error when first called.
exception RepeatedSensRhsFuncFailure
Too many convergence test failures, or unable to estimate the initial step size, due to repeated recoverable errors in the sensitivity function.
exception UnrecoverableSensRhsFuncFailure
The sensitivity function had a recoverable error, but no recovery was possible. This error can only occur after an error test failure at order one.
exception BadSensIdentifier
The index passed to identify a particular sensitivity is invalid.