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)