Learn R Programming

distr6 (version 1.5.6)

ParameterSetCollection: Parameter Set Collections for Wrapped Distributions

Description

ParameterSetCollection is used to combine multiple ParameterSets in wrapped distributions. Generally only need to be constructed internally.

Arguments

Super class

distr6::ParameterSet -> ParameterSetCollection

Active bindings

deps

Returns ParameterSet dependencies table.

parameterSets

Returns ParameterSets in collection.

Methods

Public methods

Method new()

Creates a new instance of this R6 class.

Usage

ParameterSetCollection$new(..., lst = NULL, .checks = NULL, .supports = NULL)

Arguments

...

([ParameterSet]) ParameterSets to combine into a collection. Should be supplied as named arguments where the names are unique and correspond to references for the distributions.

lst

(list()) Alternative constructor by supplying a named list of ParameterSets.

.checks

Used internally.

.supports

Used internally.

Examples

b = Binomial$new()
g = Geometric$new()
ParameterSetCollection$new(Binom1 = b$parameters(),
                           Binom2 = b$parameters(),
                           Geom = g$parameters())

ParameterSetCollection$new(lst = list(Binom1 = b$parameters(), Binom2 = b$parameters(), Geom = g$parameters()))

Method print()

Prints the ParameterSetCollection.

Usage

ParameterSetCollection$print(hide_cols = c("settable"), ...)

Arguments

hide_cols

(character()) Names of columns in the ParameterSet to hide whilst printing.

...

ANY Additional arguments, currently unused.

Method parameters()

Returns the full parameter details for the supplied parameter, or returns self if id is NULL or unmatched.

Usage

ParameterSetCollection$parameters(id = NULL)

Arguments

id

character() id of parameter to return.

Method getParameterValue()

Returns the value of the supplied parameter.

Usage

ParameterSetCollection$getParameterValue(id, error = "warn")

Arguments

id

(character(1)) To return the parameter for a specific distribution, use the parameter ID with the distribution name prefix, otherwise to return the parameter for all distributions omit the prefix. See examples.

error

(character(1)) If "warn" then returns a warning on error, otherwise breaks if "stop".

Examples

psc <- ParameterSetCollection$new(Binom1 = Binomial$new()$parameters(),
                                  Binom2 = Binomial$new()$parameters(),
                                  Geom = Geometric$new()$parameters())
psc$getParameterValue("Binom1__prob")
psc$getParameterValue("prob")

Method getParameterSupport()

Returns the support of the supplied parameter.

Usage

ParameterSetCollection$getParameterSupport(id, error = "warn")

Arguments

id

character() id of parameter support to return.

error

(character(1)) If "warn" then returns a warning on error, otherwise breaks if "stop".

Returns

A set6::Set object.

Examples

b <- Binomial$new()
g <- Geometric$new()
psc <- ParameterSetCollection$new(Binom1 = b$parameters(),
                                  Binom2 = b$parameters(),
                                  Geom = g$parameters())
psc$getParameterSupport("Binom1__prob")

Method setParameterValue()

Sets the value(s) of the given parameter(s). Because of R6 reference semantics this also updates the ParameterSet of the wrapped distibution, and vice versa. See examples.

Usage

ParameterSetCollection$setParameterValue(
  ...,
  lst = NULL,
  error = "warn",
  resolveConflicts = FALSE
)

Arguments

...

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".

resolveConflicts

(logical(1)) If FALSE (default) throws error if conflicting parameterisations are provided, otherwise automatically resolves them by removing all conflicting parameters.

Examples

b <- Binomial$new()
g <- Geometric$new()
psc <- ParameterSetCollection$new(Binom1 = b$parameters(),
                                  Binom2 = b$parameters(),
                                  Geom = g$parameters())
psc$getParameterValue("Binom1__prob")
b$getParameterValue("prob")
psc$setParameterValue(Binom1__prob = 0.4)
# both updated
psc$getParameterValue("Binom1__prob")
b$getParameterValue("prob")

g$setParameterValue(prob = 0.1) # both updated psc$getParameterValue("Geom__prob") g$getParameterValue("prob")

Method merge()

Merges other ParameterSetCollections into self.

Usage

ParameterSetCollection$merge(..., lst = NULL)

Arguments

...

([ParameterSetCollection]s)

lst

(list(1)) Alternative argument for passing parameters. List names should be parameter names and list values are the new values to set.

`lst`

(list()) Alternative method of passing a list of ParameterSetCollections.

Examples

b <- Binomial$new()
g <- Geometric$new()
psc <- ParameterSetCollection$new(Binom = b$parameters())
psc2 <- ParameterSetCollection$new(Geom = g$parameters())
psc$merge(psc2)$parameters()

Method addDeps()

Dependencies should be added to internal ParameterSets.

Usage

ParameterSetCollection$addDeps(...)

Arguments

...

ANY Ignored.

Method values()

Returns parameter set values as a named list.

Usage

ParameterSetCollection$values(settable = TRUE)

Arguments

settable

(logical(1)) If TRUE (default) only returns values of settable parameters, otherwise returns all.

Method clone()

The objects of this class are cloneable with this method.

Usage

ParameterSetCollection$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

Run this code
# NOT RUN {
## ------------------------------------------------
## Method `ParameterSetCollection$new`
## ------------------------------------------------

b = Binomial$new()
g = Geometric$new()
ParameterSetCollection$new(Binom1 = b$parameters(),
                           Binom2 = b$parameters(),
                           Geom = g$parameters())

ParameterSetCollection$new(lst = list(Binom1 = b$parameters(),
                                      Binom2 = b$parameters(),
                                      Geom = g$parameters()))

## ------------------------------------------------
## Method `ParameterSetCollection$getParameterValue`
## ------------------------------------------------

psc <- ParameterSetCollection$new(Binom1 = Binomial$new()$parameters(),
                                  Binom2 = Binomial$new()$parameters(),
                                  Geom = Geometric$new()$parameters())
psc$getParameterValue("Binom1__prob")
psc$getParameterValue("prob")

## ------------------------------------------------
## Method `ParameterSetCollection$getParameterSupport`
## ------------------------------------------------

b <- Binomial$new()
g <- Geometric$new()
psc <- ParameterSetCollection$new(Binom1 = b$parameters(),
                                  Binom2 = b$parameters(),
                                  Geom = g$parameters())
psc$getParameterSupport("Binom1__prob")

## ------------------------------------------------
## Method `ParameterSetCollection$setParameterValue`
## ------------------------------------------------

b <- Binomial$new()
g <- Geometric$new()
psc <- ParameterSetCollection$new(Binom1 = b$parameters(),
                                  Binom2 = b$parameters(),
                                  Geom = g$parameters())
psc$getParameterValue("Binom1__prob")
b$getParameterValue("prob")
psc$setParameterValue(Binom1__prob = 0.4)
# both updated
psc$getParameterValue("Binom1__prob")
b$getParameterValue("prob")

g$setParameterValue(prob = 0.1)
# both updated
psc$getParameterValue("Geom__prob")
g$getParameterValue("prob")

## ------------------------------------------------
## Method `ParameterSetCollection$merge`
## ------------------------------------------------

b <- Binomial$new()
g <- Geometric$new()
psc <- ParameterSetCollection$new(Binom = b$parameters())
psc2 <- ParameterSetCollection$new(Geom = g$parameters())
psc$merge(psc2)$parameters()

# }

Run the code above in your browser using DataLab