Utility function to construct optimiser from keras, primarily for internal use.

get_keras_optimizer(
  optimizer = "adam",
  lr = 0.001,
  beta_1 = 0.9,
  beta_2 = 0.999,
  epsilon = 1e-07,
  decay = NULL,
  clipnorm = NULL,
  clipvalue = NULL,
  momentum = 0,
  nesterov = FALSE,
  rho = 0.95,
  global_clipnorm = NULL,
  use_ema = FALSE,
  ema_momentum = 0.99,
  ema_overwrite_frequency = NULL,
  jit_compile = TRUE,
  initial_accumultator_value = 0.1,
  amsgrad = FALSE,
  lr_power = -0.5,
  l1_regularization_strength = 0,
  l2_regularization_strength = 0,
  l2_shrinkage_regularization_strength = 0,
  beta = 0,
  centered = FALSE
)

Arguments

optimizer

(character(1))
Optimizer to construct, see details for those available. Default is "adam".

lr

(numeric(1))
Learning rate passed to all optimizers.

beta_1, beta_2

(numeric(1))
Passed to adamax, adam, and nadam.

epsilon

(numeric(1))
Passed to adadelta, adagrad, adam, adamax, nadam, rmsprop

decay, clipnorm, clipvalue, global_clipnorm

(numeric(1))
Passed to all optimizers.

momentum

(numeric(1))
Passed to rmsprop and sgd.

nesterov

(logical(1))
Passed to sgd.

rho

(numeric(1))
Passed to adadelta and rmsprop.

use_ema, jit_compile

(logical(1))
Passed to all optimizers.

ema_momentum, ema_overwrite_frequency

(numeric(1))
Passed to all optimizers.

initial_accumultator_value

(numeric(1))
Passed to adagrad and ftrl.

amsgrad

(logical(1))
Passed to adam and sgd.

lr_power, l1_regularization_strength, l2_regularization_strength, l2_shrinkage_regularization_strength, beta

(numeric(1))
Passed to ftrl.

centered

(logical(1))
Passed to rmsprop.

Examples

# \donttest{
if (requireNamespaces("keras")) {
  get_keras_optimizer()

  get_keras_optimizer(optimizer = "adamax", decay = 0.1, lr = 0.01)
}
#> List of 22
#>  $ python              : chr "/usr/local/bin/python3"
#>  $ libpython           : chr "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/config-3.12-darwin/libpython3.12.dylib"
#>  $ pythonhome          : chr "/Library/Frameworks/Python.framework/Versions/3.12:/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ pythonpath          : chr "/Users/runner/work/_temp/Library/reticulate/config:/Library/Frameworks/Python.framework/Versions/3.12/lib/pytho"| __truncated__
#>  $ prefix              : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ exec_prefix         : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ base_exec_prefix    : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ virtualenv          : chr ""
#>  $ virtualenv_activate : chr ""
#>  $ executable          : chr "/usr/local/bin/python3"
#>  $ base_executable     : chr "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12"
#>  $ version_string      : chr "3.12.2 (v3.12.2:6abddd9f6a, Feb  6 2024, 17:02:06) [Clang 13.0.0 (clang-1300.0.29.30)]"
#>  $ version             : chr "3.12"
#>  $ architecture        : chr "64bit"
#>  $ anaconda            : logi FALSE
#>  $ conda               : chr "False"
#>  $ numpy               : NULL
#>  $ required_module     : chr "tensorflow"
#>  $ required_module_path: NULL
#>  $ available           : logi TRUE
#>  $ python_versions     : chr [1:2] "/usr/local/bin/python3" "/Library/Frameworks/Python.framework/Versions/3.12/bin/python"
#>  $ forced              : NULL
#>  - attr(*, "class")= chr "py_config"
#> Error: Python module tensorflow.keras was not found.
#> 
#> Detected Python configuration:
#> 
#> 
# }