Skip to content

Commit 12077a2

Browse files
committed
allow all keras activations
1 parent 8adb5cc commit 12077a2

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ export(glm_grouped)
253253
export(has_multi_predict)
254254
export(importance_weights)
255255
export(is_varying)
256+
export(keras_activations)
256257
export(keras_mlp)
257258
export(keras_predict_classes)
258259
export(knit_engine_docs)

R/mlp.R

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,13 @@ keras_mlp <-
192192
seeds = sample.int(10^5, size = 3),
193193
...) {
194194

195-
act_funs <- c("linear", "softmax", "relu", "elu", "tanh")
196-
rlang::arg_match(activation, act_funs)
195+
allowed_keras_activation <- keras_activations()
196+
good_activation <- activation %in% allowed_keras_activation
197+
if (!all(good_activation)) {
198+
cli::cli_abort(
199+
"{.arg activation} should be one of: {allowed_activation}."
200+
)
201+
}
197202

198203
if (penalty > 0 & dropout > 0) {
199204
cli::cli_abort("Please use either dropout or weight decay.", call = NULL)
@@ -344,6 +349,19 @@ mlp_num_weights <- function(p, hidden_units, classes) {
344349
((p + 1) * hidden_units) + ((hidden_units+1) * classes)
345350
}
346351

352+
allowed_keras_activation <-
353+
c("elu", "exponential", "gelu", "hard_sigmoid", "linear", "relu", "selu",
354+
"sigmoid", "softmax", "softplus", "softsign", "swish", "tanh")
355+
356+
#' Activation functions for neural networks in keras
357+
#'
358+
#' @keywords internal
359+
#' @return A character vector of values.
360+
#' @export
361+
keras_activations <- function() {
362+
allowed_keras_activation
363+
}
364+
347365
## -----------------------------------------------------------------------------
348366

349367
#' @importFrom purrr map

man/keras_activations.Rd

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)