if2_parameters | R Documentation |
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.
new()
Create the if2_parameters object
if2_parameters$new(parameters, transform = NULL)
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.
initial()
Return the initial parameter values as a named numeric vector
if2_parameters$initial()
walk_initialise()
Set up a parameter walk
if2_parameters$walk_initialise(n_par_sets, pars_sd)
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
walk()
Propose a new parameter matrix given a current matrix and walk standard deviation vector.
if2_parameters$walk(pars, pars_sd)
pars
A parameter matrix, from this function or
$walk_initialise()
pars_sd
A vector of standard deviations for the walk of each parameter
names()
Return the names of the parameters
if2_parameters$names()
summary()
Return a data.frame
with information about
parameters (name, min, max, and integer).
if2_parameters$summary()
prior()
Compute the prior for a parameter vector
if2_parameters$prior(pars)
pars
a parameter matrix from $walk()
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
if2_parameters$model(pars)
pars
a parameter matrix from $walk()
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.