test_optim: Test optimization function

View source: R/utils-testopt.R

test_optimR Documentation

Test optimization function

Description

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.

Usage

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
)

Arguments

optim

Torch optimizer function.

...

Additional parameters (passed to image function).

opt_hparams

A list with optimizer initialization parameters (default: list()). If missing, for each optimizer its individual defaults will be used.

test_fn

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)

steps

Number of steps to run (default 200).

pt_start_color

Starting point color (default "#5050FF7F")

pt_end_color

Ending point color (default "#FF5050FF")

ln_color

Line path color (default "#FF0000FF")

ln_weight

Line path weight (default 2)

bg_xy_breaks

Background X and Y resolution (default 100)

bg_z_breaks

Background Z resolution (default 32)

bg_palette

Background palette (default "viridis")

ct_levels

Contour levels (default 10)

ct_labels

Should show contour labels? (default FALSE)

ct_color

Contour color (default "#FFFFFF7F")

plot_each_step

Should output each step? (default FALSE)

Value

No return value, called for producing animated gifs

Author(s)

Rolf Simoes, rolf.simoes@inpe.br


torchopt documentation built on June 7, 2023, 6:10 p.m.