From d91c5f0f3106aad80bb1b2d29984aa8dd7489192 Mon Sep 17 00:00:00 2001 From: Adam Kropp <30504149+akropp@users.noreply.github.com> Date: Wed, 8 Nov 2023 08:14:11 -0500 Subject: [PATCH] Update src/mlpack/methods/ann/layer/c_relu_impl.hpp Co-authored-by: Ryan Curtin --- src/mlpack/methods/ann/layer/c_relu_impl.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mlpack/methods/ann/layer/c_relu_impl.hpp b/src/mlpack/methods/ann/layer/c_relu_impl.hpp index c6b668a0ef..a687af81c8 100644 --- a/src/mlpack/methods/ann/layer/c_relu_impl.hpp +++ b/src/mlpack/methods/ann/layer/c_relu_impl.hpp @@ -87,10 +87,12 @@ void CReLUType::Backward( const MatType& gy, MatType& g) { - // while it doesn't really matter if what we choose for the gradient at exactly 0, since we have the - // discontinuity from -1 to 1 between 0- and 0+, it seems cleaner to set the gradient at x=0 to 0 - // instead of picking either +1 or -1. - g = gy.rows(0, input.n_rows-1) % (input > 0) - gy.rows(input.n_rows, input.n_rows * 2 - 1) % (input < 0); + // While it doesn't really matter if what we choose for the gradient at + // exactly 0, since we have the discontinuity from -1 to 1 between 0- and 0+, + // it seems cleaner to set the gradient at x=0 to 0 instead of picking either + // +1 or -1. + g = gy.rows(0, input.n_rows - 1) % (input > 0) - + gy.rows(input.n_rows, input.n_rows * 2 - 1) % (input < 0); } template