src/mlpack/tests/activation_functions_test.cpp
BOOST_AUTO_TEST_CASE(CReLUFunctionTest)
{
  const arma::colvec desiredActivations("0 3.2 4.5 0 \
                                         1 0 2 0 2 0 0 \
                                         100.2 0 1 0 0");

  const arma::colvec desiredDerivatives("0 0 0 0 \
                                         0 0 0 0");
  CReLU<> crelu;
  // Test the activation function using the entire vector as input.
  arma::colvec activations;
  crelu.Forward(activationData, activations);
  arma::colvec derivatives;
  // This error vector will be set to 1 to get the derivatives.
  arma::colvec error = arma::ones<arma::colvec>(desiredActivations.n_elem);
  crelu.Backward(desiredActivations, error, derivatives);
  for (size_t i = 0; i < activations.n_elem; i++)
  {
    BOOST_REQUIRE_CLOSE(activations.at(i), desiredActivations.at(i), 1e-3);
  }
  for (size_t i = 0; i < derivatives.n_elem; i++)
  {
    BOOST_REQUIRE_CLOSE(derivatives.at(i), desiredDerivatives.at(i), 1e-3);
  }
}
/**
 * Basic test of the CReLU function.
 */
Basic test of the CReLU function.
Basic test of the CReLU function .
BOOST_AUTO_TEST_CASE(CReLUFunctionTest)
{
  const arma::colvec desiredActivations("0 3.2 4.5 0 \
                                         1 0 2 0 2 0 0 \
                                         100.2 0 1 0 0");
  const arma::colvec desiredDerivatives("0 0 0 0 \
                                         0 0 0 0");
  CReLU<> crelu;
  arma::colvec activations;
  crelu.Forward(activationData, activations);
  arma::colvec derivatives;
  arma::colvec error = arma::ones<arma::colvec>(desiredActivations.n_elem);
  crelu.Backward(desiredActivations, error, derivatives);
  for (size_t i = 0; i < activations.n_elem; i++)
  {
    BOOST_REQUIRE_CLOSE(activations.at(i), desiredActivations.at(i), 1e-3);
  }
  for (size_t i = 0; i < derivatives.n_elem; i++)
  {
    BOOST_REQUIRE_CLOSE(derivatives.at(i), desiredDerivatives.at(i), 1e-3);
  }
}
BOOST_AUTO_TEST_CASE ( CReLUFunctionTest ) { const arma :: colvec desiredActivations ( " \
 \
 " ) ; const arma :: colvec desiredDerivatives ( " \
 " ) ; CReLU < > crelu ; arma :: colvec activations ; crelu . Forward ( activationData , activations ) ; arma :: colvec derivatives ; arma :: colvec error = arma :: ones < arma :: colvec > ( desiredActivations . n_elem ) ; crelu . Backward ( desiredActivations , error , derivatives ) ; for ( size_t i = 0 ; i < activations . n_elem ; i ++ ) { BOOST_REQUIRE_CLOSE ( activations . at ( i ) , desiredActivations . at ( i ) , 1e-3 ) ; } for ( size_t i = 0 ; i < derivatives . n_elem ; i ++ ) { BOOST_REQUIRE_CLOSE ( derivatives . at ( i ) , desiredDerivatives . at ( i ) , 1e-3 ) ; } }
Basic test of the CReLU function.
Basic test of the CReLU function .
// Test the activation function using the entire vector as input. // This error vector will be set to 1 to get the derivatives.