OdeModel: An ODE model (R6 class)

OdeModelR Documentation

An ODE model (R6 class)

Description

An ODE model (R6 class). Users are not meant to instantiate objects of this class directly, instead use the ode_model() function to create models.

Public fields

has_likelihood

Is there a likelihood function?

stanmodel

An object of class StanModelWithCode.

odemodeling_version

of the package used to create the model

sig_figs

Number of significant figures to use everywhere.

t_dim

A StanDimension of the time points array.

ode_dim

A StanDimension of the ODE system.

Methods

Public methods


Method new()

Create an OdeModel object.

Usage
OdeModel$new(has_likelihood, stanmodel, sig_figs, t_dim, ode_dim)
Arguments
has_likelihood

Is there a likelihood function?

stanmodel

An object of class StanModelWithCode (will be deepcopied)..

sig_figs

Number of significant figures to use in all Stan i/o.

t_dim

Time points vector dimension variable (will be deepcopied).

ode_dim

ODE system dimension variable (will be deepcopied).

compile

Should the models be compiled.


Method assert_stanfile_exists()

Check that the Stan model has been initialized correctly

Usage
OdeModel$assert_stanfile_exists()

Method reinit()

(Re)initialize the Stan model

Usage
OdeModel$reinit()

Method print()

Print information about the model

Usage
OdeModel$print()

Method code()

Get the Stan code of the model.

Usage
OdeModel$code()

Method make_params()

Format a vector into a draws array that can be passed to ⁠$gqs()⁠. Currently works only for models with only scalar parameters.

Usage
OdeModel$make_params(x)
Arguments
x

A a vector with length equal to total number of model parameters.

Returns

A posterior::draws_array object with only one chain and iteration.


Method gqs()

Run standalone generated quantities.

Usage
OdeModel$gqs(t0, t, data = list(), solver = rk45(), params = NULL, ...)
Arguments
t0

Initial time.

t

Vector of time points.

data

Additional data.

solver

ODE solver.

params

Equal to the fitted_params argument of the ⁠$generate_quantities()⁠ method of the underlying cmdstanr::CmdStanModel object.

...

Arguments passed to the ⁠$generate_quantities()⁠ method of the underlying cmdstanr::CmdStanModel object.

Returns

An object of class OdeModelGQ.


Method sample()

Sample parameters of the model

Usage
OdeModel$sample(t0, t, data = list(), solver = rk45(), ...)
Arguments
t0

Initial time point.

t

Vector of time points.

data

Other needed data as a list.

solver

An object of class OdeSolver.

...

Arguments passed to the ⁠$sample()⁠ method of the underlying cmdstanr::CmdStanModel object.

Returns

An object of class OdeModelMCMC.


Method diagnose()

Run a gradient diagnosis

Usage
OdeModel$diagnose(
  t0,
  t,
  data = list(),
  solver = rk45(),
  error = Inf,
  epsilon = 1e-06,
  ...
)
Arguments
t0

Initial time point.

t

Vector of time points.

data

Other needed data as a list.

solver

An object of class OdeSolver.

error

Error threshold.

epsilon

Perturbation size.

...

Arguments passed to the ⁠$diagnose()⁠ method of the underlying cmdstanr::CmdStanModel object.

Returns

Raw 'Stan' output.


Method sample_manyconf()

Sample parameters of the ODE model using many different ODE solver configurations

Usage
OdeModel$sample_manyconf(
  solvers,
  t0,
  t,
  data = list(),
  savedir = "results",
  basename = "odemodelfit",
  chains = 4,
  ...
)
Arguments
solvers

List of ODE solvers (possibly the same solver with different configurations). See odesolvers_lists for creating this.

t0

Initial time point.

t

Vector of time points.

data

Other needed data as a list.

savedir

Directory where results are saved.

basename

Base name for saved files.

chains

Number of MCMC chains.

...

Additional arguments passed to the ⁠$sample()⁠ method of the underlying cmdstanr::CmdStanModel object.

Returns

A named list.


Method clone()

The objects of this class are cloneable with this method.

Usage
OdeModel$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


jtimonen/odemodeling documentation built on Sept. 15, 2024, 4:29 a.m.