Fixes for failing test

This commit is contained in:
Anush V Kini
2021-02-14 19:31:57 +05:30
parent 517a3a5e8d
commit 990803af2b
2 changed files with 22 additions and 7 deletions
@@ -27,6 +27,7 @@
#include <mlpack/methods/ann/activation_functions/elliot_function.hpp>
#include <mlpack/methods/ann/activation_functions/elish_function.hpp>
#include <mlpack/methods/ann/activation_functions/gaussian_function.hpp>
#include <mlpack/methods/ann/activation_functions/hard_swish_function.hpp>
namespace mlpack {
namespace ann /** Artificial Neural Network. */ {
@@ -50,6 +51,7 @@ namespace ann /** Artificial Neural Network. */ {
* - ELiSHLayer
* - ElliotLayer
* - GaussianLayer
* - HardSwishLayer
*
* @tparam ActivationFunction Activation function used for the embedding layer.
* @tparam InputDataType Type of the input data (arma::colvec, arma::mat,
@@ -277,6 +279,17 @@ template <
using GaussianFunctionLayer = BaseLayer<
ActivationFunction, InputDataType, OutputDataType>;
/**
* Standard HardSwish-Layer using the HardSwish activation function.
*/
template <
class ActivationFunction = HardSwishFunction,
typename InputDataType = arma::mat,
typename OutputDataType = arma::mat
>
using HardSwishFunctionLayer = BaseLayer<
ActivationFunction, InputDataType, OutputDataType>;
} // namespace ann
} // namespace mlpack
@@ -32,6 +32,7 @@
#include <mlpack/methods/ann/activation_functions/spline_function.hpp>
#include <mlpack/methods/ann/activation_functions/poisson1_function.hpp>
#include <mlpack/methods/ann/activation_functions/gaussian_function.hpp>
#include <mlpack/methods/ann/activation_functions/hard_swish_function.hpp>
#include "catch.hpp"
@@ -1143,14 +1144,15 @@ TEST_CASE("HardSwishFunctionTest", "[ActivationFunctionsTest]")
// Randomly generated data.
const arma::colvec activationData("3.6544 -1.9714 -5.2277 1.5448 2.1164");
// Calculated from torch.nn.Hardswish.
const arma::colvec desiredActivations("3.6544 -0.3380 0 1.1701 1.8047");
// Hand Calculated Values. from torch.nn.Hardswish.
const arma::colvec desiredActivations("3.6544 -0.3379636 0.0 \
1.1701345 1.8047248");
// Hand Calculated Values.
const arma::colvec desiredDerivatives("1 ");
const arma::colvec desiredDerivatives("1.0 0.38734546 0.5 \
0.89004483 1.1015749");
CheckSoftminActivationCorrect(activationData,
desiredActivations);
CheckSoftminDerivativeCorrect(activationData,
desiredDerivatives);
CheckActivationCorrect<HardSwishFunction>(activationData, desiredActivations);
CheckDerivativeCorrect<HardSwishFunction>
(desiredActivations, desiredDerivatives);
}