Skip to contents

StochasticTransformedFunction(sol, f, g, corfunc_analytical) wraps the drift f(u, p, t) of an Ito SDE solved in sol for the stochastic adjoints: it returns f(u, p, t) - c(u, p, t) with the correction c = J' vec(g(u, p, t)), J the Jacobian of vec(g) with respect to u (as SciMLSensitivity, which computes it by reverse mode differentiation; here central differences), or c = corfunc_analytical(u, p, t) when given.

Usage

StochasticTransformedFunction(
  sol,
  f = NULL,
  g = NULL,
  corfunc_analytical = NULL
)

Arguments

sol

The forward SDE solution (gives the problem).

f, g

Drift and diffusion functions (u, p, t); those of the problem when NULL.

corfunc_analytical

NULL or a function (u, p, t) returning the correction.

Value

A function (u, p, t) of class StochasticTransformedFunction.

Examples

prob <- SDEProblem(function(u, p, t) p[1] * u, function(u, p, t) p[2] * u, 1, c(0, 1),
  c(1.01, 0.87))
sol <- solve(prob, EM(), dt = 0.1, seed = 1)
tf <- StochasticTransformedFunction(sol)
tf(2, c(1.01, 0.87), 0)   # 1.01 * 2 - 0.87^2 * 2
#> [1] 0.5062