Learn R Programming

distr6 (version 1.1.0)

ParameterSet: Make an R6 Parameter Set for Distributions

Description

ParameterSets are passed to a Distribution$new constructor when creating a custom probability distribution that takes parameters.

Value

An R6 object of class ParameterSet.

Constructor

ParameterSet$new(id, value, support, settable, updateFunc = NULL, description = NULL)

Constructor Arguments

Argument Type Details
id character unique one-word identifier.
value numeric initial parameter value.
support numeric range of values parameter can take.
settable logical if TRUE the parameter is printed. See Details.
updateFunc = NULL function evaluated to update parameter. See Details.

Constructor Details

An R6 ParameterSet is required to construct a custom Probability Distribution that takes parameters. This constructor ensures that the correct format of parameters is supplied to the distribution.

Every argument can either be given as the type listed above or as a list of that type. If arguments are provided as a list, then each argument must be of the same length list, with values as NULL where appropriate. See examples for more.

Each parameter requires a unique one-word id that is used to get and set parameters after construction. The parameterisation of the distribution is determined by the parameters that have settable = TRUE, this is a slightly confusing term as it actually refers to a parameter being 'machine-settable'. Here it just means that the given parameter is used in construction and therefore will be included in a call to $print. updateFunc is used to update the parameters not used in the parameterisation. These should be given as a function that could be understood in the body of a Distribution and should start with function(self), see examples.

Internally after calling $setParameterValue, $update is called to update all parameters with a non-NA updateFunc.

Public Methods

Method Link
print(hide_cols = c("updateFunc","settable")) print.ParameterSet
update() update.ParameterSet
parameters(id = NULL) parameters
getParameterSupport(id, error = "warn") getParameterSupport
getParameterValue(id, error = "warn") getParameterValue
setParameterValue(..., lst = NULL, error = "warn") setParameterValue
merge(y, ...) merge.ParameterSet
as.data.table() as.data.table

See Also

Distribution

Examples

Run this code
# NOT RUN {
 id = list("prob", "size")
 value = list(0.2, 5)
 support = list(Interval$new(0,1), PosNaturals$new())
 settable = list(TRUE, TRUE)
 description = list("Probability of success",NULL)
 ps = ParameterSet$new(id, value, support, settable,
                       description = description)
 ps$parameters()
 ps$getParameterValue("prob")
 ps$getParameterSupport("prob")


 id = list("rate", "scale")
 value = list(1, 1)
 support = list(PosReals$new(), PosReals$new())
 settable = list(TRUE, FALSE)
 updateFunc = list(NULL, function(self) 1/self$getParameterValue('rate'))
 description = list("Arrival rate","Scale parameter")
 ps = ParameterSet$new(id, value, support, settable,
                       updateFunc, description)
 ps$parameters(id = "rate")
 ps$setParameterValue(rate = 2) # Automatically calls $update
 ps$getParameterValue("scale") # Auto-updated to 1/2

# }

Run the code above in your browser using DataLab