test_optim()
function is useful to visualize how optimizers solve the
minimization problem by showing the convergence path using a test function.
User can choose any test optimization
functions
provided by torchopt
:
"beale"
, "booth"
, "bukin_n6"
, "easom"
, "goldstein_price"
,
"himmelblau"
, "levi_n13"
, "matyas"
, "rastrigin"
,
"rosenbrock"
, and "sphere"
.
Besides these functions, users can pass any function that receives two numerical values and returns a scalar.
Optimization functions are useful to evaluate characteristics of optimization algorithms, such as convergence rate, precision, robustness, and performance. These functions give an idea about the different situations that optimization algorithms can face.
Function test_function()
plot the 2D-space of a test optimization function.
test_optim(
optim,
...,
opt_hparams = list(),
test_fn = "beale",
steps = 200,
pt_start_color = "#5050FF7F",
pt_end_color = "#FF5050FF",
ln_color = "#FF0000FF",
ln_weight = 2,
bg_xy_breaks = 100,
bg_z_breaks = 32,
bg_palette = "viridis",
ct_levels = 10,
ct_labels = FALSE,
ct_color = "#FFFFFF7F",
plot_each_step = FALSE
)
No return value, called for producing animated gifs
Torch optimizer function.
Additional parameters (passed to image
function).
A list with optimizer initialization parameters (default: list()
).
If missing, for each optimizer its individual defaults will be used.
A test function (default "beale"
). You can also pass
a list with 2 elements. The first should be a function that will be optimized
and the second is a function that returns a named vector with x0
, y0
(the starting points) and xmax
, xmin
, ymax
and ymin
(the domain).
An example: c(x0 = x0, y0 = y0, xmax = 5, xmin = -5, ymax = 5, ymin = -5)
Number of steps to run (default 200
).
Starting point color (default "#5050FF7F"
)
Ending point color (default "#FF5050FF"
)
Line path color (default "#FF0000FF"
)
Line path weight (default 2
)
Background X and Y resolution (default 100
)
Background Z resolution (default 32
)
Background palette (default "viridis"
)
Contour levels (default 10
)
Should show contour labels? (default FALSE
)
Contour color (default "#FFFFFF7F"
)
Should output each step? (default FALSE
)
Rolf Simoes, rolf.simoes@inpe.br