src/mlpack/tests/ann_layer_test.cpp
/**
 * Perform dropout x times using ones as input, sum the number of ones and
 * validate that the layer is producing approximately the correct number of
 * ones.
 */
Perform dropout x times using ones as input, sum the number of ones and
validate that the layer is producing approximately the correct number of
ones.
Perform dropout x times using ones as input sum the number of ones and validate that the layer is producing approximately the correct number of ones .
BOOST_AUTO_TEST_CASE(DropoutProbabilityTest)
{
  arma::mat input = arma::ones(1500, 1);
  const size_t iterations = 10;
  double probability[5] = { 0.1, 0.3, 0.4, 0.7, 0.8 };
  for (size_t trial = 0; trial < 5; ++trial)
  {
    double nonzeroCount = 0;
    for (size_t i = 0; i < iterations; ++i)
    {
      Dropout<> module(probability[trial]);
      module.Deterministic() = false;
      arma::mat output;
      module.Forward(input, output);
      arma::uvec nonzero = arma::find(output);
      nonzeroCount += nonzero.n_elem;
    }
    const double expected = input.n_elem * (1 - probability[trial]) *
        iterations;
    const double error = fabs(nonzeroCount - expected) / expected;
    BOOST_REQUIRE_LE(error, 0.15);
  }
}
BOOST_AUTO_TEST_CASE ( DropoutProbabilityTest ) { arma :: mat input = arma :: ones ( 1500 , 1 ) ; const size_t iterations = 10 ; double probability [ 5 ] = { 0.1 , 0.3 , 0.4 , 0.7 , 0.8 } ; for ( size_t trial = 0 ; trial < 5 ; ++ trial ) { double nonzeroCount = 0 ; for ( size_t i = 0 ; i < iterations ; ++ i ) { Dropout < > module ( probability [ trial ] ) ; module . Deterministic ( ) = false ; arma :: mat output ; module . Forward ( input , output ) ; arma :: uvec nonzero = arma :: find ( output ) ; nonzeroCount += nonzero . n_elem ; } const double expected = input . n_elem * ( 1 - probability [ trial ] ) * iterations ; const double error = fabs ( nonzeroCount - expected ) / expected ; BOOST_REQUIRE_LE ( error , 0.15 ) ; } }
Perform dropout x times using ones as input, sum the number of ones and
 validate that the layer is producing approximately the correct number of
 ones.
Perform dropout x times using ones as input sum the number of ones and validate that the layer is producing approximately the correct number of ones .
// Return a column vector containing the indices of elements of X that // are non-zero, we just need the number of non-zero values.