# NOT RUN {
## ------------------------------------------------
## 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()
# }
# 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"))
})
# }
# 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"))
# }
# 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))
))
# }
Run the code above in your browser using DataLab