Parameter Sets for Distributions
ParameterSets are passed to the Distribution constructor when creating a custom probability distribution that takes parameters.
deps
Returns ParameterSet dependencies table.
checks
Returns ParameterSet assertions table.
trafos
Returns ParameterSet transformations table.
length
Number of parameters in ParameterSet.
new()
Creates a new instance of this R6 class.
ParameterSet$new( id, value, support, settable = TRUE, updateFunc = NULL, description = NULL )
id
(character(1)|list())
id of the parameter(s) to construct, should be unique.
value
(ANY|list())
Value of parameter(s) to set.
support
([set6::Set]|list())
Support of parameter(s) to set
settable
(character(1)|list())
Logical flag indicating if the parameter(s) can be updated after construction.
updateFunc
(list())
Deprecated, please use $addDeps
instead.
description
(character(1)|list())
Optional description for the parameter(s).
Every argument can either be given as the type listed or as a list of that type. If arguments are provided as a list, then each argument must be of the same length, with values as NULL where appropriate. See examples for more.
id <- list("prob", "size") value <- list(0.2, 5) support <- list(set6::Interval$new(0, 1), set6::PosNaturals$new()) description <- list("Probability of success", NULL) ParameterSet$new(id = id, value = value, support = support, description = description ) ParameterSet$new(id = "prob", value = 0.2, support = set6::Interval$new(0, 1), description = "Probability of success" )
print()
Prints the ParameterSet.
ParameterSet$print(hide_cols = c("settable"), ...)
hide_cols
(character())
Names of columns in the ParameterSet to hide whilst printing.
...
ANY
Additional arguments, currently unused.
parameters()
Returns the full parameter details for the supplied parameter, or returns self
if id
is NULL
.
ParameterSet$parameters(id = NULL)
id
character()
id of parameter to return.
getParameterSupport()
Returns the support of the supplied parameter.
ParameterSet$getParameterSupport(id, error = "warn")
id
character()
id of parameter support to return.
error
(character(1))
If "warn"
then returns a warning on error, otherwise breaks if "stop"
.
A set6::Set object.
ps <- ParameterSet$new(id = "prob", value = 0.2, support = set6::Interval$new(0, 1), settable = TRUE, description = "Probability of success" ) ps$getParameterSupport("prob")
getParameterValue()
Returns the value of the supplied parameter.
ParameterSet$getParameterValue(id, error = "warn")
id
character()
id of parameter value to return.
error
(character(1))
If "warn"
then returns a warning on error, otherwise breaks if "stop"
.
ps <- ParameterSet$new(id = "prob", value = 0.2, support = set6::Interval$new(0, 1), settable = TRUE, description = "Probability of success" ) ps$getParameterValue("prob")
setParameterValue()
Sets the value(s) of the given parameter(s).
ParameterSet$setParameterValue( ..., lst = NULL, error = "warn", .suppressCheck = FALSE, resolveConflicts = FALSE )
...
ANY
Named arguments of parameters to set values for. See examples.
lst
(list(1))
Alternative argument for passing parameters. List names should be parameter names and list values
are the new values to set.
error
(character(1))
If "warn"
then returns a warning on error, otherwise breaks if "stop"
.
.suppressCheck
(logical(1))
Should be set internally only.
resolveConflicts
(logical(1))
If FALSE
(default) throws error if conflicting parameterisations are provided, otherwise
automatically resolves them by removing all conflicting parameters.
id <- list("rate") value <- list(1) support <- list(set6::PosReals$new()) ps <- ParameterSet$new( id, value, support ) ps$setParameterValue(rate = 2) ps$getParameterValue("rate")
merge()
Merges multiple parameter sets.
ParameterSet$merge(y, ...)
y
([ParameterSet])
...
([ParameterSet]s)
\dontrun{ ps1 <- ParameterSet$new(id = c("prob", "qprob"), value = c(0.2, 0.8), support = list(set6::Interval$new(0, 1), set6::Interval$new(0, 1)) ) ps1$addChecks(function(self) self$getParameterValue("x") > 0) ps1$addDeps("prob", "qprob", function(self) list(qprob = 1 - self$getParameterValue("prob"))) ps2 <- ParameterSet$new(id = "size", value = 10, support = set6::Interval$new(0, 10, class = "integer"), ) ps2$addTrafos("size", function(x, self) x + 1) ps1$merge(ps2) ps1$print() }
addDeps()
Add parameter dependencies for automatic updating.
ParameterSet$addDeps(x, y, fun)
x
(character(1))
id of parameter that updates y
.
y
(character())
id of parameter(s) that is/are updated by x
.
fun
(function(1))
Function used to update y
, must include self
in formal arguments and should return a
named list with names identical to, and in the same order, as y
.
\dontrun{ ps <- ParameterSet$new( id = list("a", "b", "c"), value = list(2, 3, 1/2), support = list(set6::Reals$new(), set6::Reals$new(), set6::Reals$new()) ) ps$addDeps("a", c("b", "c"), function(self) { list(b = self$getParameterValue("a") + 1, c = 1/self$getParameterValue("a")) }) }
addChecks()
Add parameter checks for automatic assertions. Note checks are made after any transformations.
ParameterSet$addChecks(fun)
fun
(function(1))
Function used to check ParameterSet
, must include self
in formal arguments and
result in a logical.
\dontrun{ id <- list("lower", "upper") value <- list(1, 3) support <- list(set6::PosReals$new(), set6::PosReals$new()) ps <- ParameterSet$new( id, value, support ) ps$addChecks(function(self) self$getParameterValue("lower") < self$getParameterValue("upper")) }
addTrafos()
Transformations to apply to parameter before setting. Note transformations are made before checks. NOTE: If a transformation for a parameter already exists then this will be overwritten.
ParameterSet$addTrafos(x, fun, dt = NULL)
x
(character(1))
id of parameter to be transformed. Only one trafo function per parameter allowed - though
multiple transformations can be encoded within this.
fun
(function(1))
Function used to transform x
, must include x, self
in formal arguments and
x
in body where x
is the value of the parameter to check. See first example.
dt
([data.table::data.table])
Alternate method to directly construct data.table
of transformations to add.
See second example.
\dontrun{ ps <- ParameterSet$new( "probs", list(c(1, 1)), set6::Interval$new(0,1)^2 ) ps$addTrafos("probs", function(x, self) return(x / sum(x))) ps$trafos ps$setParameterValue(probs = c(1, 2)) ps$getParameterValue("probs") # Alternate method (better with more parameters) ps <- ParameterSet$new( "probs", list(c(1, 1)), set6::Interval$new(0,1)^2 ) ps$addTrafos(dt = data.table::data.table( x = "probs", fun = function(x, self) return(x / sum(x)) )) }
values()
Returns parameter set values as a named list.
ParameterSet$values(settable = TRUE)
settable
(logical(1))
If TRUE
(default) only returns values of settable parameters.
clone()
The objects of this class are cloneable with this method.
ParameterSet$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `ParameterSet$new` ## ------------------------------------------------ id <- list("prob", "size") value <- list(0.2, 5) support <- list(set6::Interval$new(0, 1), set6::PosNaturals$new()) description <- list("Probability of success", NULL) ParameterSet$new(id = id, value = value, support = support, description = description ) ParameterSet$new(id = "prob", value = 0.2, support = set6::Interval$new(0, 1), description = "Probability of success" ) ## ------------------------------------------------ ## Method `ParameterSet$getParameterSupport` ## ------------------------------------------------ ps <- ParameterSet$new(id = "prob", value = 0.2, support = set6::Interval$new(0, 1), settable = TRUE, description = "Probability of success" ) ps$getParameterSupport("prob") ## ------------------------------------------------ ## Method `ParameterSet$getParameterValue` ## ------------------------------------------------ ps <- ParameterSet$new(id = "prob", value = 0.2, support = set6::Interval$new(0, 1), settable = TRUE, description = "Probability of success" ) ps$getParameterValue("prob") ## ------------------------------------------------ ## Method `ParameterSet$setParameterValue` ## ------------------------------------------------ id <- list("rate") value <- list(1) support <- list(set6::PosReals$new()) ps <- ParameterSet$new( id, value, support ) ps$setParameterValue(rate = 2) ps$getParameterValue("rate") ## ------------------------------------------------ ## Method `ParameterSet$merge` ## ------------------------------------------------ ## Not run: ps1 <- ParameterSet$new(id = c("prob", "qprob"), value = c(0.2, 0.8), support = list(set6::Interval$new(0, 1), set6::Interval$new(0, 1)) ) ps1$addChecks(function(self) self$getParameterValue("x") > 0) ps1$addDeps("prob", "qprob", function(self) list(qprob = 1 - self$getParameterValue("prob"))) ps2 <- ParameterSet$new(id = "size", value = 10, support = set6::Interval$new(0, 10, class = "integer"), ) ps2$addTrafos("size", function(x, self) x + 1) ps1$merge(ps2) ps1$print() ## End(Not run) ## ------------------------------------------------ ## Method `ParameterSet$addDeps` ## ------------------------------------------------ ## Not run: ps <- ParameterSet$new( id = list("a", "b", "c"), value = list(2, 3, 1/2), support = list(set6::Reals$new(), set6::Reals$new(), set6::Reals$new()) ) ps$addDeps("a", c("b", "c"), function(self) { list(b = self$getParameterValue("a") + 1, c = 1/self$getParameterValue("a")) }) ## End(Not run) ## ------------------------------------------------ ## Method `ParameterSet$addChecks` ## ------------------------------------------------ ## Not run: id <- list("lower", "upper") value <- list(1, 3) support <- list(set6::PosReals$new(), set6::PosReals$new()) ps <- ParameterSet$new( id, value, support ) ps$addChecks(function(self) self$getParameterValue("lower") < self$getParameterValue("upper")) ## End(Not run) ## ------------------------------------------------ ## Method `ParameterSet$addTrafos` ## ------------------------------------------------ ## Not run: ps <- ParameterSet$new( "probs", list(c(1, 1)), set6::Interval$new(0,1)^2 ) ps$addTrafos("probs", function(x, self) return(x / sum(x))) ps$trafos ps$setParameterValue(probs = c(1, 2)) ps$getParameterValue("probs") # Alternate method (better with more parameters) ps <- ParameterSet$new( "probs", list(c(1, 1)), set6::Interval$new(0,1)^2 ) ps$addTrafos(dt = data.table::data.table( x = "probs", fun = function(x, self) return(x / sum(x)) )) ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.