From 8cec72dac8b26c3858fffcb7a775da03360f3c6e Mon Sep 17 00:00:00 2001 From: Adam Kropp <30504149+akropp@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:03:05 -0400 Subject: [PATCH] (correctly) change Backward to use input instead of output --- src/mlpack/methods/ann/layer/ftswish.hpp | 2 +- src/mlpack/methods/ann/layer/ftswish_impl.hpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mlpack/methods/ann/layer/ftswish.hpp b/src/mlpack/methods/ann/layer/ftswish.hpp index 8679bd24d1..a8234cbb9f 100644 --- a/src/mlpack/methods/ann/layer/ftswish.hpp +++ b/src/mlpack/methods/ann/layer/ftswish.hpp @@ -89,7 +89,7 @@ class FTSwishType : public Layer * @param g The calculated gradient. */ void Backward(const MatType& input, - const MatType& output, + const MatType& /* output */, const MatType& gy, MatType& g); diff --git a/src/mlpack/methods/ann/layer/ftswish_impl.hpp b/src/mlpack/methods/ann/layer/ftswish_impl.hpp index 04d15dbb3f..fc9c438449 100644 --- a/src/mlpack/methods/ann/layer/ftswish_impl.hpp +++ b/src/mlpack/methods/ann/layer/ftswish_impl.hpp @@ -84,18 +84,18 @@ void FTSwishType::Forward(const MatType& input, MatType& output) template void FTSwishType::Backward( - const MatType& /* input */, - const MatType& output, + const MatType& input, + const MatType& /* output */, const MatType& gy, MatType& g) { #pragma omp for - for (size_t i = 0; i < (size_t) output.n_elem; ++i) + for (size_t i = 0; i < (size_t) input.n_elem; ++i) { - if (output(i) >= 0) + if (input(i) >= 0) { - const double fX = output(i) / (1 + std::exp(-output(i))); - const double sigmoidX = 1 / (1 + std::exp(-output(i))); + const double fX = input(i) / (1 + std::exp(-input(i))); + const double sigmoidX = 1 / (1 + std::exp(-input(i))); g(i) = gy(i) * (sigmoidX * (1 - fX) + fX);