Skip to contents

R6 wrapper for the Lorenz ODE solver.

Public fields

ptr

External pointer to the underlying C++ solver object.

Methods


Lorenz_Solver$new()

Initialize a solver for a Lorenz system. The solver takes its own copy of the system as it is at this moment and steps that copy: set_params() or set_state() on the LorenzSystem afterwards do not reach the solver. Use the solver's own $set_params() and $set_state().

Usage

Lorenz_Solver$new(System_xp, control_xp, method = "rkck")

Arguments

System_xp

External pointer to the Lorenz system object.

control_xp

External pointer to the ODE control object.

method

Integration method: "rkck" (default, explicit Cash-Karp RK 4(5)), "dopri" (explicit Dormand-Prince 5(4)), "rodas" (implicit RODAS4(3) Rosenbrock, for stiff systems) or "ros34pw2" (Rosenbrock-W of order 3, which keeps its Jacobian across steps and cannot be differentiated).


Lorenz_Solver$pars()

Parameters of the system this solver steps.

Usage

Lorenz_Solver$pars()


Lorenz_Solver$set_params()

Set the parameters this solver steps with, and re-seed it at its current state and time as $set_state() would. Call $reset() as well to start again from the initial state.

Usage

Lorenz_Solver$set_params(params)

Arguments

params

Numeric vector of system parameters, one entry per parameter in the system's order (for Lorenz: sigma, R, b).


Lorenz_Solver$time()

Get current solver time.

Usage

Lorenz_Solver$time()


Lorenz_Solver$state()

Get current solver state.

Usage

Lorenz_Solver$state()


Lorenz_Solver$set_state()

Set current solver state and time.

Usage

Lorenz_Solver$set_state(y, time)

Arguments

y

Numeric state vector.

time

Scalar time value.


Lorenz_Solver$times()

Get stored solver times.

Usage

Lorenz_Solver$times()


Lorenz_Solver$advance_adaptive()

Advance solver using adaptive stepping.

Usage

Lorenz_Solver$advance_adaptive(times)

Arguments

times

Numeric vector of requested output times.


Lorenz_Solver$advance_fixed()

Advance solver using fixed stepping.

Usage

Lorenz_Solver$advance_fixed(times)

Arguments

times

Numeric vector of requested output times.


Lorenz_Solver$advance_euler()

Advance solver using fixed-step forward Euler.

Usage

Lorenz_Solver$advance_euler(times)

Arguments

times

Numeric vector of requested output times.


Lorenz_Solver$step()

Advance solver by one step.

Usage

Lorenz_Solver$step()


Lorenz_Solver$reset()

Reset solver to its initial state.

Usage

Lorenz_Solver$reset()


Lorenz_Solver$collect()

Get or set history collection behavior.

Usage

Lorenz_Solver$collect(value)

Arguments

value

Logical flag for collect-history behavior.


Lorenz_Solver$history_size()

Return number of stored history entries.

Usage

Lorenz_Solver$history_size()


Lorenz_Solver$history_step()

Return one history entry by index.

Usage

Lorenz_Solver$history_step(i)

Arguments

i

Integer index into solver history.


Lorenz_Solver$history()

Return history as a tibble.

Usage

Lorenz_Solver$history()


Lorenz_Solver$set_target()

Set the calibration target for $loss_and_gradient().

Usage

Lorenz_Solver$set_target(schedule, target, obs_indices)

Arguments

schedule

Numeric vector: the step times $loss_and_gradient() replays, one entry per step. Normally a reference run's $times(), so each evaluation takes the same steps and the loss is a smooth function of the inputs.

target

Numeric matrix of observed states, one row per entry of obs_indices and one column per state variable.

obs_indices

Integer indices (1-based) into schedule at which each row of target was observed.


Lorenz_Solver$loss_and_gradient()

Least-squares loss against the target, and its exact gradient by automatic differentiation. The schedule is stepped under this solver's method.

Usage

Lorenz_Solver$loss_and_gradient(
  initial_state = NULL,
  params = NULL,
  mode = NULL
)

Arguments

initial_state

Initial state to evaluate at, or NULL to keep the system's.

params

Parameters to evaluate at, or NULL to keep the system's.

mode

"reverse": one reverse sweep, whose cost does not grow with the number of inputs. "forward": the schedule walked again carrying one direction per input, whose cost does; it is the only mode under "rodas", which cannot be swept. NULL (the default) is "forward" for a "rodas" solver and "reverse" otherwise. A "ros34pw2" solver is refused in either mode.

Returns

A list with loss (sum of squared differences) and gradient: d(loss)/d(params), then d(loss)/d(initial_state), for whichever were given.


Lorenz_Solver$sensitivities()

The state at each of times and its derivative with respect to the parameters and to the state at times[1], by forward-mode automatic differentiation. The solve starts from where this solver stands, with its step size afresh, and lands a step on every time; the solver itself does not move. Those steps are then walked again carrying one direction per input, under the solver's own method, "rodas" included; a "ros34pw2" solver is refused. The cost grows with the number of inputs and not with the number of times.

Usage

Lorenz_Solver$sensitivities(times, parameters = TRUE, initial = TRUE)

Arguments

times

Numeric vector of requested output times.

parameters

The parameters to differentiate with respect to: TRUE (all), FALSE (none), or names ("sigma", "R", "b") or indices.

initial

The components of the state at times[1] to differentiate with respect to: TRUE, FALSE, or names ("x", "y", "z") or indices.

Returns

A list with time; y, the state, one row per time; and dy, an array indexed by time, state component and input: the parameters first, then the initial state, named x0, y0, z0.


Lorenz_Solver$clone()

The objects of this class are cloneable with this method.

Usage

Lorenz_Solver$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.