if2_parameters: if2_parameters

if2_parametersR Documentation

if2_parameters

Description

Construct parameters for use with if2(). This creates a utility object that is used internally to work with parameters. Most users only need to construct this object, but see the examples for how it can be used.

Methods

Public methods


Method new()

Create the if2_parameters object

Usage
if2_parameters$new(parameters, transform = NULL)
Arguments
parameters

A list of if2_parameter objects, each of which describe a single parameter in your model. If parameters is named, then these names must match the ⁠$name⁠ element of each parameter is used (this is verified).

transform

An optional transformation function to apply to your parameter vector immediately before passing it to the model function. If not given, then as.list is used, as dust models require this. However, if you need to generate derived parameters from those being actively sampled you can do arbitrary transformations here.


Method initial()

Return the initial parameter values as a named numeric vector

Usage
if2_parameters$initial()

Method walk_initialise()

Set up a parameter walk

Usage
if2_parameters$walk_initialise(n_par_sets, pars_sd)
Arguments
n_par_sets

An integer number of parameter sets, which defines the size of the population being peturbed.

pars_sd

A vector of standard deviations for the walk of each parameter


Method walk()

Propose a new parameter matrix given a current matrix and walk standard deviation vector.

Usage
if2_parameters$walk(pars, pars_sd)
Arguments
pars

A parameter matrix, from this function or ⁠$walk_initialise()⁠

pars_sd

A vector of standard deviations for the walk of each parameter


Method names()

Return the names of the parameters

Usage
if2_parameters$names()

Method summary()

Return a data.frame with information about parameters (name, min, max, and integer).

Usage
if2_parameters$summary()

Method prior()

Compute the prior for a parameter vector

Usage
if2_parameters$prior(pars)
Arguments
pars

a parameter matrix from ⁠$walk()⁠


Method model()

Apply the model transformation function to a parameter vector. Output is a list for lists, suitable for use with a dust object with pars_multi = TRUE

Usage
if2_parameters$model(pars)
Arguments
pars

a parameter matrix from ⁠$walk()⁠

Examples

# Construct an object with two parameters:
pars <- mcstate::if2_parameters$new(
  list(mcstate::if2_parameter("a", 0.1, min = 0, max = 1,
                                prior = function(a) log(a)),
       mcstate::if2_parameter("b", 0, prior = dnorm)))

# Initial parameters
pars$initial()

# Create the initial parameter set
n_par_sets <- 5
pars_sd <- list("a" = 0.02, "b" = 0.02)
p_mat <- pars$walk_initialise(n_par_sets, pars_sd)
p_mat

# Propose a new parameter set
p_mat <- pars$walk(p_mat, pars_sd)
p_mat

# Information about parameters:
pars$names()
pars$summary()

# Compute prior
pars$prior(p_mat)

# Transform data for your model
pars$model(p_mat)

mrc-ide/mcstate documentation built on July 3, 2024, 1:34 p.m.