Skip to contents

StochasticCompositeAlgorithm(algs, choice_function) steps with one of the SDE algorithms in the list algs, chosen before every step by choice_function. The choice is either an AutoSwitch() object (the switch between its nonstiff and stiff methods) or a function of one argument returning the index of the method; the argument is a list with the integrator, its t, u, p, the step count iter, the step size dt and the stiffness estimate eigen_est.

Usage

StochasticCompositeAlgorithm(algs, choice_function)

AutoAlgSwitch(
  nonstiffalg,
  stiffalg,
  maxstiffstep = 10L,
  maxnonstiffstep = 3L,
  nonstifftol = 9/10,
  stifftol = 9/10,
  dtfac = 2,
  stiffalgfirst = FALSE,
  switch_max = 5L
)

AutoSOSRI2(alg, ...)

AutoSOSRA2(alg, ...)

Arguments

algs

A list of SDE algorithms.

choice_function

An AutoSwitch() object or a function, see Details.

nonstiffalg, stiffalg

SDE algorithms.

maxstiffstep, maxnonstiffstep

Consecutive verdicts before switching.

nonstifftol, stifftol

Stiffness ratio tolerances.

dtfac

Step size factor applied at a switch.

stiffalgfirst

Start with the stiff method.

switch_max

Nonstiff verdicts after which errors are checked again.

alg

A stiff SDE algorithm.

...

Options of AutoAlgSwitch().

Value

An SDE algorithm of class StochasticCompositeAlgorithm.

Details

AutoAlgSwitch(nonstiffalg, stiffalg, ...) is the composite that starts with nonstiffalg (or stiffalg with stiffalgfirst = TRUE) and switches to stiffalg after more than maxstiffstep consecutive steps whose stiffness ratio abs(eigen_est * dt / alg_stability_size(nonstiffalg)) exceeds nonstifftol, and back after more than maxnonstiffstep consecutive steps below stifftol; the step size is multiplied by dtfac when switching to the stiff method and divided by it when switching back. switch_max is the number of nonstiff verdicts after which StochasticDiffEq checks the solution for errors again. The stiffness estimate comes from the steps of SOSRI2() and SOSRA2() when they are the first method: AutoSOSRI2(alg, ...) and AutoSOSRA2(alg, ...) pair them with a stiff method alg. A method without a stability region size counts as size 0, so any nonzero estimate is stiff for it.

The solution records the index of the method of each saved point in sol$alg_choice.

Examples

f <- function(u, p, t) -50 * u
g <- function(u, p, t) 0.1 * u
prob <- SDEProblem(f, g, 1, c(0, 0.5))
sol <- solve(prob, AutoSOSRI2(LambaEM()), dt = 0.01, seed = 1)
table(sol$alg_choice)
#> 
#>   1 
#> 508