Title: | Creating Meta-Information for Parameters |
---|---|
Description: | Provides tools for describing parameters of algorithms in an abstract way. Description can include an id, a description, a domain (range or list of values), and a default value. 'dynparam' can also convert parameter sets to a 'ParamHelpers' format, in order to be able to use 'dynparam' in conjunction with 'mlrMBO'. |
Authors: | Robrecht Cannoodt [aut, cre] (<https://orcid.org/0000-0003-3641-729X>, rcannood), Wouter Saelens [aut] (<https://orcid.org/0000-0002-7114-6248>, zouter) |
Maintainer: | Robrecht Cannoodt <[email protected]> |
License: | GPL-3 |
Version: | 1.0.0 |
Built: | 2024-10-25 03:16:56 UTC |
Source: | https://github.com/dynverse/dynparam |
Define a character / string parameter
character_parameter(id, default, values, description = NULL, tuneable = TRUE)
character_parameter(id, default, values, description = NULL, tuneable = TRUE)
id |
The name of the parameter. |
default |
The default value of the parameter. |
values |
A set of possible values. |
description |
An optional (but recommended) description of the parameter. |
tuneable |
Whether or not a parameter is tuneable. |
dynparam for an overview of all dynparam functionality.
character_parameter( id = "method", default = "pearson", values = c("pearson", "spearman", "kendall"), description = "Which correlation coefficient to compute." )
character_parameter( id = "method", default = "pearson", values = c("pearson", "spearman", "kendall"), description = "Which correlation coefficient to compute." )
Will surround the collapsed set with brackets if it has more than one element.
collapse_set(..., sep = ", ", prefix = "{", postfix = "}")
collapse_set(..., sep = ", ", prefix = "{", postfix = "}")
... |
Characters to collapse |
sep |
Seperator between elements |
prefix |
A prefix |
postfix |
A postfix |
Distributions are used to define the domain of an
integer_parameter()
or a numeric_parameter()
.
distribution(lower, upper, ...) distribution_function(dist) quantile_function(dist) ## S3 method for class 'distribution' as.list(x, ...) as_distribution(li) is_distribution(x)
distribution(lower, upper, ...) distribution_function(dist) quantile_function(dist) ## S3 method for class 'distribution' as.list(x, ...) as_distribution(li) is_distribution(x)
lower |
Lower limit of the distribution. |
upper |
Upper limit of the distribution. |
... |
Fields to be saved in the distribution. |
dist |
A distribution object. |
x |
An object which might be a distribution. |
li |
A list to be converted into a distribution. |
See the sections below for more information each of the functions.
as.list(dist)
: Converting a distribution to a list.
as_distribution(li)
: Converting a list back to a distribution.
is_distribution(x)
: Checking whether something is a distribution.
In order to create a new distribution named xxx
, you need to create three functions.
A xxx()
function that calls distribution(...) %>% add_class("xxx")
at the end.
quantile_function.xxx()
: The quantile function for converting between a uniform distribution and the xxx
distribution.
distribution_function.xxx()
: The distribution function for converting between a uniform distribution and the xxx
distribution.
Check the implementations of normal_distribution()
, quantile_function.normal_distribution()
and distribution_function.normal_distribution()
for an example
on how to do define these functions. Alternatively, check the examples below.
dynparam for an overview of all dynparam functionality.
di <- uniform_distribution(lower = 1, upper = 10) print(di) li <- as.list(di) di2 <- as_distribution(li) print(di2) # Defining a custom distribution, using the pbeta and qbeta functions beta_distribution <- function( shape1, shape2, ncp, lower = -Inf, upper = Inf ) { di <- distribution(lower = lower, upper = upper, shape1, shape2, ncp) add_class(di, beta_distribution) } distribution_function.beta_distribution <- function(dist) { function(q) { stats::pbeta(q, shape1 = dist$shape1, shape2 = dist$shape2, ncp = dist$ncp) } } quantile_function.beta_distribution <- function(dist) { function(p) { stats::qbeta(p, shape1 = dist$shape1, shape2 = dist$shape2, ncp = dist$ncp) } }
di <- uniform_distribution(lower = 1, upper = 10) print(di) li <- as.list(di) di2 <- as_distribution(li) print(di2) # Defining a custom distribution, using the pbeta and qbeta functions beta_distribution <- function( shape1, shape2, ncp, lower = -Inf, upper = Inf ) { di <- distribution(lower = lower, upper = upper, shape1, shape2, ncp) add_class(di, beta_distribution) } distribution_function.beta_distribution <- function(dist) { function(q) { stats::pbeta(q, shape1 = dist$shape1, shape2 = dist$shape2, ncp = dist$ncp) } } quantile_function.beta_distribution <- function(dist) { function(p) { stats::qbeta(p, shape1 = dist$shape1, shape2 = dist$shape2, ncp = dist$ncp) } }
Provides tools for describing parameters of algorithms in an abstract way. Description can include an id, a description, a domain (range or list of values), and a default value. 'dynparam' can also convert parameter sets to a 'ParamHelpers' format, in order to be able to use 'dynparam' in conjunction with 'mlrMBO'.
Create a new parameter_set()
by adding several parameters to it
as_paramhelper()
: Convert it to a ParamHelpers object
sip()
: Sample a parameter set
These functions help you provide a meta description of parameters.
Implemented are the following functions:
character_parameter()
, integer_parameter()
, logical_parameter()
, numeric_parameter()
: Creating parameters with basic R data types.
integer_range_parameter()
, numeric_range_parameter()
: Create a discrete or continuous range parameter.
subset_parameter()
: A parameter containing a subset of a set of values.
See ?parameter for a list of helper functions converting parameters from and to other formats.
These distributions allow to define prior distributions for numeric and integer parameters.
Implemented are the following distributions:
See ?distribution for a list of helper functions converting parameters from and to other formats.
distribution()
: Creating a custom distribution
Distributions are used for defining the domain of an integer_parameter()
or numeric_parameter()
.
expuniform_distribution(lower, upper)
expuniform_distribution(lower, upper)
lower |
Lower limit of the distribution. |
upper |
Upper limit of the distribution. |
dynparam for an overview of all dynparam functionality.
expuniform_distribution(1, 10000) expuniform_distribution(1e-5, 1e-2)
expuniform_distribution(1, 10000) expuniform_distribution(1e-5, 1e-2)
Get a description of the parameter
get_description(x, sep = ", ")
get_description(x, sep = ", ")
x |
The parameter |
sep |
A separator between different fields |
Define a integer parameter
integer_parameter(id, default, distribution, description = NULL, tuneable = TRUE)
integer_parameter(id, default, distribution, description = NULL, tuneable = TRUE)
id |
The name of the parameter. |
default |
The default value of the parameter. |
distribution |
A distribution from which the parameter can be sampled. |
description |
An optional (but recommended) description of the parameter. |
tuneable |
Whether or not a parameter is tuneable. |
dynparam for an overview of all dynparam functionality.
integer_parameter( id = "k", default = 5, distribution = uniform_distribution(3, 10), description = "The number of clusters." ) integer_parameter( id = "num_iter", default = 100, distribution = expuniform_distribution(10, 10000), description = "The number of iterations." )
integer_parameter( id = "k", default = 5, distribution = uniform_distribution(3, 10), description = "The number of clusters." ) integer_parameter( id = "num_iter", default = 100, distribution = expuniform_distribution(10, 10000), description = "The number of iterations." )
Define a integer range parameter
integer_range_parameter(id, default, lower_distribution, upper_distribution, description = NULL, tuneable = TRUE)
integer_range_parameter(id, default, lower_distribution, upper_distribution, description = NULL, tuneable = TRUE)
id |
The name of the parameter. |
default |
The default value of the parameter. |
lower_distribution |
A distribution from which the lower value of the range can be sampled. |
upper_distribution |
A distribution from which the upper value fo the range can be sampled. |
description |
An optional (but recommended) description of the parameter. |
tuneable |
Whether or not a parameter is tuneable. |
dynparam for an overview of all dynparam functionality.
integer_range_parameter( id = "ks", default = c(3L, 15L), lower_distribution = uniform_distribution(1L, 5L), upper_distribution = uniform_distribution(10L, 20L), description = "The numbers of clusters to be evaluated." )
integer_range_parameter( id = "ks", default = c(3L, 15L), lower_distribution = uniform_distribution(1L, 5L), upper_distribution = uniform_distribution(10L, 20L), description = "The numbers of clusters to be evaluated." )
Define a logical parameter
logical_parameter(id, default, description = NULL, tuneable = TRUE)
logical_parameter(id, default, description = NULL, tuneable = TRUE)
id |
The name of the parameter. |
default |
The default value of the parameter. |
description |
An optional (but recommended) description of the parameter. |
tuneable |
Whether or not a parameter is tuneable. |
dynparam for an overview of all dynparam functionality.
logical_parameter( id = "scale", default = TRUE, description = "Whether or not to scale the input variables" )
logical_parameter( id = "scale", default = TRUE, description = "Whether or not to scale the input variables" )
Distributions are used for defining the domain of an integer_parameter()
or numeric_parameter()
.
normal_distribution(mean, sd, lower = -Inf, upper = Inf)
normal_distribution(mean, sd, lower = -Inf, upper = Inf)
mean |
Mean of the distribution |
sd |
Standard deviation of the distribution. |
lower |
An optional lower limit. |
upper |
An optional upper limit. |
dynparam for an overview of all dynparam functionality.
normal_distribution(mean = 0, sd = 1) normal_distribution(mean = 5, sd = 1, lower = 1, upper = 10)
normal_distribution(mean = 0, sd = 1) normal_distribution(mean = 5, sd = 1, lower = 1, upper = 10)
Define a numeric parameter
numeric_parameter(id, default, distribution, description = NULL, tuneable = TRUE)
numeric_parameter(id, default, distribution, description = NULL, tuneable = TRUE)
id |
The name of the parameter. |
default |
The default value of the parameter. |
distribution |
A distribution from which the parameter can be sampled. |
description |
An optional (but recommended) description of the parameter. |
tuneable |
Whether or not a parameter is tuneable. |
dynparam for an overview of all dynparam functionality.
numeric_parameter( id = "alpha", default = 0.5, distribution = uniform_distribution(0.0, 1.0), description = "Weighting parameter for distance function." ) numeric_parameter( id = "beta", default = 0.001, distribution = expuniform_distribution(1e-4, 1e-1), description = "Percentage decrease in age per iteration" )
numeric_parameter( id = "alpha", default = 0.5, distribution = uniform_distribution(0.0, 1.0), description = "Weighting parameter for distance function." ) numeric_parameter( id = "beta", default = 0.001, distribution = expuniform_distribution(1e-4, 1e-1), description = "Percentage decrease in age per iteration" )
Define a numeric range parameter
numeric_range_parameter(id, default, lower_distribution, upper_distribution, description = NULL, tuneable = TRUE)
numeric_range_parameter(id, default, lower_distribution, upper_distribution, description = NULL, tuneable = TRUE)
id |
The name of the parameter. |
default |
The default value of the parameter. |
lower_distribution |
A distribution from which the lower value of the range can be sampled. |
upper_distribution |
A distribution from which the upper value fo the range can be sampled. |
description |
An optional (but recommended) description of the parameter. |
tuneable |
Whether or not a parameter is tuneable. |
dynparam for an overview of all dynparam functionality.
numeric_range_parameter( id = "quantiles", default = c(0.1, 0.99), lower_distribution = uniform_distribution(0, 0.25), upper_distribution = uniform_distribution(0.9, 1), description = "The lower and upper quantile thresholds." )
numeric_range_parameter( id = "quantiles", default = c(0.1, 0.99), lower_distribution = uniform_distribution(0, 0.25), upper_distribution = uniform_distribution(0.9, 1), description = "The lower and upper quantile thresholds." )
Multiple parameters can be combined in a parameter set. The sections below contain information on how to create, serialise and process a parameter.
parameter(id, default, ..., description = NULL, tuneable = TRUE) ## S3 method for class 'parameter' as.list(x, ...) as_parameter(li) is_parameter(x) as_descriptive_tibble(x)
parameter(id, default, ..., description = NULL, tuneable = TRUE) ## S3 method for class 'parameter' as.list(x, ...) as_parameter(li) is_parameter(x) as_descriptive_tibble(x)
id |
The name of the parameter. |
default |
The default value of the parameter. |
... |
Extra fields to be saved in the parameter. |
description |
An optional (but recommended) description of the parameter. |
tuneable |
Whether or not a parameter is tuneable. |
x |
An object (parameter or distribution) to be converted. |
li |
A list to be converted into a parameter. |
character_parameter()
, integer_parameter()
, logical_parameter()
, numeric_parameter()
: Creating parameters with basic R data types.
integer_range_parameter()
, numeric_range_parameter()
: Create a discrete or continuous range parameter.
subset_parameter()
: A parameter containing a subset of a set of values.
parameter()
: An abstract function to be used by other parameter functions.
as.list(param)
: Converting a parameter to a list.
as_parameter(li)
: Converting a list back to a parameter.
is_parameter(x)
: Checking whether something is a parameter.
as_descriptive_tibble(param)
: Convert to a tibble containing meta information.
dynparam for an overview of all dynparam functionality.
int_param <- integer_parameter( id = "num_iter", default = 100L, distribution = expuniform_distribution(lower = 1L, upper = 10000L), description = "Number of iterations" ) print(int_param) li <- as.list(int_param) print(as_parameter(li)) subset_param <- subset_parameter( id = "dimreds", default = c("pca", "mds"), values = c("pca", "mds", "tsne", "umap", "ica"), description = "Which dimensionality reduction methods to apply (can be multiple)" ) int_range_param <- integer_range_parameter( id = "ks", default = c(3L, 15L), lower_distribution = uniform_distribution(1L, 5L), upper_distribution = uniform_distribution(10L, 20L), description = "The numbers of clusters to be evaluated" ) parameter_set( int_param, subset_param, int_range_param )
int_param <- integer_parameter( id = "num_iter", default = 100L, distribution = expuniform_distribution(lower = 1L, upper = 10000L), description = "Number of iterations" ) print(int_param) li <- as.list(int_param) print(as_parameter(li)) subset_param <- subset_parameter( id = "dimreds", default = c("pca", "mds"), values = c("pca", "mds", "tsne", "umap", "ica"), description = "Which dimensionality reduction methods to apply (can be multiple)" ) int_range_param <- integer_range_parameter( id = "ks", default = c(3L, 15L), lower_distribution = uniform_distribution(1L, 5L), upper_distribution = uniform_distribution(10L, 20L), description = "The numbers of clusters to be evaluated" ) parameter_set( int_param, subset_param, int_range_param )
Parameter set helper functions
parameter_set(..., parameters = NULL, forbidden = NULL) is_parameter_set(x) ## S3 method for class 'parameter_set' as.list(x, ...) as_parameter_set(li) get_defaults(x) sip(x, n = 1, as_tibble = TRUE) as_paramhelper(x)
parameter_set(..., parameters = NULL, forbidden = NULL) is_parameter_set(x) ## S3 method for class 'parameter_set' as.list(x, ...) as_parameter_set(li) get_defaults(x) sip(x, n = 1, as_tibble = TRUE) as_paramhelper(x)
... |
Parameters to wrap in a parameter set. |
parameters |
A list of parameters to wrap in a parameter set. |
forbidden |
States forbidden region of parameter via a character vector, which will be turned into an expression. |
x |
An object for which to check whether it is a parameter set. |
li |
A list to be converted into a parameter set. |
n |
Number of objects to return. |
as_tibble |
Whether or not to return as a tibble. |
get_defaults()
: Get all default parameters.
sip()
: It's like sample()
, but for parameter sets.
as_paramhelper()
: Convert a parameter set to a ParamHelpers object.
as.list()
: Converting a parameter set to a list.
as_parameter_set()
: Converting a list back to a parameter set.
is_parameter_set(x)
: Checking whether something is a parameter set.
dynparam for an overview of all dynparam functionality.
parameters <- parameter_set( integer_parameter( id = "num_iter", default = 100L, distribution = expuniform_distribution(lower = 1L, upper = 10000L), description = "Number of iterations" ), subset_parameter( id = "dimreds", default = c("pca", "mds"), values = c("pca", "mds", "tsne", "umap", "ica"), description = "Which dimensionality reduction methods to apply (can be multiple)" ), integer_range_parameter( id = "ks", default = c(3L, 15L), lower_distribution = uniform_distribution(1L, 5L), upper_distribution = uniform_distribution(10L, 20L), description = "The numbers of clusters to be evaluated" ) ) get_defaults(parameters) sip(parameters, n = 1)
parameters <- parameter_set( integer_parameter( id = "num_iter", default = 100L, distribution = expuniform_distribution(lower = 1L, upper = 10000L), description = "Number of iterations" ), subset_parameter( id = "dimreds", default = c("pca", "mds"), values = c("pca", "mds", "tsne", "umap", "ica"), description = "Which dimensionality reduction methods to apply (can be multiple)" ), integer_range_parameter( id = "ks", default = c(3L, 15L), lower_distribution = uniform_distribution(1L, 5L), upper_distribution = uniform_distribution(10L, 20L), description = "The numbers of clusters to be evaluated" ) ) get_defaults(parameters) sip(parameters, n = 1)
Define a range parameter
range_parameter(id, default, lower_distribution, upper_distribution, description = NULL, tuneable = TRUE)
range_parameter(id, default, lower_distribution, upper_distribution, description = NULL, tuneable = TRUE)
id |
The name of the parameter. |
default |
The default value of the parameter. |
lower_distribution |
A distribution from which the lower value of the range can be sampled. |
upper_distribution |
A distribution from which the upper value fo the range can be sampled. |
description |
An optional (but recommended) description of the parameter. |
tuneable |
Whether or not a parameter is tuneable. |
Define a subset parameter
subset_parameter(id, default, values, description = NULL, tuneable = TRUE)
subset_parameter(id, default, values, description = NULL, tuneable = TRUE)
id |
The name of the parameter. |
default |
The default value of the parameter. |
values |
A set of possible values. |
description |
An optional (but recommended) description of the parameter. |
tuneable |
Whether or not a parameter is tuneable. |
dynparam for an overview of all dynparam functionality.
subset_parameter( id = "dimreds", default = c("pca", "mds"), values = c("pca", "mds", "tsne", "umap", "ica"), description = "Which dimensionality reduction methods to apply (can be multiple)" )
subset_parameter( id = "dimreds", default = c("pca", "mds"), values = c("pca", "mds", "tsne", "umap", "ica"), description = "Which dimensionality reduction methods to apply (can be multiple)" )
Distributions are used for defining the domain of an integer_parameter()
or numeric_parameter()
.
uniform_distribution(lower, upper)
uniform_distribution(lower, upper)
lower |
Lower limit of the distribution. |
upper |
Upper limit of the distribution. |
dynparam for an overview of all dynparam functionality.
uniform_distribution(1, 10)
uniform_distribution(1, 10)