src/mlpack/tests/ann_layer_test.cpp
BOOST_AUTO_TEST_CASE(SimpleAlphaDropoutLayerTest)
{
  // Initialize the probability of setting a value to alphaDash.
  const double p = 0.2;

  // Initialize the input parameter having a mean nearabout 0
  // and variance nearabout 1.
  arma::mat input = arma::randn<arma::mat>(1000, 1);

  AlphaDropout<> module(p);
  module.Deterministic() = false;

  // Test the Forward function when training phase.
  arma::mat output;
  module.Forward(input, output);
  // Check whether mean remains nearly same.
  BOOST_REQUIRE_LE(
      arma::as_scalar(arma::abs(arma::mean(input) - arma::mean(output))), 0.1);

  // Check whether variance remains nearly same.
  BOOST_REQUIRE_LE(
      arma::as_scalar(arma::abs(arma::var(input) - arma::var(output))), 0.1);

  // Test the Backward function when training phase.
  arma::mat delta;
  module.Backward(input, input, delta);
  BOOST_REQUIRE_LE(
      arma::as_scalar(arma::abs(arma::mean(delta) - 0)), 0.05);

  // Test the Forward function when testing phase.
  module.Deterministic() = true;
  module.Forward(input, output);
  BOOST_REQUIRE_EQUAL(arma::accu(input), arma::accu(output));
}
/*
 * Perform test to check whether mean and variance remain nearly same
 * after AlphaDropout.
 */
Perform test to check whether mean and variance remain nearly same
after AlphaDropout.
Perform test to check whether mean and variance remain nearly same after AlphaDropout .
BOOST_AUTO_TEST_CASE(SimpleAlphaDropoutLayerTest)
{
  const double p = 0.2;
  arma::mat input = arma::randn<arma::mat>(1000, 1);
  AlphaDropout<> module(p);
  module.Deterministic() = false;
  arma::mat output;
  module.Forward(input, output);
  BOOST_REQUIRE_LE(
      arma::as_scalar(arma::abs(arma::mean(input) - arma::mean(output))), 0.1);
  BOOST_REQUIRE_LE(
      arma::as_scalar(arma::abs(arma::var(input) - arma::var(output))), 0.1);
  arma::mat delta;
  module.Backward(input, input, delta);
  BOOST_REQUIRE_LE(
      arma::as_scalar(arma::abs(arma::mean(delta) - 0)), 0.05);
  module.Deterministic() = true;
  module.Forward(input, output);
  BOOST_REQUIRE_EQUAL(arma::accu(input), arma::accu(output));
}
BOOST_AUTO_TEST_CASE ( SimpleAlphaDropoutLayerTest ) { const double p = 0.2 ; arma :: mat input = arma :: randn < arma :: mat > ( 1000 , 1 ) ; AlphaDropout < > module ( p ) ; module . Deterministic ( ) = false ; arma :: mat output ; module . Forward ( input , output ) ; BOOST_REQUIRE_LE ( arma :: as_scalar ( arma :: abs ( arma :: mean ( input ) - arma :: mean ( output ) ) ) , 0.1 ) ; BOOST_REQUIRE_LE ( arma :: as_scalar ( arma :: abs ( arma :: var ( input ) - arma :: var ( output ) ) ) , 0.1 ) ; arma :: mat delta ; module . Backward ( input , input , delta ) ; BOOST_REQUIRE_LE ( arma :: as_scalar ( arma :: abs ( arma :: mean ( delta ) - 0 ) ) , 0.05 ) ; module . Deterministic ( ) = true ; module . Forward ( input , output ) ; BOOST_REQUIRE_EQUAL ( arma :: accu ( input ) , arma :: accu ( output ) ) ; }
Perform test to check whether mean and variance remain nearly same
 after AlphaDropout.
Perform test to check whether mean and variance remain nearly same after AlphaDropout .
// Initialize the probability of setting a value to alphaDash. // Initialize the input parameter having a mean nearabout 0 // and variance nearabout 1. // Test the Forward function when training phase. // Check whether mean remains nearly same. // Check whether variance remains nearly same. // Test the Backward function when training phase. // Test the Forward function when testing phase.