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


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()
#>   a   b 
#> 0.1 0.0 

# 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
#>           [,1]        [,2]        [,3]       [,4]        [,5]
#> a  0.095039469  0.07334459 0.116361301 0.12941940 0.104585662
#> b -0.007306416 -0.01133474 0.006297038 0.02415437 0.001534398

# Propose a new parameter set
p_mat <- pars$walk(p_mat, pars_sd)
p_mat
#>          [,1]         [,2]        [,3]       [,4]        [,5]
#> a  0.10590882  0.101096316  0.13392404 0.13027376  0.07802785
#> b -0.02957219 -0.008500499 -0.01550211 0.03416819 -0.00691448

# Information about parameters:
pars$names()
#> [1] "a" "b"
pars$summary()
#>   name  min max discrete integer
#> 1    a    0   1    FALSE   FALSE
#> 2    b -Inf Inf    FALSE   FALSE

# Compute prior
pars$prior(p_mat)
#> [1] -1.846409 -1.892754 -1.611588 -1.639408 -2.151757

# Transform data for your model
pars$model(p_mat)
#> [[1]]
#> [[1]]$a
#> [1] 0.1059088
#> 
#> [[1]]$b
#> [1] -0.02957219
#> 
#> 
#> [[2]]
#> [[2]]$a
#> [1] 0.1010963
#> 
#> [[2]]$b
#> [1] -0.008500499
#> 
#> 
#> [[3]]
#> [[3]]$a
#> [1] 0.133924
#> 
#> [[3]]$b
#> [1] -0.01550211
#> 
#> 
#> [[4]]
#> [[4]]$a
#> [1] 0.1302738
#> 
#> [[4]]$b
#> [1] 0.03416819
#> 
#> 
#> [[5]]
#> [[5]]$a
#> [1] 0.07802785
#> 
#> [[5]]$b
#> [1] -0.00691448
#> 
#>