src/mlpack/tests/activation_functions_test.cpp
void CheckHardShrinkDerivativeCorrect(const arma::colvec input,
                                      const arma::colvec target)
{
  HardShrink<> hardshrink;

  // Test the calculation of the derivatives using the entire vector as input.
  arma::colvec derivatives;

  // This error vector will be set to 1 to get the derivatives.
  arma::colvec error = arma::ones<arma::colvec>(input.n_elem);
  hardshrink.Backward(input, error, derivatives);
  for (size_t i = 0; i < derivatives.n_elem; i++)
  {
    BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3);
  }
}
/**
 * Implementation of the HardShrink activation function derivative test.
 * The derivative function is implemented as HardShrink layer in the file
 * hardshrink.hpp
 *
 * @param input Input data used for evaluating the HardShrink activation
 * function.
 * @param target Target data used to evaluate the HardShrink activation.
 */
Implementation of the HardShrink activation function derivative test.
The derivative function is implemented as HardShrink layer in the file
hardshrink.hpp

@param input Input data used for evaluating the HardShrink activation
function.
@param target Target data used to evaluate the HardShrink activation.
Implementation of the HardShrink activation function derivative test . The derivative function is implemented as HardShrink layer in the file hardshrink . hpp @param input Input data used for evaluating the HardShrink activation function . @param target Target data used to evaluate the HardShrink activation .
void CheckHardShrinkDerivativeCorrect(const arma::colvec input,
                                      const arma::colvec target)
{
  HardShrink<> hardshrink;
  arma::colvec derivatives;
  arma::colvec error = arma::ones<arma::colvec>(input.n_elem);
  hardshrink.Backward(input, error, derivatives);
  for (size_t i = 0; i < derivatives.n_elem; i++)
  {
    BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3);
  }
}
void CheckHardShrinkDerivativeCorrect ( const arma :: colvec input , const arma :: colvec target ) { HardShrink < > hardshrink ; arma :: colvec derivatives ; arma :: colvec error = arma :: ones < arma :: colvec > ( input . n_elem ) ; hardshrink . Backward ( input , error , derivatives ) ; for ( size_t i = 0 ; i < derivatives . n_elem ; i ++ ) { BOOST_REQUIRE_CLOSE ( derivatives . at ( i ) , target . at ( i ) , 1e-3 ) ; } }
Implementation of the HardShrink activation function derivative test.
Implementation of the HardShrink activation function derivative test .
// Test the calculation of the derivatives using the entire vector as input. // This error vector will be set to 1 to get the derivatives.