Method new()
Initializes a new Optimizer object.
Usage
Optimizer$new(which, ...)
Arguments
which
A character, either one of optimizer_dictionary$keys or
"custom" (in which case $definition() must be used to
define the optimizer details).
...
Optionally additional arguments to be passed to the optimizer algorithm.
Without specifications, default values are used.
Returns
A new Optimizer object.
Method definition()
Defines an optimizer.
Usage
Optimizer$definition(
algorithm,
arg_objective,
arg_initial,
out_value,
out_parameter,
direction
)
Arguments
algorithm
A function, the optimization algorithm.
arg_objective
A character, the argument name for the objective function in
algorithm.
arg_initial
A character, the argument name for the initial values in
algorithm.
out_value
A character, the element name for the optimal function value in
the output list of algorithm.
out_parameter
A character, the element name for the optimal parameters in the
output list of algorithm.
direction
Either "min" (if the optimizer minimizes) or "max"
(if the optimizer maximizes).
Returns
Invisibly the Optimizer object.
Method set_arguments()
Sets optimizer arguments.
Usage
Optimizer$set_arguments(...)
Arguments
...
Optionally additional arguments to be passed to the optimizer algorithm.
Without specifications, default values are used.
Returns
The Optimizer object.
Method validate()
Validates the Optimizer object. A time limit in seconds for
the optimization can be set via the $seconds field.
Usage
Optimizer$validate(
objective = optimizeR::test_objective,
initial = round(stats::rnorm(2)),
...,
direction = "min"
)
Arguments
objective
A function to be optimized that
has at least one argument that receives a numeric vector
and returns a single numeric value.
Alternatively, it can also be a Objective object for more
flexibility.
initial
A numeric vector with starting parameter values for the optimization.
...
Optionally additional arguments to be passed to the optimizer algorithm.
Without specifications, default values are used.
direction
Either "min" for minimization or "max" for maximization.
Returns
The Optimizer object.
Method minimize()
Performing minimization.
Usage
Optimizer$minimize(objective, initial, ...)
Arguments
objective
A function to be optimized that
has at least one argument that receives a numeric vector
and returns a single numeric value.
Alternatively, it can also be a Objective object for more
flexibility.
initial
A numeric vector with starting parameter values for the optimization.
...
Optionally additional arguments to be passed to the optimizer algorithm.
Without specifications, default values are used.
Returns
A named list, containing at least these five elements:
value
A numeric, the minimum function value.
parameter
A numeric vector, the parameter vector
where the minimum is obtained.
seconds
A numeric, the optimization time in seconds.
initial
A numeric, the initial parameter values.
error
Either TRUE if an error occurred, or FALSE, else.
Appended are additional output elements of the optimizer.
If an error occurred, then the error message is also appended as element
error_message.
If the time limit was exceeded, this also counts as an error. In addition,
the flag time_out = TRUE is appended.
Examples
Optimizer$new("stats::nlm")$
minimize(objective = function(x) x^4 + 3*x - 5, initial = 2)
Method maximize()
Performing maximization.
Usage
Optimizer$maximize(objective, initial, ...)
Arguments
objective
A function to be optimized that
has at least one argument that receives a numeric vector
and returns a single numeric value.
Alternatively, it can also be a Objective object for more
flexibility.
initial
A numeric vector with starting parameter values for the optimization.
...
Optionally additional arguments to be passed to the optimizer algorithm.
Without specifications, default values are used.
Returns
A named list, containing at least these five elements:
value
A numeric, the maximum function value.
parameter
A numeric vector, the parameter vector
where the maximum is obtained.
seconds
A numeric, the optimization time in seconds.
initial
A numeric, the initial parameter values.
error
Either TRUE if an error occurred, or FALSE, else.
Appended are additional output elements of the optimizer.
If an error occurred, then the error message is also appended as element
error_message.
If the time limit was exceeded, this also counts as an error. In addition,
the flag time_out = TRUE is appended.
Examples
Optimizer$new("stats::nlm")$
maximize(objective = function(x) -x^4 + 3*x - 5, initial = 2)
Performing minimization or maximization.
Usage
Optimizer$optimize(objective, initial, direction = "min", ...)
Arguments
objective
A function to be optimized that
has at least one argument that receives a numeric vector
and returns a single numeric value.
Alternatively, it can also be a Objective object for more
flexibility.
initial
A numeric vector with starting parameter values for the optimization.
direction
Either "min" for minimization or "max" for maximization.
...
Optionally additional arguments to be passed to the optimizer algorithm.
Without specifications, default values are used.
Returns
A named list, containing at least these five elements:
value
A numeric, the maximum function value.
parameter
A numeric vector, the parameter vector
where the maximum is obtained.
seconds
A numeric, the optimization time in seconds.
initial
A numeric, the initial parameter values.
error
Either TRUE if an error occurred, or FALSE, else.
Appended are additional output elements of the optimizer.
If an error occurred, then the error message is also appended as element
error_message.
If the time limit was exceeded, this also counts as an error. In addition,
the flag time_out = TRUE is appended.
Examples
objective <- function(x) -x^4 + 3*x - 5
optimizer <- Optimizer$new("stats::nlm")
optimizer$optimize(objective = objective, initial = 2, direction = "min")
optimizer$optimize(objective = objective, initial = 2, direction = "max")
Prints the optimizer label.
Usage
Optimizer$print(...)
Arguments
...
Optionally additional arguments to be passed to the optimizer algorithm.
Without specifications, default values are used.
Returns
Invisibly the Optimizer object.
Method clone()
The objects of this class are cloneable with this method.
Usage
Optimizer$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.