1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
|
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2003, 2004 Ferdinando Ametrano
Copyright (C) 2007 Mark Joshi
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#include "preconditions.hpp"
#include "toplevelfixture.hpp"
#include "utilities.hpp"
#include <ql/math/statistics/discrepancystatistics.hpp>
#include <ql/math/statistics/sequencestatistics.hpp>
#include <ql/math/randomnumbers/burley2020sobolrsg.hpp>
#include <ql/math/randomnumbers/faurersg.hpp>
#include <ql/math/randomnumbers/haltonrsg.hpp>
#include <ql/math/randomnumbers/mt19937uniformrng.hpp>
#include <ql/math/randomnumbers/seedgenerator.hpp>
#include <ql/math/randomnumbers/primitivepolynomials.hpp>
#include <ql/math/randomnumbers/randomizedlds.hpp>
#include <ql/math/randomnumbers/randomsequencegenerator.hpp>
#include <ql/math/randomnumbers/sobolrsg.hpp>
#include <ql/utilities/dataformatters.hpp>
#include <ql/math/randomnumbers/latticerules.hpp>
#include <ql/math/randomnumbers/latticersg.hpp>
//#define PRINT_ONLY
#ifdef PRINT_ONLY
#include <fstream>
#endif
using namespace QuantLib;
using namespace boost::unit_test_framework;
using std::fabs;
BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture)
BOOST_AUTO_TEST_SUITE(LowDiscrepancyTests)
BOOST_AUTO_TEST_CASE(testSeedGenerator) {
BOOST_TEST_MESSAGE("Testing random-seed generator...");
SeedGenerator::instance().get();
}
BOOST_AUTO_TEST_CASE(testPolynomialsModuloTwo) {
BOOST_TEST_MESSAGE("Testing " << PPMT_MAX_DIM <<
" primitive polynomials modulo two...");
const Size jj[] = {
1, 1, 2, 2, 6, 6, 18,
16, 48, 60, 176, 144, 630, 756,
1800, 2048, 7710, 7776, 27594, 24000, 84672,
120032, 356960, 276480, 1296000, 1719900, 4202496
};
Size i=0,j=0,n=0;
BigInteger polynomial=0;
while (n<PPMT_MAX_DIM || polynomial!=-1) {
if (polynomial==-1) {
++i; // Increase degree index
j=0; // Reset index of polynomial in degree.
}
polynomial = PrimitivePolynomials[i][j];
if (polynomial==-1) {
--n;
if (j!=jj[i]) {
BOOST_ERROR("Only " << j << " polynomials in degree " << i+1
<< " instead of " << jj[i]);
}
}
++j; // Increase index of polynomial in degree i+1
++n; // Increase overall polynomial counter
}
}
BOOST_AUTO_TEST_CASE(testRandomizedLowDiscrepancySequence) {
BOOST_TEST_MESSAGE("Testing randomized low-discrepancy sequences up to "
"dimension " << PPMT_MAX_DIM << "...");
RandomizedLDS<SobolRsg, RandomSequenceGenerator<MersenneTwisterUniformRng> > rldsg(PPMT_MAX_DIM);
rldsg.nextSequence();
rldsg.lastSequence();
rldsg.nextRandomizer();
MersenneTwisterUniformRng t0;
SobolRsg t1(PPMT_MAX_DIM);
RandomSequenceGenerator<MersenneTwisterUniformRng> t2(PPMT_MAX_DIM);
RandomizedLDS<SobolRsg, RandomSequenceGenerator<MersenneTwisterUniformRng> > rldsg2(t1, t2);
rldsg2.nextSequence();
rldsg2.lastSequence();
rldsg2.nextRandomizer();
RandomizedLDS<SobolRsg, RandomSequenceGenerator<MersenneTwisterUniformRng> > rldsg3(t1);
rldsg3.nextSequence();
rldsg3.lastSequence();
rldsg3.nextRandomizer();
}
namespace
{
void testRandomizedLatticeRule(LatticeRule::type name,
const std::string& nameString)
{
Size maxDim = 30;
Size N = 1024;
Size numberBatches = 32;
BOOST_TEST_MESSAGE("Testing randomized lattice sequences (" << nameString
<< ") up to dimension " << maxDim << "...");
std::vector<Real> z;
LatticeRule::getRule(name, z, N);
LatticeRsg latticeGenerator(maxDim,
z,
N);
unsigned long seed = 12345678UL;
MersenneTwisterUniformRng rng( seed);
RandomSequenceGenerator<MersenneTwisterUniformRng> rsg(maxDim,
rng);
RandomizedLDS<LatticeRsg, RandomSequenceGenerator<MersenneTwisterUniformRng> > rldsg(latticeGenerator,rsg);
SequenceStatistics outerStats(maxDim);
for (Size i=0; i < numberBatches; ++i)
{
SequenceStatistics innerStats(maxDim);
for (Size j=0; j < N; ++j)
{
innerStats.add(rldsg.nextSequence().value);
}
outerStats.add(innerStats.mean());
rldsg.nextRandomizer();
}
std::vector<Real> means(outerStats.mean());
std::vector<Real> sds(outerStats.errorEstimate());
std::vector<Real> errorInSds(maxDim);
for (Size i=0; i < maxDim; ++i)
errorInSds[i] = (means[i]-0.5)/ sds[i];
Real tolerance = 4.0;
for (Size i=0; i < maxDim; ++i)
if (fabs(errorInSds[i] ) > tolerance)
BOOST_ERROR("Lattice generator" << nameString <<" returns a mean of " <<
means[i] << " with error equal to " << errorInSds[i]
<< " standard deviations in dimension " << i);
}
}
BOOST_AUTO_TEST_CASE(testRandomizedLattices){
testRandomizedLatticeRule(LatticeRule::A, "A");
testRandomizedLatticeRule(LatticeRule::B, "B");
testRandomizedLatticeRule(LatticeRule::C, "C");
testRandomizedLatticeRule(LatticeRule::D, "D");
}
BOOST_AUTO_TEST_CASE(testSobol) {
BOOST_TEST_MESSAGE("Testing Sobol sequences up to dimension "
<< PPMT_MAX_DIM << "...");
std::vector<Real> point;
Real tolerance = 1.0e-15;
// testing max dimensionality
Size dimensionality = PPMT_MAX_DIM;
BigNatural seed = 123456;
SobolRsg rsg(dimensionality, seed);
Size points = 100, i;
for (i=0; i<points; i++) {
point = rsg.nextSequence().value;
if (point.size()!=dimensionality) {
BOOST_ERROR("Sobol sequence generator returns "
" a sequence of wrong dimensionality: " << point.size()
<< " instead of " << dimensionality);
}
}
// testing homogeneity properties
dimensionality = 33;
seed = 123456;
rsg = SobolRsg(dimensionality, seed);
SequenceStatistics stat(dimensionality);
std::vector<Real> mean;
Size k = 0;
for (Integer j=1; j<5; j++) { // five cycle
points = Size(std::pow(2.0, j))-1; // base 2
for (; k<points; k++) {
point = rsg.nextSequence().value;
stat.add(point);
}
mean = stat.mean();
for (i=0; i<dimensionality; i++) {
Real error = std::fabs(mean[i]-0.5);
if (error > tolerance) {
BOOST_ERROR(io::ordinal(i+1) << " dimension: "
<< std::fixed
<< "mean (" << mean[i]
<< ") at the end of the " << io::ordinal(j+1)
<< " cycle in Sobol sequence is not " << 0.5
<< std::scientific
<< " (error = " << error << ")");
}
}
}
// testing first dimension (van der Corput sequence)
const Real vanderCorputSequenceModuloTwo[] = {
// first cycle (zero excluded)
0.50000,
// second cycle
0.75000, 0.25000,
// third cycle
0.37500, 0.87500, 0.62500, 0.12500,
// fourth cycle
0.18750, 0.68750, 0.93750, 0.43750, 0.31250, 0.81250, 0.56250, 0.06250,
// fifth cycle
0.09375, 0.59375, 0.84375, 0.34375, 0.46875, 0.96875, 0.71875, 0.21875,
0.15625, 0.65625, 0.90625, 0.40625, 0.28125, 0.78125, 0.53125, 0.03125
};
dimensionality = 1;
rsg = SobolRsg(dimensionality);
points = Size(std::pow(2.0, 5))-1; // five cycles
for (i=0; i<points; i++) {
point = rsg.nextSequence().value;
Real error = std::fabs(point[0]-vanderCorputSequenceModuloTwo[i]);
if (error > tolerance) {
BOOST_ERROR(io::ordinal(i+1) << " draw ("
<< std::fixed << point[0]
<< ") in 1-D Sobol sequence is not in the "
<< "van der Corput sequence modulo two: "
<< "it should have been "
<< vanderCorputSequenceModuloTwo[i]
<< std::scientific
<< " (error = " << error << ")");
}
}
}
BOOST_AUTO_TEST_CASE(testFaure) {
BOOST_TEST_MESSAGE("Testing Faure sequences...");
std::vector<Real> point;
Real tolerance = 1.0e-15;
// testing "high" dimensionality
Size dimensionality = PPMT_MAX_DIM;
FaureRsg rsg(dimensionality);
Size points = 100, i;
for (i=0; i<points; i++) {
point = rsg.nextSequence().value;
if (point.size()!=dimensionality) {
BOOST_ERROR("Faure sequence generator returns "
" a sequence of wrong dimensionality: " << point.size()
<< " instead of " << dimensionality);
}
}
// 1-dimension Faure (van der Corput sequence base 2)
const Real vanderCorputSequenceModuloTwo[] = {
// first cycle (zero excluded)
0.50000,
// second cycle
0.75000, 0.25000,
// third cycle
0.37500, 0.87500, 0.62500, 0.12500,
// fourth cycle
0.18750, 0.68750, 0.93750, 0.43750, 0.31250, 0.81250, 0.56250, 0.06250,
// fifth cycle
0.09375, 0.59375, 0.84375, 0.34375, 0.46875, 0.96875, 0.71875, 0.21875,
0.15625, 0.65625, 0.90625, 0.40625, 0.28125, 0.78125, 0.53125, 0.03125
};
dimensionality = 1;
rsg = FaureRsg(dimensionality);
points = Size(std::pow(2.0, 5))-1; // five cycles
for (i=0; i<points; i++) {
point = rsg.nextSequence().value;
Real error = std::fabs(point[0]-vanderCorputSequenceModuloTwo[i]);
if (error > tolerance) {
BOOST_ERROR(io::ordinal(i+1) << " draw, dimension 1 ("
<< std::fixed << point[0]
<< ") in 3-D Faure sequence should have been "
<< vanderCorputSequenceModuloTwo[i]
<< std::scientific
<< " (error = " << error << ")");
}
}
// 2nd dimension of the 2-dimensional Faure sequence
// (shuffled van der Corput sequence base 2)
// checked with the code provided with "Economic generation of
// low-discrepancy sequences with a b-ary gray code", by E. Thiemard
const Real FaureDimensionTwoOfTwo[] = {
// first cycle (zero excluded)
0.50000,
// second cycle
0.25000, 0.75000,
// third cycle
0.37500, 0.87500, 0.12500, 0.62500,
// fourth cycle
0.31250, 0.81250, 0.06250, 0.56250, 0.18750, 0.68750, 0.43750, 0.93750,
// fifth cycle
0.46875, 0.96875, 0.21875, 0.71875, 0.09375, 0.59375, 0.34375, 0.84375,
0.15625, 0.65625, 0.40625, 0.90625, 0.28125, 0.78125, 0.03125, 0.53125
};
dimensionality = 2;
rsg = FaureRsg(dimensionality);
points = Size(std::pow(2.0, 5))-1; // five cycles
for (i=0; i<points; i++) {
point = rsg.nextSequence().value;
Real error = std::fabs(point[0]-vanderCorputSequenceModuloTwo[i]);
if (error > tolerance) {
BOOST_ERROR(io::ordinal(i+1) << " draw, dimension 1 ("
<< std::fixed << point[0]
<< ") in 3-D Faure sequence should have been "
<< vanderCorputSequenceModuloTwo[i]
<< std::scientific
<< " (error = " << error << ")");
}
error = std::fabs(point[1]-FaureDimensionTwoOfTwo[i]);
if (error > tolerance) {
BOOST_ERROR(io::ordinal(i+1) << " draw, dimension 2 ("
<< std::fixed << point[1]
<< ") in 3-D Faure sequence should have been "
<< FaureDimensionTwoOfTwo[i]
<< std::scientific
<< " (error = " << error << ")");
}
}
// 3-dimension Faure sequence (shuffled van der Corput sequence base 3)
// see "Monte Carlo Methods in Financial Engineering,"
// by Paul Glasserman, 2004 Springer Verlag, pag. 299
const Real FaureDimensionOneOfThree[] = {
// first cycle (zero excluded)
1.0/3, 2.0/3,
// second cycle
7.0/9, 1.0/9, 4.0/9, 5.0/9, 8.0/9, 2.0/9
};
const Real FaureDimensionTwoOfThree[] = {
// first cycle (zero excluded)
1.0/3, 2.0/3,
// second cycle
1.0/9, 4.0/9, 7.0/9, 2.0/9, 5.0/9, 8.0/9
};
const Real FaureDimensionThreeOfThree[] = {
// first cycle (zero excluded)
1.0/3, 2.0/3,
// second cycle
4.0/9, 7.0/9, 1.0/9, 8.0/9, 2.0/9, 5.0/9
};
dimensionality = 3;
rsg = FaureRsg(dimensionality);
points = Size(std::pow(3.0, 2))-1; // three cycles
for (i=0; i<points; i++) {
point = rsg.nextSequence().value;
Real error = std::fabs(point[0]-FaureDimensionOneOfThree[i]);
if (error > tolerance) {
BOOST_ERROR(io::ordinal(i+1) << " draw, dimension 1 ("
<< std::fixed << point[0]
<< ") in 3-D Faure sequence should have been "
<< FaureDimensionOneOfThree[i]
<< std::scientific
<< " (error = " << error << ")");
}
error = std::fabs(point[1]-FaureDimensionTwoOfThree[i]);
if (error > tolerance) {
BOOST_ERROR(io::ordinal(i+1) << " draw, dimension 2 ("
<< std::fixed << point[1]
<< ") in 3-D Faure sequence should have been "
<< FaureDimensionTwoOfThree[i]
<< std::scientific
<< " (error = " << error << ")");
}
error = std::fabs(point[2]-FaureDimensionThreeOfThree[i]);
if (error > tolerance) {
BOOST_ERROR(io::ordinal(i+1) << " draw, dimension 3 ("
<< std::fixed << point[2]
<< ") in 3-D Faure sequence should have been "
<< FaureDimensionThreeOfThree[i]
<< std::scientific
<< " (error = " << error << ")");
}
}
}
BOOST_AUTO_TEST_CASE(testHalton) {
BOOST_TEST_MESSAGE("Testing Halton sequences...");
std::vector<Real> point;
Real tolerance = 1.0e-15;
// testing "high" dimensionality
Size dimensionality = PPMT_MAX_DIM;
HaltonRsg rsg(dimensionality, 0, false, false);
Size points = 100, i, k;
for (i=0; i<points; i++) {
point = rsg.nextSequence().value;
if (point.size()!=dimensionality) {
BOOST_ERROR("Halton sequence generator returns "
" a sequence of wrong dimensionality: " << point.size()
<< " instead of " << dimensionality);
}
}
// testing first and second dimension (van der Corput sequence)
const Real vanderCorputSequenceModuloTwo[] = {
// first cycle (zero excluded)
0.50000,
// second cycle
0.25000, 0.75000,
// third cycle
0.12500, 0.62500, 0.37500, 0.87500,
// fourth cycle
0.06250, 0.56250, 0.31250, 0.81250, 0.18750, 0.68750, 0.43750, 0.93750,
// fifth cycle
0.03125, 0.53125, 0.28125, 0.78125, 0.15625, 0.65625, 0.40625, 0.90625,
0.09375, 0.59375, 0.34375, 0.84375, 0.21875, 0.71875, 0.46875, 0.96875,
};
dimensionality = 1;
rsg = HaltonRsg(dimensionality, 0, false, false);
points = Size(std::pow(2.0, 5))-1; // five cycles
for (i=0; i<points; i++) {
point = rsg.nextSequence().value;
Real error = std::fabs(point[0]-vanderCorputSequenceModuloTwo[i]);
if (error > tolerance) {
BOOST_ERROR(io::ordinal(i+1) << " draw ("
<< std::fixed << point[0]
<< ") in 1-D Halton sequence is not in the "
<< "van der Corput sequence modulo two: "
<< "it should have been "
<< vanderCorputSequenceModuloTwo[i]
<< std::scientific
<< " (error = " << error << ")");
}
}
const Real vanderCorputSequenceModuloThree[] = {
// first cycle (zero excluded)
1.0/3, 2.0/3,
// second cycle
1.0/9, 4.0/9, 7.0/9, 2.0/9, 5.0/9, 8.0/9,
// third cycle
1.0/27, 10.0/27, 19.0/27, 4.0/27, 13.0/27, 22.0/27,
7.0/27, 16.0/27, 25.0/27, 2.0/27, 11.0/27, 20.0/27,
5.0/27, 14.0/27, 23.0/27, 8.0/27, 17.0/27, 26.0/27
};
dimensionality = 2;
rsg = HaltonRsg(dimensionality, 0, false, false);
points = Size(std::pow(3.0, 3))-1; // three cycles of the higher dimension
for (i=0; i<points; i++) {
point = rsg.nextSequence().value;
Real error = std::fabs(point[0]-vanderCorputSequenceModuloTwo[i]);
if (error > tolerance) {
BOOST_ERROR("First component of " << io::ordinal(i+1)
<< " draw (" << std::fixed << point[0]
<< ") in 2-D Halton sequence is not in the "
<< "van der Corput sequence modulo two: "
<< "it should have been "
<< vanderCorputSequenceModuloTwo[i]
<< std::scientific
<< " (error = " << error << ")");
}
error = std::fabs(point[1]-vanderCorputSequenceModuloThree[i]);
if (error > tolerance) {
BOOST_ERROR("Second component of " << io::ordinal(i+1)
<< " draw (" << std::fixed << point[1]
<< ") in 2-D Halton sequence is not in the "
<< "van der Corput sequence modulo three: "
<< "it should have been "
<< vanderCorputSequenceModuloThree[i]
<< std::scientific
<< " (error = " << error << ")");
}
}
// testing homogeneity properties
dimensionality = 33;
rsg = HaltonRsg(dimensionality, 0, false, false);
SequenceStatistics stat(dimensionality);
std::vector<Real> mean, stdev, variance, skewness, kurtosis;
k = 0;
Integer j;
for (j=1; j<5; j++) { // five cycle
points = Size(std::pow(2.0, j))-1; // base 2
for (; k<points; k++) {
point = rsg.nextSequence().value;
stat.add(point);
}
mean = stat.mean();
Real error = std::fabs(mean[0] - 0.5);
if (error > tolerance) {
BOOST_ERROR("First dimension mean (" << std::fixed << mean[0]
<< ") at the end of the " << io::ordinal(j+1)
<< " cycle in Halton sequence is not " << 0.5
<< std::scientific
<< " (error = " << error << ")");
}
}
// reset generator and gaussianstatistics
rsg = HaltonRsg(dimensionality, 0, false, false);
stat.reset(dimensionality);
k = 0;
for (j=1; j<3; j++) { // three cycle
points = Size(std::pow(3.0, j))-1; // base 3
for (; k<points; k++) {
point = rsg.nextSequence().value;
stat.add(point);
}
mean = stat.mean();
Real error = std::fabs(mean[1] - 0.5);
if (error > tolerance) {
BOOST_ERROR("Second dimension mean (" << std::fixed << mean[1]
<< ") at the end of the " << io::ordinal(j+1)
<< " cycle in Halton sequence is not " << 0.5
<< std::scientific
<< " (error = " << error << ")");
}
}
}
const Real dim002Discr_Sobol[] = {
8.33e-004, 4.32e-004, 2.24e-004, 1.12e-004,
5.69e-005, 2.14e-005 // , null
};
const Real dim002DiscrMersenneTwis[] = {
8.84e-003, 5.42e-003, 5.23e-003, 4.47e-003,
4.75e-003, 3.11e-003, 2.97e-003
};
const Real dim002DiscrPlain_Halton[] = {
1.26e-003, 6.73e-004, 3.35e-004, 1.91e-004,
1.11e-004, 5.05e-005, 2.42e-005
};
const Real dim002DiscrRShiftHalton[] = {1.32e-003, 7.25e-004};
const Real dim002DiscrRStRShHalton[] = {1.35e-003, 9.43e-004};
const Real dim002DiscrRStartHalton[] = {1.08e-003, 6.40e-004};
const Real dim002Discr_Unit_Sobol[] = {
8.33e-004, 4.32e-004, 2.24e-004, 1.12e-004, 5.69e-005, 2.14e-005 // , null
};
const Real dim003Discr_Sobol[] = {
1.21e-003, 6.37e-004, 3.40e-004, 1.75e-004,
9.21e-005, 4.79e-005, 2.56e-005
};
const Real dim003DiscrMersenneTwis[] = {
7.02e-003, 4.94e-003, 4.82e-003, 4.91e-003,
3.33e-003, 2.80e-003, 2.62e-003
};
const Real dim003DiscrPlain_Halton[] = {
1.63e-003, 9.62e-004, 4.83e-004, 2.67e-004,
1.41e-004, 7.64e-005, 3.93e-005
};
const Real dim003DiscrRShiftHalton[] = {1.96e-003, 1.03e-003};
const Real dim003DiscrRStRShHalton[] = {2.17e-003, 1.54e-003};
const Real dim003DiscrRStartHalton[] = {1.48e-003, 7.77e-004};
const Real dim003Discr_Unit_Sobol[] = {1.21e-003, 6.37e-004, 3.40e-004, 1.75e-004,
9.21e-005, 4.79e-005, 2.56e-005};
const Real dim005Discr_Sobol[] = {
1.59e-003, 9.55e-004, 5.33e-004, 3.22e-004,
1.63e-004, 9.41e-005, 5.19e-005
};
const Real dim005DiscrMersenneTwis[] = {
4.28e-003, 3.48e-003, 2.48e-003, 1.98e-003,
1.57e-003, 1.39e-003, 6.33e-004
};
const Real dim005DiscrPlain_Halton[] = {
1.93e-003, 1.23e-003, 6.89e-004, 4.22e-004,
2.13e-004, 1.25e-004, 7.17e-005
};
const Real dim005DiscrRShiftHalton[] = {2.02e-003, 1.36e-003};
const Real dim005DiscrRStRShHalton[] = {2.11e-003, 1.25e-003};
const Real dim005DiscrRStartHalton[] = {1.74e-003, 1.08e-003};
const Real dim005Discr_Unit_Sobol[] = {1.85e-003, 9.39e-004, 5.19e-004, 2.99e-004,
1.75e-004, 9.51e-005, 5.55e-005};
const Real dim010DiscrJackel_Sobol[] = {
7.08e-004, 5.31e-004, 3.60e-004, 2.18e-004,
1.57e-004, 1.12e-004, 6.39e-005
};
const Real dim010DiscrSobLev_Sobol[] = {
7.01e-004, 5.10e-004, 3.28e-004, 2.21e-004,
1.57e-004, 1.08e-004, 6.38e-005
};
const Real dim010DiscrMersenneTwis[] = {
8.83e-004, 6.56e-004, 4.87e-004, 3.37e-004,
3.06e-004, 1.73e-004, 1.43e-004
};
const Real dim010DiscrPlain_Halton[] = {
1.23e-003, 6.89e-004, 4.03e-004, 2.83e-004,
1.61e-004, 1.08e-004, 6.69e-005
};
const Real dim010DiscrRShiftHalton[] = {9.25e-004, 6.40e-004};
const Real dim010DiscrRStRShHalton[] = {8.41e-004, 5.42e-004};
const Real dim010DiscrRStartHalton[] = {7.89e-004, 5.33e-004};
const Real dim010Discr_Unit_Sobol[] = {7.67e-004, 4.92e-004, 3.47e-004, 2.34e-004,
1.39e-004, 9.47e-005, 5.72e-005};
const Real dim015DiscrJackel_Sobol[] = {
1.59e-004, 1.23e-004, 7.73e-005, 5.51e-005,
3.91e-005, 2.73e-005, 1.96e-005
};
const Real dim015DiscrSobLev_Sobol[] = {
1.48e-004, 1.06e-004, 8.19e-005, 6.29e-005,
4.16e-005, 2.54e-005, 1.73e-005
};
const Real dim015DiscrMersenneTwis[] = {
1.63e-004, 1.12e-004, 8.36e-005, 6.09e-005,
4.34e-005, 2.95e-005, 2.10e-005
};
const Real dim015DiscrPlain_Halton[] = {
5.75e-004, 3.12e-004, 1.70e-004, 9.89e-005,
5.33e-005, 3.45e-005, 2.11e-005
};
const Real dim015DiscrRShiftHalton[] = {1.75e-004, 1.19e-004};
const Real dim015DiscrRStRShHalton[] = {1.66e-004, 1.34e-004};
const Real dim015DiscrRStartHalton[] = {2.09e-004, 1.30e-004};
const Real dim015Discr_Unit_Sobol[] = {2.24e-004, 1.39e-004, 9.86e-005, 6.02e-005,
4.39e-005, 3.06e-005, 2.32e-005};
const Real dim030DiscrJackel_Sobol[] = {
6.43e-007, 5.28e-007, 3.88e-007, 2.49e-007,
2.09e-007, 1.55e-007, 1.07e-007
};
const Real dim030DiscrSobLev_Sobol[] = {
1.03e-006, 6.06e-007, 3.81e-007, 2.71e-007,
2.68e-007, 1.73e-007, 1.21e-007
};
const Real dim030DiscrMersenneTwis[] = {
4.38e-007, 3.25e-007, 4.47e-007, 2.85e-007,
2.03e-007, 1.50e-007, 1.17e-007
};
const Real dim030DiscrPlain_Halton[] = {
4.45e-004, 2.23e-004, 1.11e-004, 5.56e-005,
2.78e-005, 1.39e-005, 6.95e-006
};
const Real dim030DiscrRShiftHalton[] = {8.11e-007, 6.05e-007};
const Real dim030DiscrRStRShHalton[] = {1.85e-006, 1.03e-006};
const Real dim030DiscrRStartHalton[] = {4.42e-007, 4.64e-007};
const Real dim030Discr_Unit_Sobol[] = {4.35e-005, 2.17e-005, 1.09e-005, 5.43e-006,
2.73e-006, 1.37e-006, 6.90e-007};
const Real dim050DiscrJackel_Sobol[] = {
2.98e-010, 2.91e-010, 2.62e-010, 1.53e-010,
1.48e-010, 1.15e-010, 8.41e-011
};
const Real dim050DiscrSobLev_Sobol[] = {
3.11e-010, 2.52e-010, 1.61e-010, 1.54e-010,
1.11e-010, 8.60e-011, 1.17e-010
};
const Real dim050DiscrSobLem_Sobol[] = {
4.57e-010, 6.84e-010, 3.68e-010, 2.20e-010,
1.81e-010, 1.14e-010, 8.31e-011
};
const Real dim050DiscrMersenneTwis[] = {
3.27e-010, 2.42e-010, 1.47e-010, 1.98e-010,
2.31e-010, 1.30e-010, 8.09e-011
};
const Real dim050DiscrPlain_Halton[] = {
4.04e-004, 2.02e-004, 1.01e-004, 5.05e-005,
2.52e-005, 1.26e-005, 6.31e-006
};
const Real dim050DiscrRShiftHalton[] = {1.14e-010, 1.25e-010};
const Real dim050DiscrRStRShHalton[] = {2.92e-010, 5.02e-010};
const Real dim050DiscrRStartHalton[] = {1.93e-010, 6.82e-010};
const Real dim050Discr_Unit_Sobol[] = {1.63e-005, 8.14e-006, 4.07e-006, 2.04e-006,
1.02e-006, 5.09e-007, 2.54e-007};
const Real dim100DiscrJackel_Sobol[] = {
1.26e-018, 1.55e-018, 8.46e-019, 4.43e-019,
4.04e-019, 2.44e-019, 4.86e-019
};
const Real dim100DiscrSobLev_Sobol[] = {
1.17e-018, 2.65e-018, 1.45e-018, 7.28e-019,
6.33e-019, 3.36e-019, 3.43e-019
};
const Real dim100DiscrSobLem_Sobol[] = {
8.79e-019, 4.60e-019, 6.69e-019, 7.17e-019,
5.81e-019, 2.97e-019, 2.64e-019
};
const Real dim100DiscrMersenneTwis[] = {
5.30e-019, 7.29e-019, 3.71e-019, 3.33e-019,
1.33e-017, 6.70e-018, 3.36e-018
};
const Real dim100DiscrPlain_Halton[] = {
3.63e-004, 1.81e-004, 9.07e-005, 4.53e-005,
2.27e-005, 1.13e-005, 5.66e-006
};
const Real dim100DiscrRShiftHalton[] = {3.36e-019, 2.19e-019};
const Real dim100DiscrRStRShHalton[] = {4.44e-019, 2.24e-019};
const Real dim100DiscrRStartHalton[] = {9.85e-020, 8.34e-019};
const Real dim100Discr_Unit_Sobol[] = {4.97e-006, 2.48e-006, 1.24e-006, 6.20e-007,
3.10e-007, 1.55e-007, 7.76e-008};
const Size dimensionality[] = {2, 3, 5, 10, 15, 30, 50, 100 };
// 7 discrepancy measures for each dimension of all sequence generators
// would take a few days ... too long for usual/frequent test running
const Size discrepancyMeasuresNumber = 1;
// let's add some generality here...
class MersenneFactory {
public:
typedef RandomSequenceGenerator<MersenneTwisterUniformRng>
MersenneTwisterUniformRsg;
typedef MersenneTwisterUniformRsg generator_type;
MersenneTwisterUniformRsg make(Size dim,
BigNatural seed) const {
return MersenneTwisterUniformRsg(dim,seed);
}
std::string name() const { return "Mersenne Twister"; }
};
class SobolFactory {
public:
typedef SobolRsg generator_type;
explicit SobolFactory(SobolRsg::DirectionIntegers unit) : unit_(unit) {}
SobolRsg make(Size dim,
BigNatural seed) const {
return SobolRsg(dim,seed,unit_);
}
std::string name() const {
std::string prefix;
switch (unit_) {
case SobolRsg::Unit:
prefix = "unit-initialized ";
break;
case SobolRsg::Jaeckel:
prefix = "Jaeckel-initialized ";
break;
case SobolRsg::SobolLevitan:
prefix = "SobolLevitan-initialized ";
break;
case SobolRsg::SobolLevitanLemieux:
prefix = "SobolLevitanLemieux-initialized ";
break;
case SobolRsg::Kuo:
prefix = "Kuo";
break;
case SobolRsg::Kuo2:
prefix = "Kuo2";
break;
case SobolRsg::Kuo3:
prefix = "Kuo3";
break;
default:
QL_FAIL("unknown direction integers");
}
return prefix + "Sobol sequences: ";
}
private:
SobolRsg::DirectionIntegers unit_;
};
class HaltonFactory {
public:
typedef HaltonRsg generator_type;
HaltonFactory(bool randomStart, bool randomShift)
: start_(randomStart), shift_(randomShift) {}
HaltonRsg make(Size dim,
BigNatural seed) const {
return HaltonRsg(dim,seed,start_,shift_);
}
std::string name() const {
std::string prefix = start_ ?
"random-start " :
"";
if (shift_)
prefix += "random-shift ";
return prefix + "Halton";
}
private:
bool start_, shift_;
};
template <class T>
void testGeneratorDiscrepancy(const T& generatorFactory,
#ifndef PRINT_ONLY
const Real * const discrepancy[8],
const std::string&,
const std::string&
#else
const Real * const [8],
const std::string& fileName,
const std::string& arrayName
#endif
) {
#ifndef PRINT_ONLY
Real tolerance = 1.0e-2;
#endif
std::vector<Real> point;
Size dim;
BigNatural seed = 123456;
Real discr;
// more than 1 discrepancy measures take long time
Size sampleLoops = std::max<Size>(1, discrepancyMeasuresNumber);
#ifdef PRINT_ONLY
std::ofstream outStream(fileName.c_str());
#endif
for (Integer i = 0; i<8; i++) {
#ifdef PRINT_ONLY
outStream << std::endl;
#endif
dim = dimensionality[i];
DiscrepancyStatistics stat(dim);
typename T::generator_type rsg = generatorFactory.make(dim, seed);
Size j, k=0, jMin=10;
stat.reset();
#ifdef PRINT_ONLY
outStream << "const Real dim" << dim
<< arrayName << "[] = {" ;
#endif
for (j=jMin; j<jMin+sampleLoops; j++) {
Size points = Size(std::pow(2.0, Integer(j)))-1;
for (; k<points; k++) {
point = rsg.nextSequence().value;
stat.add(point);
}
discr = stat.discrepancy();
#ifdef PRINT_ONLY
if (j!=jMin)
outStream << ", ";
outStream << std::fixed << std::setprecision(2) << discr;
#else
if (std::fabs(discr-discrepancy[i][j-jMin])>tolerance*discr) {
BOOST_ERROR(generatorFactory.name()
<< "discrepancy dimension " << dimensionality[i]
<< " at " << points << " samples is "
<< discr << " instead of "
<< discrepancy[i][j-jMin]);
}
#endif
}
#ifdef PRINT_ONLY
outStream << "};" << std::endl;
#endif
}
#ifdef PRINT_ONLY
outStream.close();
#endif
}
BOOST_AUTO_TEST_CASE(testMersenneTwisterDiscrepancy) {
BOOST_TEST_MESSAGE("Testing Mersenne-twister discrepancy...");
const Real * const discrepancy[8] = {
dim002DiscrMersenneTwis, dim003DiscrMersenneTwis,
dim005DiscrMersenneTwis, dim010DiscrMersenneTwis,
dim015DiscrMersenneTwis, dim030DiscrMersenneTwis,
dim050DiscrMersenneTwis, dim100DiscrMersenneTwis
};
testGeneratorDiscrepancy(MersenneFactory(),
discrepancy,
"MersenneDiscrepancy.txt",
"DiscrMersenneTwis");
}
BOOST_AUTO_TEST_CASE(testPlainHaltonDiscrepancy) {
BOOST_TEST_MESSAGE("Testing plain Halton discrepancy...");
const Real * const discrepancy[8] = {
dim002DiscrPlain_Halton, dim003DiscrPlain_Halton,
dim005DiscrPlain_Halton, dim010DiscrPlain_Halton,
dim015DiscrPlain_Halton, dim030DiscrPlain_Halton,
dim050DiscrPlain_Halton, dim100DiscrPlain_Halton};
testGeneratorDiscrepancy(HaltonFactory(false,false),
discrepancy,
"PlainHaltonDiscrepancy.txt",
"DiscrPlain_Halton");
}
BOOST_AUTO_TEST_CASE(testRandomStartHaltonDiscrepancy) {
BOOST_TEST_MESSAGE("Testing random-start Halton discrepancy...");
const Real * const discrepancy[8] = {
dim002DiscrRStartHalton, dim003DiscrRStartHalton,
dim005DiscrRStartHalton, dim010DiscrRStartHalton,
dim015DiscrRStartHalton, dim030DiscrRStartHalton,
dim050DiscrRStartHalton, dim100DiscrRStartHalton};
testGeneratorDiscrepancy(HaltonFactory(true,false),
discrepancy,
"RandomStartHaltonDiscrepancy.txt",
"DiscrRStartHalton");
}
BOOST_AUTO_TEST_CASE(testRandomShiftHaltonDiscrepancy) {
BOOST_TEST_MESSAGE("Testing random-shift Halton discrepancy...");
const Real * const discrepancy[8] = {
dim002DiscrRShiftHalton, dim003DiscrRShiftHalton,
dim005DiscrRShiftHalton, dim010DiscrRShiftHalton,
dim015DiscrRShiftHalton, dim030DiscrRShiftHalton,
dim050DiscrRShiftHalton, dim100DiscrRShiftHalton};
testGeneratorDiscrepancy(HaltonFactory(false,true),
discrepancy,
"RandomShiftHaltonDiscrepancy.txt",
"DiscrRShiftHalton");
}
BOOST_AUTO_TEST_CASE(testRandomStartRandomShiftHaltonDiscrepancy) {
BOOST_TEST_MESSAGE("Testing random-start, random-shift Halton discrepancy...");
const Real * const discrepancy[8] = {
dim002DiscrRStRShHalton, dim003DiscrRStRShHalton,
dim005DiscrRStRShHalton, dim010DiscrRStRShHalton,
dim015DiscrRStRShHalton, dim030DiscrRStRShHalton,
dim050DiscrRStRShHalton, dim100DiscrRStRShHalton};
testGeneratorDiscrepancy(HaltonFactory(true,true),
discrepancy,
"RandomStartRandomShiftHaltonDiscrepancy.txt",
"DiscrRStRShHalton");
}
BOOST_AUTO_TEST_CASE(testJackelSobolDiscrepancy) {
BOOST_TEST_MESSAGE("Testing Jaeckel-Sobol discrepancy...");
const Real * const discrepancy[8] = {
dim002Discr_Sobol, dim003Discr_Sobol,
dim005Discr_Sobol, dim010DiscrJackel_Sobol,
dim015DiscrJackel_Sobol, dim030DiscrJackel_Sobol,
dim050DiscrJackel_Sobol, dim100DiscrJackel_Sobol};
testGeneratorDiscrepancy(SobolFactory(SobolRsg::Jaeckel),
discrepancy,
"JackelSobolDiscrepancy.txt",
"DiscrJackel_Sobol");
}
BOOST_AUTO_TEST_CASE(testSobolLevitanSobolDiscrepancy) {
BOOST_TEST_MESSAGE("Testing Levitan-Sobol discrepancy...");
const Real * const discrepancy[8] = {
dim002Discr_Sobol, dim003Discr_Sobol,
dim005Discr_Sobol, dim010DiscrSobLev_Sobol,
dim015DiscrSobLev_Sobol, dim030DiscrSobLev_Sobol,
dim050DiscrSobLev_Sobol, dim100DiscrSobLev_Sobol};
testGeneratorDiscrepancy(SobolFactory(SobolRsg::SobolLevitan),
discrepancy,
"SobolLevitanSobolDiscrepancy.txt",
"DiscrSobLev_Sobol");
}
BOOST_AUTO_TEST_CASE(testSobolLevitanLemieuxSobolDiscrepancy) {
BOOST_TEST_MESSAGE("Testing Levitan-Lemieux-Sobol discrepancy...");
const Real * const discrepancy[8] = {
dim002Discr_Sobol, dim003Discr_Sobol,
dim005Discr_Sobol, dim010DiscrSobLev_Sobol,
dim015DiscrSobLev_Sobol, dim030DiscrSobLev_Sobol,
dim050DiscrSobLem_Sobol, dim100DiscrSobLem_Sobol};
testGeneratorDiscrepancy(SobolFactory(SobolRsg::SobolLevitanLemieux),
discrepancy,
"SobolLevitanLemieuxSobolDiscrepancy.txt",
"DiscrSobLevLem_Sobol");
}
BOOST_AUTO_TEST_CASE(testUnitSobolDiscrepancy) {
BOOST_TEST_MESSAGE("Testing unit Sobol discrepancy...");
const Real* const discrepancy[8] = {dim002Discr_Unit_Sobol, dim003Discr_Unit_Sobol,
dim005Discr_Unit_Sobol, dim010Discr_Unit_Sobol,
dim015Discr_Unit_Sobol, dim030Discr_Unit_Sobol,
dim050Discr_Unit_Sobol, dim100Discr_Unit_Sobol};
testGeneratorDiscrepancy(SobolFactory(SobolRsg::Unit), discrepancy, "UnitSobolDiscrepancy.txt",
"Discr__Unit_Sobol");
}
BOOST_AUTO_TEST_CASE(testSobolSkipping) {
BOOST_TEST_MESSAGE("Testing Sobol sequence skipping...");
unsigned long seed = 42;
Size dimensionality[] = { 1, 10, 100, 1000 };
unsigned long skip[] = { 0, 1, 42, 512, 100000 };
SobolRsg::DirectionIntegers integers[] = { SobolRsg::Unit,
SobolRsg::Jaeckel,
SobolRsg::SobolLevitan,
SobolRsg::SobolLevitanLemieux };
for (auto& integer : integers) {
for (Size& j : dimensionality) {
for (unsigned long& k : skip) {
// extract n samples
SobolRsg rsg1(j, seed, integer);
for (Size l = 0; l < k; l++)
rsg1.nextInt32Sequence();
// skip n samples at once
SobolRsg rsg2(j, seed, integer);
rsg2.skipTo(k);
// compare next 100 samples
for (Size m = 0; m < 100; m++) {
const std::vector<std::uint_least32_t>& s1 = rsg1.nextInt32Sequence();
const std::vector<std::uint_least32_t>& s2 = rsg2.nextInt32Sequence();
for (Size n = 0; n < s1.size(); n++) {
if (s1[n] != s2[n]) {
BOOST_ERROR("Mismatch after skipping:"
<< "\n size: " << j << "\n integers: " << integer
<< "\n skipped: " << k << "\n at index: " << n
<< "\n expected: " << s1[n] << "\n found: " << s2[n]);
}
}
}
}
}
}
}
BOOST_AUTO_TEST_CASE(testHighDimensionalIntegrals, *precondition(if_speed(Slow))) {
BOOST_TEST_MESSAGE("Testing high-dimensional integrals...");
/* We are running "Integration test 1, results for high dimensions" (Figure 9) from:
Sobol, Asotsky, Kreinin, Kucherenko: Construction and Comparison of High-Dimensional Sobol’
Generators, available at https://www.broda.co.uk/doc/HD_SobolGenerator.pdf
We check the error of Kuo1 (using Gray code and sequential numbers) roughly against what
their graph suggests. In addition we check the error of the Burley2020-scrambled version of
Kuo1 against what we experimentally find - the error turns out to be more than one order
better than the unscrambled version. */
auto integrand = [](const std::vector<Real>& c, const std::vector<Real>& x) {
Real p = 1.0;
for (Size i = 0; i < c.size(); ++i) {
p *= 1.0 + c[i] * (x[i] - 0.5);
}
return p;
};
Size N = 30031;
std::vector<Size> dimension = {1000, 2000, 5000};
std::vector<std::vector<Real>> expectedOrderOfError = {
{-3.0, -3.0, -4.5}, {-2.5, -2.5, -4.0}, {-2.0, -2.0, -4.0}};
for (Size d = 0; d < dimension.size(); ++d) {
std::vector<Real> c1(dimension[d], 0.01);
SobolRsg s1(dimension[d], 42, SobolRsg::DirectionIntegers::Kuo, true);
SobolRsg s2(dimension[d], 42, SobolRsg::DirectionIntegers::Kuo, false);
Burley2020SobolRsg s3(dimension[d], 42, SobolRsg::DirectionIntegers::Kuo, 43);
Real I1 = 0.0, I2 = 0.0, I3 = 0.0;
for (Size i = 0; i < N; ++i) {
I1 += integrand(c1, s1.nextSequence().value) / static_cast<double>(N);
I2 += integrand(c1, s2.nextSequence().value) / static_cast<double>(N);
I3 += integrand(c1, s3.nextSequence().value) / static_cast<double>(N);
}
Real errOrder1 = std::log10(std::abs(I1 - 1.0));
Real errOrder2 = std::log10(std::abs(I2 - 1.0));
Real errOrder3 = std::log10(std::abs(I3 - 1.0));
BOOST_CHECK_MESSAGE(errOrder1 < expectedOrderOfError[d][0],
"order of error for dimension " + std::to_string(dimension[d]) + " is" +
std::to_string(errOrder1) + " expected " +
std::to_string(expectedOrderOfError[d][0]));
BOOST_CHECK_MESSAGE(errOrder2 < expectedOrderOfError[d][1],
"order of error for dimension " + std::to_string(dimension[d]) + " is" +
std::to_string(errOrder2) + " expected " +
std::to_string(expectedOrderOfError[d][1]));
BOOST_CHECK_MESSAGE(errOrder3 < expectedOrderOfError[d][2],
"order of error for dimension " + std::to_string(dimension[d]) + " is" +
std::to_string(errOrder3) + " expected " +
std::to_string(expectedOrderOfError[d][2]));
}
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
|