From a389184f485eaf9d4feda9c19b361ab293108a06 Mon Sep 17 00:00:00 2001 From: Adam Kropp <30504149+akropp@users.noreply.github.com> Date: Tue, 14 Nov 2023 07:32:13 -0500 Subject: [PATCH] Update elish_function.hpp --- .../ann/activation_functions/elish_function.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/mlpack/methods/ann/activation_functions/elish_function.hpp b/src/mlpack/methods/ann/activation_functions/elish_function.hpp index 8f13b00a7c..4eced57122 100644 --- a/src/mlpack/methods/ann/activation_functions/elish_function.hpp +++ b/src/mlpack/methods/ann/activation_functions/elish_function.hpp @@ -111,11 +111,16 @@ class ElishFunction { // simplified the x>=0 part to be in terms of x and y -- maybe // the x<0 part can be as well? + dy.set_size(arma::size(y)); arma::uvec ltz = arma::find(x < 0); - InputVecType ex = arma::exp(x(ltz)); - dy(ltz) = (ex - 2 / (1 + ex) + 2 / arma::pow(1 + ex, 2)); + if (!ltz.empty()) { + InputVecType ex = arma::exp(x(ltz)); + dy(ltz) = (ex - 2 / (1 + ex) + 2 / arma::pow(1 + ex, 2)); + } arma::uvec gtz = arma::find(x > 0); - dy(gtz) = (y(gtz) / x(gtz)) % (1.0 + x(gtz) - y(gtz)); + if (!gtz.empty()) { + dy(gtz) = (y(gtz) / x(gtz)) % (1.0 + x(gtz) - y(gtz)); + } dy(arma::find(x == 0)).fill(0.5); // the expression above is indeterminate at 0, even though // the expression solely in terms of x is defined (= 0.5)