10-Feb-2019 08:30:42 walker_sample_test: MATLAB version. Test walker_sample. I4_CHOOSE_TEST I4_CHOOSE evaluates C(N,K). N K CNK 0 0 1 1 0 1 1 1 1 2 0 1 2 1 2 2 2 1 3 0 1 3 1 3 3 2 3 3 3 1 4 0 1 4 1 4 4 2 6 4 3 4 4 4 1 I4_UNIFORM_AB_TEST I4_UNIFORM_AB computes pseudorandom values in an interval [A,B]. The lower endpoint A = -100.000000 The upper endpoint B = 200.000000 The initial seed is 123456789 1 -35 2 187 3 149 4 69 5 25 6 -81 7 -23 8 -67 9 -87 10 90 11 -82 12 35 13 20 14 127 15 139 16 -100 17 170 18 5 19 -72 20 -96 NORMALIZE_TEST NORMALIZE normalizes entries 1 through N of a vector of length N+2. Initial X: 1: 0.218418 2: 0.956318 3: 0.829509 4: 0.561695 5: 0.415307 6: 0.0661187 7: 0.257578 Initial L1 norm of X(1:N) = 2.82895 Normalized X: 1: 0.218418 2: 0.338047 3: 0.293222 4: 0.198553 5: 0.146806 6: 0.0233722 7: 0.257578 Final L1 norm of X(1:N) = 1 NORMALIZE_TEST Normal end of execution. R8_UNIFORM_01_TEST R8_UNIFORM_01 produces a sequence of random values. Using random seed 123456789 SEED R8_UNIFORM_01(SEED) 469049721 0.218418 2053676357 0.956318 1781357515 0.829509 1206231778 0.561695 891865166 0.415307 141988902 0.066119 553144097 0.257578 236130416 0.109957 94122056 0.043829 1361431000 0.633966 Verify that the sequence can be restarted. Set the seed back to its original value, and see that we generate the same sequence. SEED R8_UNIFORM_01(SEED) 469049721 0.218418 2053676357 0.956318 1781357515 0.829509 1206231778 0.561695 891865166 0.415307 141988902 0.066119 553144097 0.257578 236130416 0.109957 94122056 0.043829 1361431000 0.633966 R8VEC_PRINT_TEST R8VEC_PRINT prints an R8VEC. The R8VEC: 1: 123.456 2: 5e-06 3: -1e+06 4: 3.14159 R8VEC_UNIFORM_01 R8VEC_UNIFORM_01 returns a random R8VEC with entries in [ 0.0, 1.0 ] Input SEED = 123456789 Random R8VEC: 1: 0.218418 2: 0.956318 3: 0.829509 4: 0.561695 5: 0.415307 6: 0.0661187 7: 0.257578 8: 0.109957 9: 0.043829 10: 0.633966 Input SEED = 1361431000 Random R8VEC: 1: 0.0617272 2: 0.449539 3: 0.401306 4: 0.754673 5: 0.797287 6: 0.00183837 7: 0.897504 8: 0.350752 9: 0.0945448 10: 0.0136169 Input SEED = 29242052 Random R8VEC: 1: 0.859097 2: 0.840847 3: 0.123104 4: 0.00751236 5: 0.260303 6: 0.912484 7: 0.113664 8: 0.351629 9: 0.822887 10: 0.267132 RANDOM_PERMUTATION_TEST RANDOM_PERMUTATION randomly permutes entries 1 through N of a vector X[0:N+1]. Initial X: 1: 0 2: 1 3: 2 4: 3 5: 4 6: 5 7: 6 Permuted X: 1: 0 2: 2 3: 5 4: 1 5: 3 6: 4 7: 6 RANDOM_PERMUTATION_TEST Normal end of execution. WALKER_BUILD_TEST WALKER_BUILD builds the Walker sampler data vectors Y and A, given a probability vector X. Binomial PDF (ignore first and last entries): 1: 0 2: 0.0625 3: 0.25 4: 0.375 5: 0.25 6: 0.0625 7: 0 I A[I] Y[i] (ignore first and last entries) 0 0 0 1 3 0.3125 2 2 1 3 4 0.5 4 2 0.75 5 3 0.3125 6 6 2 WALKER_BUILD_TEST Normal end of execution. WALKER_SAMPLER_TEST: WALKER_SAMPLER creates Walker sample vectors Y and A for efficiently sampling a discrete probability vector. Test the Walker sampler with a Zipf-type probability. Zipf probabilities for N = 10 and parameter P = 2 I X(I) 1 0.645258 2 0.161314 3 0.0716953 4 0.0403286 5 0.0258103 6 0.0179238 7 0.0131685 8 0.0100822 9 0.00796615 10 0.00645258 Randomly permuted X: I X(I) 1 0.0716953 2 0.00645258 3 0.00796615 4 0.0131685 5 0.0403286 6 0.0179238 7 0.0100822 8 0.0258103 9 0.645258 10 0.161314 Built the sampler i Y(i) A(i): 1 0.716953 10 2 0.0645258 9 3 0.0796615 9 4 0.131685 9 5 0.403286 9 6 0.179238 9 7 0.100822 9 8 0.258103 9 9 0.669902 10 10 1 10 100000 samples: prob #samples: 0.0716953 7294 0.00645258 618 0.00796615 781 0.0131685 1361 0.0403286 4149 0.0179238 1850 0.0100822 986 0.0258103 2524 0.645258 64569 0.161314 15868 sumvar = 1.63761 (should be about 1) WALKER_VERIFY_TEST WALKER_VERIFY verifies the Walker sampler data vectors Y and A,for a given probability vector X. Benford PDF (ignore first and last entries): 1: 0 2: 0.30103 3: 0.176091 4: 0.124939 5: 0.09691 6: 0.0791812 7: 0.0669468 8: 0.0579919 9: 0.0511525 10: 0.0457575 11: 0 I A(I) Y(i) (ignore first and last entries) 0 0 0 1 1 1 2 1 0.896612 3 2 0.72697 4 2 0.87219 5 2 0.712631 6 3 0.602521 7 1 0.521928 8 1 0.460373 9 1 0.411817 10 10 2 The verification sum = 1.38778e-16 It should be very close to zero. WALKER_VERIFY_TEST Normal end of execution. ZIPF_PROBABILITY_TEST ZIPF_PROBABILITY sets up a probablity vector X of N+2 elements containing in X[1:N] the probabilities of outcomes 1 through Nin a Zipf distribution with parameter P. X for N = 5, P = 1.0 1: 0 2: 0.437956 3: 0.218978 4: 0.145985 5: 0.109489 6: 0.0875912 7: 0 X for N = 5, P = 2.0 1: 0 2: 0.683242 3: 0.17081 4: 0.0759157 5: 0.0427026 6: 0.0273297 7: 0 X for N = 10, P = 2.0 1: 0 2: 0.645258 3: 0.161314 4: 0.0716953 5: 0.0403286 6: 0.0258103 7: 0.0179238 8: 0.0131685 9: 0.0100822 10: 0.00796615 11: 0.00645258 12: 0 ZIPF_PROBABILITY_TEST Normal end of execution. walker_sample_test: Normal end of execution. 10-Feb-2019 08:30:53