This function performs alternating optimization of the function f
.
Usage
ao(
f,
p,
...,
partition = as.list(1:length(p)),
base_optimizer = optimizeR::optimizer_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 singlenumeric
. The first argument off
must be anumeric
of the same length asp
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 ofp
, specifying the partition in the alternating optimization process. The default isas.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 specified viadefine_optimizer
. It numerically solves the optimization problems in the partitions. The default optimizer isoptimizer_optim
.- iterations
An
integer
, the maximum number of iterations throughpartitions
before the alternating optimization process is terminated. Can also beInf
, in which casetolerance
is responsible for the termination. The default is10
.- tolerance
A non-negative
numeric
. The alternating optimization terminates prematurely (i.e., beforeinterations
is reached) if the euclidean distance between the current estimate and the one from the last iteration is smaller thantolerance
. The default is1e-6
.- f_partition
A
list
of the same length aspartition
. Thei
-th element can be afunction
that computes the value off
for thei
-th parameter set defined inpartition
. Thefunction
must be of the formfunction(theta_part, theta_rest, ...)
, wheretheta_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 namedtheta_rest
),...
receives the additional arguments tof
. Alternatively, it can beNULL
, in which casef
is used.
- joint_end
If
TRUE
, the parameter set is optimized jointly after the alternating optimization process is terminated. The default isFALSE
.- verbose
If
TRUE
, full tracing details are printed during the alternating optimization process. The default isFALSE
.
Value
A list
with the elements
estimate
, the optimal parameter vector found,value
, the value off
atestimate
,sequence
, adata.frame
of the function values, estimates and computation times in the single iterations and partitions,and
seconds
, the overall computation time in seconds.
Examples
### minimization of the Himmelblau function
### alternating optimization separately for x_1 and x_2
### parameter restriction: -5 <= x_1, x_2 <= 5
himmelblau <- function(x) (x[1]^2 + x[2] - 11)^2 + (x[1] + x[2]^2 - 7)^2
ao(
f = himmelblau, p = c(0, 0), partition = list(1, 2), iterations = Inf,
base_optimizer = optimizeR::optimizer_optim(
lower = -5, upper = 5, method = "L-BFGS-B"
)
)
#> $value
#> [1] 1.940035e-12
#>
#> $estimate
#> [1] 3.584428 -1.848126
#>
#> $sequence
#> iteration partition value seconds p1 p2
#> 1 0 NA 1.700000e+02 0.0000000000 0.000000 0.000000
#> 2 1 1 1.327270e+01 0.0003359318 3.395691 0.000000
#> 3 1 2 1.743666e+00 0.0003166199 3.395691 -1.803183
#> 4 2 1 2.847292e-02 0.0002729893 3.581412 -1.803183
#> 5 2 2 4.687472e-04 0.0002295971 3.581412 -1.847412
#> 6 3 1 7.368063e-06 0.0003387928 3.584381 -1.847412
#> 7 3 2 1.157612e-07 0.0001697540 3.584381 -1.848115
#> 8 4 1 1.900153e-09 0.0001718998 3.584427 -1.848115
#> 9 4 2 4.221429e-11 0.0001406670 3.584427 -1.848126
#> 10 5 1 3.598278e-12 0.0001335144 3.584428 -1.848126
#> 11 5 2 1.940035e-12 0.0001347065 3.584428 -1.848126
#>
#> $seconds
#> [1] 0.002244473
#>