| register_keras_optimizer | R Documentation |
Allows users to register a custom optimizer function so it can be used by
name within kerasnip model specifications and tuned with dials.
register_keras_optimizer(name, optimizer_fn)
name |
The name to register the optimizer under (character). |
optimizer_fn |
The optimizer function. It should return a Keras optimizer object. |
Registered optimizers are stored in an internal environment. When a model is
compiled, kerasnip will first check this internal registry for an optimizer
matching the provided name before checking the keras3 package.
The optimizer_fn can be a simple function or a partially applied function
using purrr::partial(). This is useful for creating versions of Keras
optimizers with specific settings.
No return value, called for side effects.
register_keras_loss(), register_keras_metric()
if (requireNamespace("keras3", quietly = TRUE)) {
# Register a custom version of Adam with a different default beta_1
my_adam <- purrr::partial(keras3::optimizer_adam, beta_1 = 0.8)
register_keras_optimizer("my_adam", my_adam)
# Now "my_adam" can be used as a string in a model spec, e.g.,
# my_model_spec(compile_optimizer = "my_adam")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.