Tudat/Mathematics/Statistics/UnitTests/unitTestRandomSampling.cpp
//! Test if Sobol sampler interface is working correctly. Note that this test is somewhat minimal, but the core of the
//! Sobol sampling is tested in the GSL unit tests.
Test if Sobol sampler interface is working correctly. Note that this test is somewhat minimal, but the core of the
Sobol sampling is tested in the GSL unit tests.
Test if Sobol sampler interface is working correctly . Note that this test is somewhat minimal but the core of the Sobol sampling is tested in the GSL unit tests .
BOOST_AUTO_TEST_CASE( test_Sobol_Sampler )
{
    int dimension = 3;
    int numberOfSamples = 1E6;
    Eigen::VectorXd lower( dimension );
    Eigen::VectorXd upper( dimension );
    lower << 0.0, 1.0, -2.0;
    upper << 1.0, 3.0, 4.0;
    Eigen::VectorXd width = upper - lower;
    Eigen::VectorXd average = (upper + lower) / 2.0;
    std::vector< Eigen::VectorXd > sobolSamples = tudat::statistics::generateVectorSobolSample(
                numberOfSamples, lower, upper );
    Eigen::VectorXd sampleMean = statistics::computeSampleMean( sobolSamples );
    BOOST_CHECK_SMALL( std::fabs( average( 0 ) - sampleMean( 0 ) ), 2.0E-6 );
    BOOST_CHECK_SMALL( std::fabs( average( 1 ) - sampleMean( 1 ) ), 2.0E-6 );
    BOOST_CHECK_SMALL( std::fabs( average( 2 ) - sampleMean( 2 ) ), 2.0E-6 );
    sobolSamples = tudat::statistics::generateVectorSobolSample( dimension, numberOfSamples );
    sampleMean = statistics::computeSampleMean( sobolSamples );
    BOOST_CHECK_SMALL( std::fabs( 0.5 - sampleMean( 0 ) ), 2.0E-6 );
    BOOST_CHECK_SMALL( std::fabs( 0.5 - sampleMean( 1 ) ), 2.0E-6 );
    BOOST_CHECK_SMALL( std::fabs( 0.5 - sampleMean( 2 ) ), 2.0E-6 );
}
BOOST_AUTO_TEST_CASE ( test_Sobol_Sampler ) { int dimension = 3 ; int numberOfSamples = 1E6 ; Eigen :: VectorXd lower ( dimension ) ; Eigen :: VectorXd upper ( dimension ) ; lower << 0.0 , 1.0 , -2.0 ; upper << 1.0 , 3.0 , 4.0 ; Eigen :: VectorXd width = upper - lower ; Eigen :: VectorXd average = ( upper + lower ) / 2.0 ; std :: vector < Eigen :: VectorXd > sobolSamples = tudat :: statistics :: generateVectorSobolSample ( numberOfSamples , lower , upper ) ; Eigen :: VectorXd sampleMean = statistics :: computeSampleMean ( sobolSamples ) ; BOOST_CHECK_SMALL ( std :: fabs ( average ( 0 ) - sampleMean ( 0 ) ) , 2.0E-6 ) ; BOOST_CHECK_SMALL ( std :: fabs ( average ( 1 ) - sampleMean ( 1 ) ) , 2.0E-6 ) ; BOOST_CHECK_SMALL ( std :: fabs ( average ( 2 ) - sampleMean ( 2 ) ) , 2.0E-6 ) ; sobolSamples = tudat :: statistics :: generateVectorSobolSample ( dimension , numberOfSamples ) ; sampleMean = statistics :: computeSampleMean ( sobolSamples ) ; BOOST_CHECK_SMALL ( std :: fabs ( 0.5 - sampleMean ( 0 ) ) , 2.0E-6 ) ; BOOST_CHECK_SMALL ( std :: fabs ( 0.5 - sampleMean ( 1 ) ) , 2.0E-6 ) ; BOOST_CHECK_SMALL ( std :: fabs ( 0.5 - sampleMean ( 2 ) ) , 2.0E-6 ) ; }
Test if Sobol sampler interface is working correctly.
Test if Sobol sampler interface is working correctly .
// Define settings and generate samples. // Compute sample average // Compute sample average