Alternating Optimization
Description
This function performs alternating optimization of the function f
.
Usage
ao(
f,
p,
...,
partition = as.list(1:length(p)),
base_optimizer = optimizeR::Optimizer$new("stats::optim"),
iterations = 10,
tolerance = 1e-06,
f_partition = vector(mode = "list", length = length(partition)),
joint_end = FALSE,
verbose = FALSE
)
Arguments
f |
A function to be optimized, returning a single numeric .
The first argument of f must be a numeric of the same length as
p followed by any other arguments specified by the ...
argument.
|
p |
A numeric vector, the starting parameter values for the optimization.
|
... |
Additional arguments to be passed to f .
|
partition |
A list of vectors of indices of p , specifying the partition of
the parameter vector in the alternating optimization process.
The default is as.list(1:length(p)) , i.e. each parameter is
optimized separately.
Parameter indices can be members of multiple subsets.
|
base_optimizer |
An Optimizer object, which can be created via
Optimizer .
It numerically solves the optimization problems in the partitions.
|
iterations |
An integer , the maximum number of iterations through
partitions before the alternating optimization process is terminated.
Can also be Inf , in which case tolerance is responsible for the
termination.
The default is 10 .
|
tolerance |
A non-negative numeric . The alternating optimization terminates
prematurely (i.e., before interations is reached) if the euclidean
distance between the current estimate and the one from the last iteration is
smaller than tolerance .
The default is 1e-6 .
|
f_partition |
A list of the same length as partition .
The i -th element can be a function that computes the value of
f for the i -th parameter set defined in partition .
The function must be of the form
function(theta_part, theta_rest, ...) , where
-
theta_part receives the parameter set for the current partition
(this argument can be named differently),
-
theta_rest receives the remaining parameters
(this argument must be named theta_rest ),
-
... receives the additional arguments to f .
Alternatively, it can be NULL , in which case f is used.
|
joint_end |
If TRUE , the parameter set is optimized jointly after the alternating
optimization process is terminated.
The default is FALSE .
|
verbose |
If TRUE , full tracing details are printed during the alternating
optimization process.
The default is FALSE .
|
Value
A list
with the elements
-
estimate
, the optimal parameter vector found,
-
value
, the value of f
at estimate
,
-
sequence
, a data.frame
of the function values, estimates and
computation times in the single iterations and partitions,
and seconds
, the overall computation time in seconds.
Examples
# definition of the Himmelblau function
himmelblau <- function(x) (x[1]^2 + x[2] - 11)^2 + (x[1] + x[2]^2 - 7)^2
# alternating minimization separately for x_1 and x_2
# parameter restriction: -5 <= x_1, x_2 <= 5
ao(
f = himmelblau, p = c(0, 0), partition = list(1, 2), iterations = Inf,
base_optimizer = optimizeR::Optimizer$new(
which = "stats::optim", lower = -5, upper = 5, method = "L-BFGS-B"
)
)
[Package
ao version 0.3.3
Index]