01 May 2011 11:26:03 AM HALTON_PRB: C++ version Test the HALTON library. TEST01 HALTON computes the next element of a Halton sequence. HALTON_STEP_SET sets the step. In this test, we try several values of STEP. We repeat the test for several dimensions. We assume defaults for SEED, LEAP and BASE. DIM_NUM = 1 N = 11 STEP = 0 SEED = 0 BASE = 2 STEP Halton 0 0 1 0.5 2 0.25 3 0.75 4 0.125 5 0.625 6 0.375 7 0.875 8 0.0625 9 0.5625 10 0.3125 DIM_NUM = 1 N = 11 STEP = 5 SEED = 0 BASE = 2 STEP Halton 5 0.625 6 0.375 7 0.875 8 0.0625 9 0.5625 10 0.3125 11 0.8125 12 0.1875 13 0.6875 14 0.4375 15 0.9375 DIM_NUM = 1 N = 11 STEP = 1000 SEED = 0 BASE = 2 STEP Halton 1000 0.0927734 1001 0.592773 1002 0.342773 1003 0.842773 1004 0.217773 1005 0.717773 1006 0.467773 1007 0.967773 1008 0.0615234 1009 0.561523 1010 0.311523 DIM_NUM = 1 N = 11 STEP = 1000000 SEED = 0 BASE = 2 STEP Halton 1000000 0.00883389 1000001 0.508834 1000002 0.258834 1000003 0.758834 1000004 0.133834 1000005 0.633834 1000006 0.383834 1000007 0.883834 1000008 0.0713339 1000009 0.571334 1000010 0.321334 DIM_NUM = 2 N = 11 STEP = 0 SEED = 0 0 BASE = 2 3 STEP Halton 0 0 0 1 0.5 0.333333 2 0.25 0.666667 3 0.75 0.111111 4 0.125 0.444444 5 0.625 0.777778 6 0.375 0.222222 7 0.875 0.555556 8 0.0625 0.888889 9 0.5625 0.037037 10 0.3125 0.37037 DIM_NUM = 2 N = 11 STEP = 5 SEED = 0 0 BASE = 2 3 STEP Halton 5 0.625 0.777778 6 0.375 0.222222 7 0.875 0.555556 8 0.0625 0.888889 9 0.5625 0.037037 10 0.3125 0.37037 11 0.8125 0.703704 12 0.1875 0.148148 13 0.6875 0.481481 14 0.4375 0.814815 15 0.9375 0.259259 DIM_NUM = 2 N = 11 STEP = 1000 SEED = 0 0 BASE = 2 3 STEP Halton 1000 0.0927734 0.347508 1001 0.592773 0.680841 1002 0.342773 0.125286 1003 0.842773 0.458619 1004 0.217773 0.791952 1005 0.717773 0.236397 1006 0.467773 0.56973 1007 0.967773 0.903064 1008 0.0615234 0.0512117 1009 0.561523 0.384545 1010 0.311523 0.717878 DIM_NUM = 2 N = 11 STEP = 1000000 SEED = 0 0 BASE = 2 3 STEP Halton 1000000 0.00883389 0.361066 1000001 0.508834 0.694399 1000002 0.258834 0.138844 1000003 0.758834 0.472177 1000004 0.133834 0.805511 1000005 0.633834 0.249955 1000006 0.383834 0.583288 1000007 0.883834 0.916622 1000008 0.0713339 0.0647698 1000009 0.571334 0.398103 1000010 0.321334 0.731436 DIM_NUM = 3 N = 11 STEP = 0 SEED = 0 0 0 BASE = 2 3 5 STEP Halton 0 0 0 0 1 0.5 0.333333 0.2 2 0.25 0.666667 0.4 3 0.75 0.111111 0.6 4 0.125 0.444444 0.8 5 0.625 0.777778 0.04 6 0.375 0.222222 0.24 7 0.875 0.555556 0.44 8 0.0625 0.888889 0.64 9 0.5625 0.037037 0.84 10 0.3125 0.37037 0.08 DIM_NUM = 3 N = 11 STEP = 5 SEED = 0 0 0 BASE = 2 3 5 STEP Halton 5 0.625 0.777778 0.04 6 0.375 0.222222 0.24 7 0.875 0.555556 0.44 8 0.0625 0.888889 0.64 9 0.5625 0.037037 0.84 10 0.3125 0.37037 0.08 11 0.8125 0.703704 0.28 12 0.1875 0.148148 0.48 13 0.6875 0.481481 0.68 14 0.4375 0.814815 0.88 15 0.9375 0.259259 0.12 DIM_NUM = 3 N = 11 STEP = 1000 SEED = 0 0 0 BASE = 2 3 5 STEP Halton 1000 0.0927734 0.347508 0.00512 1001 0.592773 0.680841 0.20512 1002 0.342773 0.125286 0.40512 1003 0.842773 0.458619 0.60512 1004 0.217773 0.791952 0.80512 1005 0.717773 0.236397 0.04512 1006 0.467773 0.56973 0.24512 1007 0.967773 0.903064 0.44512 1008 0.0615234 0.0512117 0.64512 1009 0.561523 0.384545 0.84512 1010 0.311523 0.717878 0.08512 DIM_NUM = 3 N = 11 STEP = 1000000 SEED = 0 0 0 BASE = 2 3 5 STEP Halton 1000000 0.00883389 0.361066 5.7344e-05 1000001 0.508834 0.694399 0.200057 1000002 0.258834 0.138844 0.400057 1000003 0.758834 0.472177 0.600057 1000004 0.133834 0.805511 0.800057 1000005 0.633834 0.249955 0.0400573 1000006 0.383834 0.583288 0.240057 1000007 0.883834 0.916622 0.440057 1000008 0.0713339 0.0647698 0.640057 1000009 0.571334 0.398103 0.840057 1000010 0.321334 0.731436 0.0800573 TEST0125 I4_TO_HALTON computes a Halton sequence. The user gives the seed and bases as explicit input. In this test, we call I4_TO_HALTON repeatedly. We use distinct primes as bases. DIM_NUM = 1 N = 11 STEP = 0 SEED = 0 LEAP = 1 BASE = 2 STEP Halton 0 0 1 0.5 2 0.25 3 0.75 4 0.125 5 0.625 6 0.375 7 0.875 8 0.0625 9 0.5625 10 0.3125 DIM_NUM = 2 N = 11 STEP = 0 SEED = 0 0 LEAP = 1 1 BASE = 2 3 STEP Halton 0 0 0 1 0.5 0.333333 2 0.25 0.666667 3 0.75 0.111111 4 0.125 0.444444 5 0.625 0.777778 6 0.375 0.222222 7 0.875 0.555556 8 0.0625 0.888889 9 0.5625 0.037037 10 0.3125 0.37037 DIM_NUM = 3 N = 11 STEP = 0 SEED = 0 0 0 LEAP = 1 1 1 BASE = 2 3 5 STEP Halton 0 0 0 0 1 0.5 0.333333 0.2 2 0.25 0.666667 0.4 3 0.75 0.111111 0.6 4 0.125 0.444444 0.8 5 0.625 0.777778 0.04 6 0.375 0.222222 0.24 7 0.875 0.555556 0.44 8 0.0625 0.888889 0.64 9 0.5625 0.037037 0.84 10 0.3125 0.37037 0.08 TEST0126 I4_TO_HALTON computes a Halton sequence. The user gives the seed and bases as explicit input. In this test, we call I4_TO_HALTON repeatedly. We use the same value for all bases. DIM_NUM = 3 N = 11 SEED = 0 0 0 LEAP = 1 1 1 BASE = 2 2 2 STEP Halton 0 0 0 0 1 0.5 0.5 0.5 2 0.25 0.25 0.25 3 0.75 0.75 0.75 4 0.125 0.125 0.125 5 0.625 0.625 0.625 6 0.375 0.375 0.375 7 0.875 0.875 0.875 8 0.0625 0.0625 0.0625 9 0.5625 0.5625 0.5625 10 0.3125 0.3125 0.3125 TEST02 HALTON_SEQUENCE computes N elements of a Halton sequence on a single call. DIM_NUM = 3 N = 10 STEP = 0 SEED = 0 0 0 STEP Halton 0 0 0 0 1 0.5 0.333333 0.2 2 0.25 0.666667 0.4 3 0.75 0.111111 0.6 4 0.125 0.444444 0.8 5 0.625 0.777778 0.04 6 0.375 0.222222 0.24 7 0.875 0.555556 0.44 8 0.0625 0.888889 0.64 9 0.5625 0.037037 0.84 TEST025 I4_TO_HALTON_SEQUENCE computes N elements of a Halton sequence on a single call. All arguments are specified explicitly. DIM_NUM = 3 N = 10 STEP = 0 SEED = 0 0 0 LEAP = 1 1 1 BASE = 2 3 5 STEP Halton 0 0 0 0 1 0.5 0.333333 0.2 2 0.25 0.666667 0.4 3 0.75 0.111111 0.6 4 0.125 0.444444 0.8 5 0.625 0.777778 0.04 6 0.375 0.222222 0.24 7 0.875 0.555556 0.44 8 0.0625 0.888889 0.64 9 0.5625 0.037037 0.84 DIM_NUM = 3 N = 10 STEP = 0 SEED = 1 2 3 LEAP = 1 1 1 BASE = 2 3 5 STEP Halton 0 0.5 0.666667 0.6 1 0.25 0.111111 0.8 2 0.75 0.444444 0.04 3 0.125 0.777778 0.24 4 0.625 0.222222 0.44 5 0.375 0.555556 0.64 6 0.875 0.888889 0.84 7 0.0625 0.037037 0.08 8 0.5625 0.37037 0.28 9 0.3125 0.703704 0.48 DIM_NUM = 3 N = 10 STEP = 0 SEED = 1 1 1 LEAP = 3 3 3 BASE = 2 3 5 STEP Halton 0 0.5 0.333333 0.2 1 0.125 0.444444 0.8 2 0.875 0.555556 0.44 3 0.3125 0.37037 0.08 4 0.6875 0.481481 0.68 5 0.03125 0.592593 0.32 6 0.78125 0.407407 0.92 7 0.40625 0.518519 0.56 8 0.59375 0.62963 0.008 9 0.21875 0.345679 0.608 DIM_NUM = 3 N = 10 STEP = 0 SEED = 1 2 3 LEAP = 1 1 1 BASE = 2 2 2 STEP Halton 0 0.5 0.25 0.75 1 0.25 0.75 0.125 2 0.75 0.125 0.625 3 0.125 0.625 0.375 4 0.625 0.375 0.875 5 0.375 0.875 0.0625 6 0.875 0.0625 0.5625 7 0.0625 0.5625 0.3125 8 0.5625 0.3125 0.8125 9 0.3125 0.8125 0.1875 TEST03 HALTON_STEP_SET specifies the next element of the Halton sequence to compute. In this test, we demonstrate how resetting STEP determines the next element computed. DIM_NUM = 1 N = 11 STEP = 0 SEED = 0 STEP Halton 0 0 1 0.5 2 0.25 3 0.75 4 0.125 5 0.625 6 0.375 7 0.875 8 0.0625 9 0.5625 10 0.3125 N = 11 STEP = 6 STEP Halton 6 0.375 7 0.875 8 0.0625 9 0.5625 10 0.3125 11 0.8125 12 0.1875 13 0.6875 14 0.4375 15 0.9375 16 0.03125 N = 6 STEP = 0 STEP Halton 0 0 1 0.5 2 0.25 3 0.75 4 0.125 5 0.625 N = 5 STEP = 100 STEP Halton 100 0.148438 101 0.648438 102 0.398438 103 0.898438 104 0.0859375 TEST04 HALTON_BASE_GET gets the current Halton bases. HALTON_BASE_SET sets the current Halton bases. In this test, we compute a Halton sequence with the default base, then change the base, reset the seed, and recompute the sequence. DIM_NUM = 1 N = 10 STEP = 0 SEED = 0 BASE = 2 STEP Halton 0 0 1 0.5 2 0.25 3 0.75 4 0.125 5 0.625 6 0.375 7 0.875 8 0.0625 9 0.5625 DIM_NUM = 1 N = 10 STEP = 0 SEED = 0 BASE = 3 STEP Halton 0 0 1 0.333333 2 0.666667 3 0.111111 4 0.444444 5 0.777778 6 0.222222 7 0.555556 8 0.888889 9 0.037037 DIM_NUM = 1 N = 10 STEP = 0 SEED = 0 BASE = 4 STEP Halton 0 0 1 0.25 2 0.5 3 0.75 4 0.0625 5 0.3125 6 0.5625 7 0.8125 8 0.125 9 0.375 TEST045 HALTON_SEQUENCE computes N elements of a Halton sequence on a single call. DIM_NUM = 2 N = 101 STEP = 0 SEED = 0 0 BASE = 2 3 STEP Halton 0 0 0 1 0.5 0.333333 2 0.25 0.666667 3 0.75 0.111111 4 0.125 0.444444 5 0.625 0.777778 6 0.375 0.222222 7 0.875 0.555556 8 0.0625 0.888889 9 0.5625 0.037037 10 0.3125 0.37037 11 0.8125 0.703704 12 0.1875 0.148148 13 0.6875 0.481481 14 0.4375 0.814815 15 0.9375 0.259259 16 0.03125 0.592593 17 0.53125 0.925926 18 0.28125 0.0740741 19 0.78125 0.407407 20 0.15625 0.740741 21 0.65625 0.185185 22 0.40625 0.518519 23 0.90625 0.851852 24 0.09375 0.296296 25 0.59375 0.62963 26 0.34375 0.962963 27 0.84375 0.0123457 28 0.21875 0.345679 29 0.71875 0.679012 30 0.46875 0.123457 31 0.96875 0.45679 32 0.015625 0.790123 33 0.515625 0.234568 34 0.265625 0.567901 35 0.765625 0.901235 36 0.140625 0.0493827 37 0.640625 0.382716 38 0.390625 0.716049 39 0.890625 0.160494 40 0.078125 0.493827 41 0.578125 0.82716 42 0.328125 0.271605 43 0.828125 0.604938 44 0.203125 0.938272 45 0.703125 0.0864198 46 0.453125 0.419753 47 0.953125 0.753086 48 0.046875 0.197531 49 0.546875 0.530864 50 0.296875 0.864198 51 0.796875 0.308642 52 0.171875 0.641975 53 0.671875 0.975309 54 0.421875 0.0246914 55 0.921875 0.358025 56 0.109375 0.691358 57 0.609375 0.135802 58 0.359375 0.469136 59 0.859375 0.802469 60 0.234375 0.246914 61 0.734375 0.580247 62 0.484375 0.91358 63 0.984375 0.0617284 64 0.0078125 0.395062 65 0.507812 0.728395 66 0.257812 0.17284 67 0.757812 0.506173 68 0.132812 0.839506 69 0.632812 0.283951 70 0.382812 0.617284 71 0.882812 0.950617 72 0.0703125 0.0987654 73 0.570312 0.432099 74 0.320312 0.765432 75 0.820312 0.209877 76 0.195312 0.54321 77 0.695312 0.876543 78 0.445312 0.320988 79 0.945312 0.654321 80 0.0390625 0.987654 81 0.539062 0.00411523 82 0.289062 0.337449 83 0.789062 0.670782 84 0.164062 0.115226 85 0.664062 0.44856 86 0.414062 0.781893 87 0.914062 0.226337 88 0.101562 0.559671 89 0.601562 0.893004 90 0.351562 0.0411523 91 0.851562 0.374486 92 0.226562 0.707819 93 0.726562 0.152263 94 0.476562 0.485597 95 0.976562 0.81893 96 0.0234375 0.263374 97 0.523438 0.596708 98 0.273438 0.930041 99 0.773438 0.0781893 100 0.148438 0.411523 TEST05 HALTON computes the elements of a vector Halton sequence. Each call produces the next value. In this test, we call HALTON several times. DIM_NUM = 4 N = 11 SEED = 0 0 0 0 STEP Halton 0 0 0 0 0 1 0.5 0.333333 0.2 0.142857 2 0.25 0.666667 0.4 0.285714 3 0.75 0.111111 0.6 0.428571 4 0.125 0.444444 0.8 0.571429 5 0.625 0.777778 0.04 0.714286 6 0.375 0.222222 0.24 0.857143 7 0.875 0.555556 0.44 0.0204082 8 0.0625 0.888889 0.64 0.163265 9 0.5625 0.037037 0.84 0.306122 10 0.3125 0.37037 0.08 0.44898 TEST06 HALTON_SEQUENCE computes the next N elements of a vector Halton sequence. Each call produces the next value. By default, the bases are the first DIM_NUM primes. In this test, we demonstrate how one call can compute many successive vector elements of the sequence. DIM_NUM = 4 N = 11 STEP = 0 SEED = 0 0 0 0 STEP Halton 0 0 0 0 0 1 0.5 0.333333 0.2 0.142857 2 0.25 0.666667 0.4 0.285714 3 0.75 0.111111 0.6 0.428571 4 0.125 0.444444 0.8 0.571429 5 0.625 0.777778 0.04 0.714286 6 0.375 0.222222 0.24 0.857143 7 0.875 0.555556 0.44 0.0204082 8 0.0625 0.888889 0.64 0.163265 9 0.5625 0.037037 0.84 0.306122 10 0.3125 0.37037 0.08 0.44898 TEST07 HALTON_STEP_SET specifies which element of the Halton subsequence to compute. In this test, we show how STEP chooses the next element. DIM_NUM = 4 N = 10 STEP = 0 SEED = 0 0 0 0 LEAP = 1 1 1 1 BASE = 2 3 5 7 STEP Halton 0 0 0 0 0 1 0.5 0.333333 0.2 0.142857 2 0.25 0.666667 0.4 0.285714 3 0.75 0.111111 0.6 0.428571 4 0.125 0.444444 0.8 0.571429 5 0.625 0.777778 0.04 0.714286 6 0.375 0.222222 0.24 0.857143 7 0.875 0.555556 0.44 0.0204082 8 0.0625 0.888889 0.64 0.163265 9 0.5625 0.037037 0.84 0.306122 N = 10 STEP = 6 STEP Halton 6 0.375 0.222222 0.24 0.857143 7 0.875 0.555556 0.44 0.0204082 8 0.0625 0.888889 0.64 0.163265 9 0.5625 0.037037 0.84 0.306122 10 0.3125 0.37037 0.08 0.44898 11 0.8125 0.703704 0.28 0.591837 12 0.1875 0.148148 0.48 0.734694 13 0.6875 0.481481 0.68 0.877551 14 0.4375 0.814815 0.88 0.0408163 15 0.9375 0.259259 0.12 0.183673 N = 6 STEP = 0 STEP Halton 0 0 0 0 0 1 0.5 0.333333 0.2 0.142857 2 0.25 0.666667 0.4 0.285714 3 0.75 0.111111 0.6 0.428571 4 0.125 0.444444 0.8 0.571429 5 0.625 0.777778 0.04 0.714286 N = 5 STEP = 100 STEP Halton 100 0.148438 0.411523 0.032 0.291545 101 0.648438 0.744856 0.232 0.434402 102 0.398438 0.1893 0.432 0.577259 103 0.898438 0.522634 0.632 0.720117 104 0.0859375 0.855967 0.832 0.862974 TEST08 HALTON_BASE_GET gets the current bases. HALTON_BASE_SET sets the current bases. HALTON_SEQUENCE computes the next N elements of a vector Halton sequence. In this test, we compute the first 10 elements of a sequence, then change bases, reset the seed and recompute. DIM_NUM = 4 N = 10 STEP = 0 SEED = 0 0 0 0 BASE = 2 3 5 7 STEP Halton 0 0 0 0 0 1 0.5 0.333333 0.2 0.142857 2 0.25 0.666667 0.4 0.285714 3 0.75 0.111111 0.6 0.428571 4 0.125 0.444444 0.8 0.571429 5 0.625 0.777778 0.04 0.714286 6 0.375 0.222222 0.24 0.857143 7 0.875 0.555556 0.44 0.0204082 8 0.0625 0.888889 0.64 0.163265 9 0.5625 0.037037 0.84 0.306122 BASE = 3 7 13 19 STEP Halton 0 0 0 0 0 1 0.333333 0.142857 0.0769231 0.0526316 2 0.666667 0.285714 0.153846 0.105263 3 0.111111 0.428571 0.230769 0.157895 4 0.444444 0.571429 0.307692 0.210526 5 0.777778 0.714286 0.384615 0.263158 6 0.222222 0.857143 0.461538 0.315789 7 0.555556 0.0204082 0.538462 0.368421 8 0.888889 0.163265 0.615385 0.421053 9 0.037037 0.306122 0.692308 0.473684 TEST09 For the unit sphere in 2 dimensions (the circle): HALTON generates "U1" points, U1_TO_SPHERE_UNIT_2D maps U2 points to the circle; DIM_NUM = 1 N = 5 STEP = 0 A few sample values: 1 0 -1 1.22465e-16 6.12323e-17 1 -1.83697e-16 -1 0.707107 0.707107 N = 1000 STEP = 0 Average the points, which should get a value close to zero, and closer as N increases. Average: -3.59712e-17 -2.22045e-18 Now choose a random direction, sample the same number of points, and compute the dot product with the direction. Take the absolute value of each dot product and sum and average. We expect a value near 2 / PI = 0.6366... Random V: 0.867008 -0.498294 Average |(XdotV)| 0.636461 Random V: -0.769054 0.639184 Average |(XdotV)| 0.636493 Random V: -0.460607 -0.887604 Average |(XdotV)| 0.636524 Random V: 0.605572 0.79579 Average |(XdotV)| 0.636443 Random V: 0.219026 -0.975719 Average |(XdotV)| 0.636426 TEST10 For the unit ball in 2 dimensions (the disk): U2_TO_BALL_UNIT_2D samples; DIM_NUM = 2 N = 5 STEP = 0 A few sample values: 0 0 -0.353553 0.612372 -0.25 -0.433013 0.663414 0.55667 -0.332232 0.120922 N = 1000 STEP = 0 Average the points, which should get a value close to zero, and closer as N increases. Average: 0.000588437 0.000106363 Average the distance of the points from the center, which should be DIM_NUM / ( DIM_NUM + 1 ) = 0.666667 Average: 0.665496 Average the angle THETA, which should approach PI. Average: 3.13012 TEST11 For the unit sphere in 3 dimensions: U2_TO_SPHERE_UNIT_3D samples; DIM_NUM = 2 N = 5 STEP = 123456789 A few sample values: 0.745567 0.585674 0.317989 -0.912665 0.365944 -0.182011 0.0815592 -0.569423 0.817989 0.121255 0.577953 -0.807011 -0.932375 -0.305668 0.192989 N = 1000 STEP = 0 Average the points, which should get a value close to zero, and closer as N increases. Average: 0.0007581 -2.60471e-05 -0.00245313 Now choose a random direction, sample the same number of points, and compute the dot product with the direction. Take the absolute value of each dot product and sum and average. Random V: 0.402147 -0.377874 0.83396 Average |(XdotV)| 0.500719 Random V: 0.962942 -0.154988 -0.220728 Average |(XdotV)| 0.500167 Random V: -0.331541 -0.877059 0.347632 Average |(XdotV)| 0.499537 Random V: 0.163484 -0.688001 -0.707056 Average |(XdotV)| 0.500191 Random V: 0.675689 -0.467135 0.570288 Average |(XdotV)| 0.500638 TEST12 For the unit ball in 3 dimensions: U3_TO_BALL_UNIT_3D samples; DIM_NUM = 3 N = 5 STEP = 0 A few sample values: 0 0 -0 -0.292402 0.506455 3.58089e-17 -0.319046 -0.552605 -0.368403 0.559545 0.469514 0.421716 -0.576994 0.210009 -0.696238 N = 1000 STEP = 0 Average the points, which should get a value close to zero, and closer as N increases. Average: 0.000437565 0.000566738 -0.00171389 Average the distance of the points from the center, which should be DIM_NUM / ( DIM_NUM + 1 ) = 0.75 Average: 0.748738 Average the angle THETA, which should approach PI. Average: 3.13012 Average the angle PHI, which should approach PI/2. Average: 1.57136 TEST13 HALHAM_WRITE writes a Halton or Hammersley dataset to a file DIM_NUM = 3 N = 10 STEP = 0 SEED = 0 0 0 LEAP = 1 1 1 BASE = 2 3 5 STEP Halton 0 0 0 0 1 0.5 0.333333 0.2 2 0.25 0.666667 0.4 3 0.75 0.111111 0.6 4 0.125 0.444444 0.8 5 0.625 0.777778 0.04 6 0.375 0.222222 0.24 7 0.875 0.555556 0.44 8 0.0625 0.888889 0.64 9 0.5625 0.037037 0.84 The data was written to "halton_03_00010.txt". HALTON_PRB: Normal end of execution. 01 May 2011 11:26:03 AM