/* Probabilistic programming - tests in Picat. This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. import ppl_utils. import ppl_distributions. import cp. main => go. go ?=> % test_distribution($binomial_dist(10,1/2)), % nl, % test_distribution($pascal_dist(10,1/2)), % nl, % test_distribution($normal_dist(100,15)), % nl, % test_distribution($gamma_dist(2,3)), % nl, % test_distribution($negative_binomial_dist(10,1/2)), % nl, % test_distribution($cauchy_dist(1,1)), % nl, % test_distribution($categorical_dist([1/3,1/3,1/3],[1,2,3])), % nl, % test_distribution($frechet_dist(2,3)), nl, test_distribution($beta_dist(100,100)), nl, nl. go => true. /* Benford dist = benford_dist(10) Random sample sample = [2,1,3,6,3,3,3,9,2,3,2,1,3,2,5,4,8,3,6,8] Mean: sample_mean = 3.4753 3.44024 Variance: sample_variance = 6.15999 Variance: Not supported PDF: 1 0.301029995663981 2 0.176091259055681 3 0.1249387366083 4 0.096910013008056 5 0.079181246047625 6 0.066946789630613 7 0.057991946977687 8 0.051152522447381 9 0.045757490560675 CDF: 1 0.301029995663981 2 0.477121254719662 3 0.602059991327962 4 0.698970004336019 5 0.778151250383644 6 0.845098040014257 7 0.903089986991943 8 0.954242509439325 9 1.0 Quantile: 0.01 1 0.025 1 0.05 1 0.25 1 0.5 3 0.75 5 0.84 6 0.975 9 0.99 9 0.999 9 0.9999 9 0.999999 9 */ test_benford => test_distribution($benford_dist(10)), nl. /* dist = cauchy_dist(1,1) special = (map)[cdf = [0.15,0.95],pdf = [0.15,0.95]] Random sample sample = [3.51713,9.6905,5.4842,1.81128,-0.888343,5.19966,0.0613545,2.55369,3.46807,4.06284,0.925141,9.94762,1.466,1.97522,-2.26747,-1.14398,-1.02741,1.55756,1.76025,4.97166] Mean: sample_mean = -0.726625 indeterminate Variance: sample_variance = 13698.7 variance = indeterminate PDF: -0.96261050550515 0.065606014713031 0.03738949449485 0.165216832498284 1.03738949449485 0.31786551835872 2.03738949449485 0.153315392576 3.03738949449485 0.061796274154319 4.03738949449485 0.031128313809426 5.03738949449485 0.018398868812047 6.03738949449485 0.012068487245179 7.03738949449485 0.008499580106648 CDF: -0.96261050550515 0.15 0.03738949449485 0.256063356021575 1.03738949449485 0.511895904412608 2.03738949449485 0.755840861537877 3.03738949449485 0.85476155450794 4.03738949449485 0.898760555269781 5.03738949449485 0.922714848260185 6.03738949449485 0.937621521572806 7.03738949449485 0.947751265349754 Quantile: 0.01 -30.820515953773853 0.025 -11.706204736174696 0.05 -5.313751514675041 0.25 0.0 0.5 1.0 0.75 2.0 0.84 2.818993247281066 0.975 13.706204736174696 0.99 32.82051595377385 0.999 319.30883898554157 0.9999 3184.098757116828892 0.999999 318310.886177819047589 */ test_cauchy => Dist = $cauchy_dist(1,1), test_distribution(Dist,new_map([cs=[0.15,0.95]])), nl. /* Pareto type 1 dist = pareto1_dist(1,4) special = (map)[] Random sample sample = [1.5297,1.00999,1.12454,1.25667,1.14454,1.82078,1.18955,1.18298,1.43476,1.25692,1.3594,1.44421,1.40144,1.11496,1.06843,1.56089,1.49262,1.14594,1.12271,1.3733] Mean: sample_mean = 1.33041 1.33333 Variance: sample_variance = 0.231965 variance = 0.222222 PDF: 1.002515743147813 3.950062656937378 1.146499870949184 2.019249297309051 1.290483998750555 1.117626965753616 1.434468126551926 0.658575359085136 1.578452254353297 0.408227956261818 1.722436382154668 0.263842066497408 1.866420509956039 0.176608865255902 2.01040463775741 0.121798686295273 2.154388765558781 0.086186573083288 2.298372893360152 0.062367385192346 2.442357021161523 0.046027167203145 2.586341148962894 0.034564552905676 2.730325276764265 0.02636258801957 2.874309404565635 0.020388835031849 3.018293532367006 0.015968077279834 3.162277660168377 0.012649110640674 CDF: 1.002515743147813 0.01 1.146499870949184 0.421232735305236 1.290483998750555 0.639430071030706 1.434468126551926 0.763823659614971 1.578452254353297 0.838907915537124 1.722436382154668 0.886387206380498 1.866420509956039 0.917593397911581 2.01040463775741 0.938783839049806 2.154388765558781 0.953580153801838 2.298372893360152 0.96416412311104 2.442357021161523 0.971896306254306 2.586341148962894 0.977651068631136 2.730325276764265 0.982005389892311 2.874309404565635 0.985349044929955 3.018293532367006 0.987950913905485 3.162277660168377 0.99 Quantile: 0.01 1.002515743147813 0.025 1.006349525306027 0.05 1.01290589497996 0.25 1.074569931823542 0.5 1.189207115002721 0.75 1.414213562373095 0.84 1.58113883008419 0.975 2.51486685936587 0.99 3.162277660168379 0.999 5.623413251903489 0.9999 10.000000000000275 0.999999 31.622776601456462 */ test_pareto1 => test_distribution($pareto1_dist(1,4)), nl. /* Matching dist dist = matching_dist(10) Random sample sample = [3,0,0,1,1,0,2,1,0,2,2,0,1,1,0,0,2,0,1,2] Mean: sample_mean = 1.0006 1 Variance: sample_variance = 1.0068 variance = 1 PDF: 0 0.367879464285714 1 0.367879188712522 2 0.183940972222222 3 0.061309523809524 4 0.015335648148148 CDF: 0 0.367879464285714 1 0.735758652998237 2 0.919699625220459 3 0.981009149029983 4 0.996344797178131 Quantile: 0.01 0 0.025 0 0.05 0 0.25 0 0.5 1 0.75 2 0.84 2 0.975 3 0.99 4 0.999 5 0.9999 6 0.999999 8 */ test_matching_dist => test_distribution($matching_dist(10)), nl. test_matching_dist => true. /* Zipf distribution. There are two versions of zipf: zipf(N,S) and zipf(Rho), and both have one "original" and one Mathematica compliant version. */ /* Zipf / 1: dist = zipf_dist(4) Random sample sample = [1,1,1,1,1,1,1,2,1,2,1,2,1,1,4,1,1,1,1,1] Mean: sample_mean = 1.3052 1.11063 Variance: sample_variance = 0.923653 variance = 0.286326 PDF: 1 0.923938402921824 2 0.057746150182614 3 0.011406646949652 4 0.003609134386413 CDF: 1 0.923938402921571 2 0.981684553104185 3 0.993091200053837 4 0.99670033444025 Quantile: 0.01 1 0.025 1 0.05 1 0.25 1 0.5 1 0.75 1 0.84 2 0.975 3 0.99 4 0.999 7 0.9999 15 0.999999 68 */ test_zipf_1 => test_distribution($zipf_dist(4)), nl. test_zipf_1 => true. /* Zipf MMA / 1 dist = zipf_mma_dist(3) Random sample sample = [1,2,2,1,1,1,2,1,1,1,1,1,1,1,2,1,1,3,1,1] Mean: sample_mean = 1.2989 1.11063 Variance: sample_variance = 0.872559 variance = 0.286326 PDF: 1 0.923938402921824 2 0.057746150182614 3 0.011406646949652 4 0.003609134386413 CDF: 1 0.923938402921571 2 0.981684553104185 3 0.993091200053837 4 0.99670033444025 Quantile: 0.01 1 0.025 1 0.05 1 0.25 1 0.5 1 0.75 1 0.84 2 0.975 3 0.99 4 0.999 7 0.9999 15 0.999999 68 */ test_zipf_mma_1 => test_distribution($zipf_mma_dist(3)), nl. test_zipf_mma_1 => true. /* Zipf / 2: dist = zipf_dist(15,0.3) Random sample sample = [12,9,11,9,12,11,1,8,10,3,7,14,1,6,1,4,1,10,3,8] Mean: sample_mean = 7.0346 7.01817 Variance: sample_variance = 19.4798 variance = 19.3572 PDF: 1 0.113298111977239 2 0.092026662956149 3 0.081486618564136 4 0.0747488775148 5 0.0699087716722 6 0.066187701199686 7 0.063196534086971 8 0.060714954886335 9 0.058607057868281 10 0.056783567317065 11 0.055182944115892 12 0.053761118908756 13 0.052485539666318 14 0.051331536253551 15 0.050280003012621 CDF: 1 0.113298111977239 2 0.205324774933388 3 0.286811393497524 4 0.361560271012324 5 0.431469042684523 6 0.49765674388421 7 0.560853277971181 8 0.621568232857516 9 0.680175290725797 10 0.736958858042862 11 0.792141802158754 12 0.84590292106751 13 0.898388460733828 14 0.949719996987379 15 1.0 Quantile: 0.01 1 0.025 1 0.05 1 0.25 3 0.5 7 0.75 11 0.84 12 0.975 15 0.99 15 0.999 15 0.9999 15 0.999999 15 */ test_zipf_2 => test_distribution($zipf_dist(15,0.3)), nl. test_zipf_2 => true. /* Zipf MMA / 2: Random: [1,4,2,2,11,15,12,6,8,6,1,2,1,1,3,1,2,2,4,9] mean = 3.5318 = 3.57738 variance = 12.0826 = 12.309 PDF: 0 = 0.0 1 = 0.40531 2 = 0.164607 3 = 0.0971695 4 = 0.0668513 5 = 0.050018 6 = 0.0394631 7 = 0.0322969 8 = 0.0271501 9 = 0.0232955 10 = 0.0203136 CDF: 0 = 0.0 1 = 0.40531 2 = 0.569918 3 = 0.667087 4 = 0.733938 5 = 0.783956 6 = 0.823419 7 = 0.855716 8 = 0.882866 9 = 0.906162 10 = 0.926476 Quantile: 0.0100000 = 1 0.0250000 = 1 0.0500000 = 1 0.2500000 = 1 0.5000000 = 2 0.7500000 = 5 0.8400000 = 7 0.9750000 = 14 0.9900000 = 15 0.9990000 = 15 0.9999000 = 15 0.9999990 = 15 Survival function: 0.33291297303423262 Hazard function: 0.49444499283509663 */ test_zipf_mma_2 => _ = random2(), println("Zipf MMA / 2:"), N = 15, S = 0.3, Qs = [0.01,0.025,0.05,0.25,0.50,0.75,0.84,0.975,0.99,0.999,0.9999,0.999999], println("Random:"), println([zipf_mma_dist(N,S) : _ in 1..20]), Samples = [zipf_mma_dist(N,S) : _ in 1..10000], println(mean=avg(Samples)=zipf_mma_dist_mean(N,S)), println(variance=variance(Samples)=zipf_mma_dist_variance(N,S)), println("\nPDF:"), foreach(I in 0..10) printf("%d = %w\n",I,zipf_mma_dist_pdf(N,S,I) ), end, println("\nCDF:"), foreach(I in 0..10) printf("%d = %w\n",I,zipf_mma_dist_cdf(N,S,I)) end, println("\nQuantile:"), foreach(Q in Qs) printf("%.7f = %w\n",Q,zipf_mma_dist_quantile(N,S,Q)) end, println("\nSurvival function:"), printf("%.17f\n",survival_function(zipf_mma,[N,S,3])), println("\nHazard function:"), printf("%.17f\n",hazard_function_discrete(zipf_mma,[N,S,3])), nl. test_zipf_mma_2 => true. /* Hypergeometric1_dist Cf hypergeometric_dist (which is probably a little clearer to use) Hypergeometric1: Random: [0,1,2,0,0,0,2,0,1,1,0,0,2,1,2,1,2,0,1,2] mean = 0.7986 variance = 0.605838 PDF: 0 = 0.310562782004569 (82251 / 264845) 1 = 0.431337197228568 (45695 / 105938) 2 = 0.209839717570655 (11115 / 52969) 3 = 0.044176782646454 (2340 / 52969) 4 = 0.003964583058015 (30 / 7567) 5 = 0.00011893749174 (9 / 75670) CDF: 0 = 0.310562782004569 (82251 / 264845) 1 = 0.741899979233136 (28149739249 / 37942768617) 2 = 0.951739696803791 (65468263093838149 / 68787992466531507) 3 = 0.995916479450245 (22362864139273279 / 22454557787433937) 4 = 0.99988106250826 (89640869446172701 / 89651532374564001) 5 = 1.0 (4503599627370497 / 4503599627370496) Quantile: 0.0100000 = 0 0.0250000 = 0 0.0500000 = 0 0.2500000 = 0 0.5000000 = 1 0.7500000 = 2 0.8400000 = 2 0.9750000 = 3 0.9900000 = 3 0.9990000 = 4 0.9999000 = 5 0.9999990 = 5 Survival function: 0.00408352054975536 Hazard function: 51.38696255201308105 */ test_hypergeometric1 => _ = random2(), println("Hypergeometric1:"), K = 5, N = 50, Kk = 4, Nn = 10, Qs = [0.01,0.025,0.05,0.25,0.50,0.75,0.84,0.975,0.99,0.999,0.9999,0.999999], println("Random:"), println([hypergeometric1_dist(K,N,Kk,Nn) : _ in 1..20]), Samples = [hypergeometric1_dist(K,N,Kk,Nn) : _ in 1..10000], println(mean=avg(Samples)), println(variance=variance(Samples)), println("\nPDF:"), foreach(I in 0..5) printf("%d = %w\n",I,hypergeometric1_dist_pdf(N,K,Nn,I).and_rat ), end, println("\nCDF:"), foreach(I in 0..5) printf("%d = %w\n",I,hypergeometric1_dist_cdf(N,K,Nn,I).and_rat()) end, println("\nQuantile:"), foreach(Q in Qs) printf("%.7f = %w\n",Q,hypergeometric1_dist_quantile(N,K,Nn,Q)) end, println("\nSurvival function:"), printf("%.17f\n",survival_function(hypergeometric1,[N,K,Nn,3])), println("\nHazard function:"), printf("%.17f\n",hazard_function_discrete(hypergeometric1,[N,K,Nn,3])), nl. test_hypergeometric1 => true. /* Laplace dist = laplace_dist(10,4) Random sample sample = [9.05076,2.19725,14.8843,9.81237,7.88457,-4.08603,14.4346,-2.58902,7.87137,1.45859,9.71005,6.06047,9.80938,5.02859,11.4847,8.76456,10.3737,13.369,9.82617,8.14232] Mean: sample_mean = 9.97418 10 Variance: sample_variance = 33.3721 variance = 32.0 PDF: 3.562248350263599 0.025 4.562248350263599 0.032100635417194 5.562248350263599 0.041218031767503 6.562248350263599 0.052925000415317 7.562248350263599 0.067957045711476 8.562248350263598 0.087258573936546 9.562248350263598 0.112042226758452 10.562248350263598 0.108608714656528 11.562248350263598 0.084584552022883 12.562248350263598 0.065874515351165 13.562248350263598 0.051303124139937 14.562248350263598 0.039954913254192 15.562248350263598 0.031116917729915 CDF: 3.562248350263599 0.1 4.562248350263599 0.128402541668774 5.562248350263599 0.164872127070013 6.562248350263599 0.211700001661267 7.562248350263599 0.271828182845905 8.562248350263598 0.349034295746184 9.562248350263598 0.448168907033806 10.562248350263598 0.565565141373887 11.562248350263598 0.661661791908468 12.562248350263598 0.736501938595339 13.562248350263598 0.794787503440253 14.562248350263598 0.840180346983231 15.562248350263598 0.87553232908034 Quantile: 0.000001 -42.489453509617313 0.00001 -33.279113137641133 0.001 -14.858432393688766 0.01 -5.648092021712584 0.025 -1.982929094215963 0.05 0.789659628023818 0.25 7.227411277760218 0.5 10.0 0.75 12.772588722239782 0.84 14.557737132753459 0.975 21.982929094215962 0.99 25.648092021712579 0.999 34.858432393688759 0.99999 53.279113137659337 0.999999 62.48945350950229 */ test_laplace => test_distribution($laplace_dist(10,5),[0.1,0.9]), nl. /* Dirichlet distribution Dirichlet: Random: [[0.208904,0.784569,0.00652739],[0.00929637,0.709181,0.281523],[0.0162785,0.859777,0.123944],[0.161369,0.821719,0.0169116],[0.188908,0.0493177,0.761774],[0.0230585,0.148798,0.828143],[0.32467,0.406406,0.268924],[0.00880658,0.985244,0.00594917],[0.0209049,0.411901,0.567194],[0.811448,0.0516273,0.136925],[0.00785366,0.992061,8.53461e-05],[0.289337,0.0170928,0.693571],[0.155394,0.0972661,0.74734],[0.352834,0.00563873,0.641527],[0.30092,0.015105,0.683975],[0.0296707,0.141707,0.828622],[0.249743,0.00413089,0.746126],[0.0034594,0.182098,0.814443],[0.905709,0.00988672,0.0844046],[0.148695,0.334942,0.516363]] mean = [0.2,0.5,0.3] variance = [0.08,0.125,0.105] PDF: [0.1,0.4,0.5] = 0.66577047934341849 [0.2,0.2,0.6] = 0.47597995481385724 [0.8,0.1,0.1] = 0.77832600926506790 [0.0,0.3,0.7] = 0.00000000000000000 */ test_dirichlet => _ = random2(), println("Dirichlet:"), Alpha = [0.2,0.5,0.3], % Qs = [0.01,0.025,0.05,0.25,0.50,0.75,0.84,0.975,0.99,0.999,0.9999,0.999999], println("Random:"), println([dirichlet_dist(Alpha) : _ in 1..20]), % Samples = [dirichlet_dist(Alpha) : _ in 1..10000], println(mean=dirichlet_dist_mean(Alpha)), println(variance=dirichlet_dist_variance(Alpha)), println("\nPDF:"), foreach(I in [[0.1,0.4,0.5],[0.2,0.2,0.6],[0.8,0.1,0.1],[0.0,0.3,0.7]]) printf("%w = %.17f\n",I,dirichlet_dist_pdf(Alpha,I) ), end, % println("\nCDF:"), % foreach(I in 10..20) % printf("%d = %w\n",I,dirichlet_dist_cdf(Alpha,I)) % end, % println("\nQuantile:"), % foreach(Q in Qs) % printf("%.7f = %w\n",Q,dirichlet_dist_quantile(Alpha,Q)) % end, % println("\nSurvival function:"), % printf("%.17f\n",survival_function(dirichlet,[Alpha,3])), % println("\nHazard function:"), % printf("%.17f\n",hazard_function_discrete(dirichlet,[Alpha,3])), nl. test_dirichlet => true. /* Negative Hypergeometric dist = negative_hypergeometric_dist(3,10,20) Random sample sample = [5,2,10,10,5,3,7,0,2,1,11,3,2,8,3,2,5,6,2,8] Mean: sample_mean = 5.4558 mean = 5.45455 Variance: sample_variance = 10.0786 Variance: Not supported PDF: 0 0.029556650246305 1 0.06568144499179 2 0.095995958064923 3 0.115195149677907 4 0.122394846532778 5 0.119201937492792 6 0.108365397720719 7 0.09288462661776 8 0.07546875912693 9 0.058256585992718 10 0.04272149639466 11 0.029699435996288 12 0.019490254872564 13 0.011994002998501 14 0.006853715999143 CDF: 0 0.029556650246305 1 0.095238095238095 2 0.191234053303018 3 0.306429202980926 4 0.428824049513703 5 0.548025987006495 6 0.656391384727215 7 0.749276011344975 8 0.824744770471905 9 0.883001356464622 10 0.925722852859282 11 0.95542228885557 12 0.974912543728133 13 0.986906546726634 14 0.993760262725777 Quantile: 0.000001 0 0.00001 0 0.001 0 0.01 0 0.025 0 0.05 1 0.25 3 0.5 5 0.75 8 0.84 9 0.975 13 0.99 14 0.999 16 0.99999 19 0.999999 20 */ test_negative_hypergeometric => _ = random2(), test_distribution($negative_hypergeometric_dist(3,10,20)), nl. test_negative_hypergeometric => true. /* Categorical: Random: [4,4,1,4,4,1,4,3,3,4,1,1,3,4,4,3,1,1,4,3] mean = 3.0 = 2.9992 variance = 1.0 = 0.989199 PDF: 1 = 0.1 (1 / 10) 2 = 0.2 (1 / 5) 3 = 0.3 (3 / 10) 4 = 0.4 (2 / 5) CDF: 1 = 0.1 (1 / 10) 2 = 0.3 (1125899906842624 / 3752999689475413) 3 = 0.6 (1688849860263938 / 2814749767106563) 4 = 1.0 (1 / 1) Quantile: 0.0100000 = 1 0.0250000 = 1 0.0500000 = 1 0.2500000 = 2 0.5000000 = 3 0.7500000 = 4 0.8400000 = 4 0.9750000 = 4 0.9900000 = 4 0.9990000 = 4 0.9999000 = 4 0.9999990 = 4 */ test_categorical => _ = random2(), println("Categorical:"), Probs = [1/10,2/10,3/10,4/10], Values = [1,2,3,4], Len = Probs.len, Qs = [0.01,0.025,0.05,0.25,0.50,0.75,0.84,0.975,0.99,0.999,0.9999,0.999999], println("Random:"), println([categorical_dist(Probs,Values) : _ in 1..20]), Samples = [categorical_dist(Probs,Values) : _ in 1..10000], println(mean=categorical_dist_mean(Probs,Values)=avg(Samples)), println(variance=categorical_dist_variance(Probs,Values)=variance(Samples)), println("\nPDF:"), foreach(I in 1..Len) printf("%d = %w\n",I,categorical_dist_pdf(Probs,Values,I).and_rat), end, println("\nCDF:"), foreach(I in 1..Len) printf("%d = %w\n",I,categorical_dist_cdf(Probs,Values,I).and_rat) end, println("\nQuantile:"), foreach(Q in Qs) printf("%.7f = %w\n",Q,categorical_dist_quantile_value(Probs,Values,Q)) end, % println("\nSurvival function:"), % printf("%.17f\n",survival_function(categorical,[Probs,Values,3])), % println("\nHazard function:"), % printf("%.17f\n",hazard_function_cont(categorical,[Probs,Values,3])), nl. test_categorical => true. /* Poisson: Random: [11,8,4,19,7,12,10,7,8,3,14,6,6,8,10,13,7,6,6,8] mean = 10 = 10.0857 variance = 10 = 10.004 PDF: 1 = 0.000453999297625 (186039 / 409778167) 2 = 0.002269996488124 (1055980 / 465190147) 3 = 0.007566654960414 (2807561 / 371043878) 4 = 0.018916637401035 (5824559 / 307906679) 5 = 0.037833274802071 (4944678 / 130696537) 6 = 0.063055458003451 (22223167 / 352438436) 7 = 0.090079225719216 (37063834 / 411458177) 8 = 0.11259903214902 (54221943 / 481548926) 9 = 0.125110035721133 (21789225 / 174160489) 10 = 0.125110035721133 (19359183 / 154737251) 11 = 0.113736396110121 (88958494 / 782146235) 12 = 0.094780330091768 (16622329 / 175377412) 13 = 0.072907946224437 (20945776 / 287290715) 14 = 0.052077104446026 (19823107 / 380649178) 15 = 0.034718069630684 (20163220 / 580770193) 16 = 0.021698793519178 (5432083 / 250340324) 17 = 0.012763996187751 (4687965 / 367280351) 18 = 0.007091108993195 (1001180 / 141188071) 19 = 0.003732162627998 (227651 / 60997074) 20 = 0.001866081313999 (227651 / 121994148) CDF: 1 = 0.000499399227387 (79447 / 159085148) 2 = 0.002769395715512 (686884 / 248026671) 3 = 0.010336050675926 (3105927 / 300494560) 4 = 0.029252688076961 (16069324 / 549328115) 5 = 0.067085962879032 (37392397 / 557380343) 6 = 0.130141420882483 (15015587 / 115379000) 7 = 0.220220646601699 (33601148 / 152579463) 8 = 0.332819678750719 (39752693 / 119442135) 9 = 0.457929714471852 (42403367 / 92597981) 10 = 0.583039750192986 (107370407 / 184156238) 11 = 0.696776146303107 (110136757 / 158066199) 12 = 0.791556476394874 (69488799 / 87787544) 13 = 0.864464422619311 (64114196 / 74166379) 14 = 0.916541527065337 (86786935 / 94689583) 15 = 0.951259596696021 (94048231347951745 / 98867051301880549) 16 = 0.972958390215199 (91523309 / 94067033) 17 = 0.985722386402951 (23115804563 / 23450623504) 18 = 0.992813495396146 (16453578570505357 / 16572678198678351) 19 = 0.996545658024143 (66716371781379049 / 66947631796076430) 20 = 0.998411739338142 (128895929 / 129100975) Quantile: 0.0100000 = 3 0.0250000 = 4 0.0500000 = 5 0.2500000 = 8 0.5000000 = 10 0.7500000 = 12 0.8400000 = 13 0.9750000 = 17 0.9900000 = 18 0.9990000 = 21 0.9999000 = 24 0.9999990 = 28 Survival function: 0.98966394932407431 Hazard function: 0.00764568110779629 */ test_poisson => _ = random2(), println("Poisson:"), Lambda = 10, Qs = [0.01,0.025,0.05,0.25,0.50,0.75,0.84,0.975,0.99,0.999,0.9999,0.999999], println("Random:"), println([poisson_dist(Lambda) : _ in 1..20]), Samples = [poisson_dist(Lambda) : _ in 1..10000], println(mean=poisson_dist_mean(Lambda)=avg(Samples)), println(variance=poisson_dist_variance(Lambda)=variance(Samples)), println("\nPDF:"), foreach(I in 1..20) printf("%d = %w\n",I,poisson_dist_pdf(Lambda,I).and_rat), end, println("\nCDF:"), foreach(I in 1..20) printf("%d = %w\n",I,poisson_dist_cdf(Lambda,I).and_rat) end, println("\nQuantile:"), foreach(Q in Qs) printf("%.7f = %w\n",Q,poisson_dist_quantile(Lambda,Q)) end, println("\nSurvival function:"), printf("%.17f\n",survival_function(poisson,[Lambda,3])), println("\nHazard function:"), printf("%.17f\n",hazard_function_cont(poisson,[Lambda,3])), nl. test_poisson => true. /* Discrete Uniform: Random: [12,12,5,3,9,11,12,1,10,8,11,2,11,5,1,11,6,11,12,12] mean = 6.5 = 6.5216 variance = 11.9167 = 11.8683 PDF: 1.000000 = 0.083333333333333 (1 / 12) 2.000000 = 0.083333333333333 (1 / 12) 3.000000 = 0.083333333333333 (1 / 12) 4.000000 = 0.083333333333333 (1 / 12) 5.000000 = 0.083333333333333 (1 / 12) 6.000000 = 0.083333333333333 (1 / 12) 7.000000 = 0.083333333333333 (1 / 12) 8.000000 = 0.083333333333333 (1 / 12) 9.000000 = 0.083333333333333 (1 / 12) 10.000000 = 0.083333333333333 (1 / 12) 11.000000 = 0.083333333333333 (1 / 12) 12.000000 = 0.083333333333333 (1 / 12) CDF: 1.000000 = 0.083333333333333 (1 / 12) 2.000000 = 0.166666666666667 (1 / 6) 3.000000 = 0.25 (1 / 4) 4.000000 = 0.333333333333333 (1 / 3) 5.000000 = 0.416666666666667 (5 / 12) 6.000000 = 0.5 (1 / 2) 7.000000 = 0.583333333333333 (7 / 12) 8.000000 = 0.666666666666667 (2 / 3) 9.000000 = 0.75 (3 / 4) 10.000000 = 0.833333333333333 (5 / 6) 11.000000 = 0.916666666666667 (11 / 12) 12.000000 = 1.0 (1 / 1) Quantile: 0.0100000 = 1 0.0250000 = 1 0.0500000 = 1 0.2500000 = 4 0.5000000 = 7 0.7500000 = 10 0.8400000 = 11 0.9750000 = 12 0.9900000 = 12 0.9990000 = 12 0.9999000 = 12 0.9999990 = 12 Survival function: 0.75000000000000000 Hazard function: 0.11111111111111110 */ test_discrete_uniform => _ = random2(), println("Discrete Uniform:"), Low = 1, Up = 12, Qs = [0.01,0.025,0.05,0.25,0.50,0.75,0.84,0.975,0.99,0.999,0.9999,0.999999], println("Random:"), println([discrete_uniform_dist(Low,Up) : _ in 1..20]), Samples = [discrete_uniform_dist(Low,Up) : _ in 1..10000], println(mean=discrete_uniform_dist_mean(Low,Up)=avg(Samples)), println(variance=discrete_uniform_dist_variance(Low,Up)=variance(Samples)), println("\nPDF:"), foreach(I in Low..Up) printf("%f = %w\n",I,discrete_uniform_dist_pdf(Low,Up,I).and_rat), end, println("\nCDF:"), foreach(I in Low..Up) printf("%f = %w\n",I,discrete_uniform_dist_cdf(Low,Up,I).and_rat) end, println("\nQuantile:"), foreach(Q in Qs) printf("%.7f = %w\n",Q,discrete_uniform_dist_quantile(Low,Up,Q)) end, println("\nSurvival function:"), printf("%.17f\n",survival_function(discrete_uniform,[Low,Up,3])), println("\nHazard function:"), printf("%.17f\n",hazard_function_cont(discrete_uniform,[Low,Up,3])), nl. test_discrete_uniform => true. /* Uniform: Random: [5.74715,10.2571,9.78027,9.63703,5.99189,8.07194,5.36174,9.00423,4.56201,5.47447,9.07768,3.8545,7.95481,3.20432,6.64246,11.1399,6.80223,11.0341,6.51855,5.69505] mean = 6.5 = 6.487 variance = 10.0833 = 10.0626 PDF: 1.000000 = 0.090909090909091 (1 / 11) 2.000000 = 0.090909090909091 (1 / 11) 3.000000 = 0.090909090909091 (1 / 11) 4.000000 = 0.090909090909091 (1 / 11) 5.000000 = 0.090909090909091 (1 / 11) 6.000000 = 0.090909090909091 (1 / 11) 7.000000 = 0.090909090909091 (1 / 11) 8.000000 = 0.090909090909091 (1 / 11) 9.000000 = 0.090909090909091 (1 / 11) 10.000000 = 0.090909090909091 (1 / 11) 11.000000 = 0.090909090909091 (1 / 11) 12.000000 = 0.090909090909091 (1 / 11) CDF: 1.000000 = 0.0 (0 / 1) 2.000000 = 0.090909090909091 (1 / 11) 3.000000 = 0.181818181818182 (2 / 11) 4.000000 = 0.272727272727273 (3 / 11) 5.000000 = 0.363636363636364 (4 / 11) 6.000000 = 0.454545454545455 (5 / 11) 7.000000 = 0.545454545454545 (6 / 11) 8.000000 = 0.636363636363636 (7 / 11) 9.000000 = 0.727272727272727 (8 / 11) 10.000000 = 0.818181818181818 (9 / 11) 11.000000 = 0.909090909090909 (10 / 11) 12.000000 = 1.0 (1 / 1) Quantile: 0.0100000 = 1.11 0.0250000 = 1.275 0.0500000 = 1.55 0.2500000 = 3.75 0.5000000 = 6.5 0.7500000 = 9.25 0.8400000 = 10.24 0.9750000 = 11.725 0.9900000 = 11.89 0.9990000 = 11.989 0.9999000 = 11.9989 0.9999990 = 12.0 Survival function: 0.81818181818181812 Hazard function: 0.11111111111111112 */ test_uniform => _ = random2(), println("Uniform:"), Low = 1, Up = 12, Qs = [0.01,0.025,0.05,0.25,0.50,0.75,0.84,0.975,0.99,0.999,0.9999,0.999999], println("Random:"), println([uniform_dist(Low,Up) : _ in 1..20]), Samples = [uniform_dist(Low,Up) : _ in 1..10000], println(mean=uniform_dist_mean(Low,Up)=avg(Samples)), println(variance=uniform_dist_variance(Low,Up)=variance(Samples)), println("\nPDF:"), foreach(I in Low..Up) printf("%f = %w\n",I,uniform_dist_pdf(Low,Up,I).and_rat), end, println("\nCDF:"), foreach(I in Low..Up) printf("%f = %w\n",I,uniform_dist_cdf(Low,Up,I).and_rat) end, println("\nQuantile:"), foreach(Q in Qs) printf("%.7f = %w\n",Q,uniform_dist_quantile(Low,Up,Q)) end, println("\nSurvival function:"), printf("%.17f\n",survival_function(uniform,[Low,Up,3])), println("\nHazard function:"), printf("%.17f\n",hazard_function_cont(uniform,[Low,Up,3])), nl. test_uniform => true. /* Beta dist = beta_dist(10,10) Random sample sample = [0.653805,0.470817,0.467369,0.616192,0.313695,0.611969,0.437096,0.449878,0.443814,0.281699,0.641026,0.489219,0.46884,0.587277,0.434575,0.704122,0.571988,0.453373,0.583883,0.483192] Mean: sample_mean = 0.499895 mean = 0.5 Variance: sample_variance = 0.0118215 variance = 0.0119048 PDF: 0.253953079514517 0.290566261781358 0.286759335579248 0.578564134084424 0.319565591643979 1.003887539153896 0.35237184770871 1.550639568410224 0.385178103773441 2.164047589405623 0.417984359838173 2.756898252997948 0.450790615902904 3.228374434139253 0.483596871967635 3.489953829873498 0.516403128032366 3.489953829873498 0.549209384097097 3.228374434139253 0.582015640161827 2.756898252997948 0.614821896226558 2.164047589405623 0.647628152291289 1.550639568410227 0.68043440835602 1.003887539153901 0.713240664420751 0.578564134084426 0.746046920485482 0.29056626178136 CDF: 0.253953079514517 0.01 0.286759335579248 0.023890622962927 0.319565591643979 0.04947499958906 0.35237184770871 0.091100838707609 0.385178103773441 0.151957667155052 0.417984359838173 0.232869921307659 0.450790615902904 0.331512865595605 0.483596871967635 0.442382496360779 0.516403128032366 0.557617503639222 0.549209384097097 0.668487134404395 0.582015640161827 0.767130078692341 0.614821896226558 0.848042332844948 0.647628152291289 0.908899161292391 0.68043440835602 0.950525000410939 0.713240664420751 0.976109377037073 0.746046920485482 0.99 Quantile: 0.000001 0.086143190208869 0.00001 0.110865697091332 0.001 0.189037115904798 0.01 0.253953079514517 0.025 0.288643247916999 0.05 0.320086529588725 0.25 0.424086532279681 0.5 0.499999999999999 0.75 0.575913467720319 0.84 0.611163871909495 0.975 0.711356752083001 0.99 0.746046920485482 0.999 0.810962884095202 0.99999 0.889134302908761 0.999999 0.913856809790404 */ test_beta => test_distribution($beta(10,10)), nl. test_beta => true. /* Beta-binomial dist = beta_binomial_dist(10,2,2) Random sample sample = [2,7,7,8,7,5,5,2,5,3,3,10,6,6,7,4,7,8,8,3] Mean: sample_mean = 4.9876 5.0 Variance: sample_variance = 6.88245 variance = 7.0 PDF: 1 0.06993006993007 2 0.094405594405594 3 0.111888111888112 4 0.122377622377623 5 0.125874125874126 6 0.122377622377623 7 0.111888111888112 8 0.094405594405595 9 0.06993006993007 CDF: 1 0.108391608391608 2 0.202797202797203 3 0.314685314685314 4 0.437062937062937 5 0.562937062937062 6 0.685314685314685 7 0.797202797202796 8 0.891608391608391 9 0.96153846153846 Quantile: 0.000001 0 0.00001 0 0.001 0 0.01 0 0.025 0 0.05 1 0.25 3 0.5 5 0.75 7 0.84 8 0.975 10 0.99 10 0.999 10 0.99999 10 0.999999 10 */ test_beta_binomial => test_distribution($beta_binomial_dist(10,2,2)), nl. test_beta_binomial => true. /* Hypergeometric dist = hypergeometric_dist(10,40,100) Random sample sample = [3,3,4,2,4,3,4,4,1,3,2,4,5,3,3,6,2,5,6,4] Mean: sample_mean = 4.0098 4.0 Variance: sample_variance = 2.1859 variance = 2.18182 PDF: 1 0.034160319772911 2 0.115291079233572 3 0.220430742685574 4 0.264312788683168 5 0.207605681292958 6 0.108127959006752 7 0.036855645175235 CDF: 1 0.038515760543957 2 0.153806839777533 3 0.374237582463111 4 0.638550371146282 5 0.846156052439245 6 0.954284011445996 7 0.99113965662123 Quantile: 0.000001 0 0.00001 0 0.001 0 0.01 1 0.025 1 0.05 2 0.25 3 0.5 4 0.75 5 0.84 5 0.975 7 0.99 7 0.999 8 0.99999 10 0.999999 10 */ test_hypergeometric => test_distribution($hypergeometric_dist(10,40,100)), nl. test_hypergeometric => true. /* Bernoulli dist = bernoulli_dist(1 / 3) Random sample sample = [0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,0,1,1,0,0] Mean: sample_mean = 0.3312 mean = 1 / 3 Variance: sample_variance = 0.221507 variance = 0.222222 PDF: 0 0.666666666666667 1 1 / 3 CDF: 0 0.666666666666667 1 1.0 Quantile: 0.000001 0 0.00001 0 0.001 0 0.01 0 0.025 0 0.05 0 0.25 0 0.5 0 0.75 1 0.84 1 0.975 1 0.99 1 0.999 1 0.99999 1 0.999999 1 */ test_bernoulli => test_distribution($bernoulli(1/3)), nl. test_bernoulli => true. /* Geometric: Random: [1,0,2,2,1,0,3,1,4,5,0,3,4,2,1,6,0,5,6,0] mean = 2.0 = 2.0272 variance = 6.0 = 6.40146 PDF: 0 = 0.333333333333333 (1 / 3) 1 = 0.222222222222222 (2 / 9) 2 = 0.148148148148148 (300239975158035 / 2026619832316736) 3 = 0.098765432098765 (70368744177665 / 712483534798858) 4 = 0.065843621399177 (8791800151051 / 133525464794087) 5 = 0.043895747599451 (2913890332713 / 66382064142118) 6 = 0.029263831732968 (733306134883 / 25058445577955) 7 = 0.019509221155312 (219993631585 / 11276392318978) 8 = 0.013006147436874 (54914036171 / 4222160054507) 9 = 0.008670764957916 (512 / 59049) 10 = 0.005780509971944 (1024 / 177147) 11 = 0.003853673314629 (2048 / 531441) 12 = 0.002569115543086 (4096 / 1594323) 13 = 0.001712743695391 (8192 / 4782969) 14 = 0.001141829130261 (16384 / 14348907) 15 = 0.000761219420174 (32768 / 43046721) 16 = 0.000507479613449 (65536 / 129140163) 17 = 0.000338319742299 (131072 / 387420489) 18 = 0.000225546494866 (126893 / 562602403) 19 = 0.000150364329911 (129679 / 862431935) 20 = 0.000100242886607 (41369 / 412687637) CDF: 0 = 0.333333333333333 (1125899906842624 / 3377699720527873) 1 = 0.555555555555555 (703687441776641 / 1266637395197954) 2 = 0.703703703703704 (220537095154747 / 313394819430430) 3 = 0.802469135802469 (71468255805444 / 89060441849861) 4 = 0.868312757201646 (228867900138525 / 263577723856216) 5 = 0.912208504801097 (9140248282661 / 10019911275278) 6 = 0.941472336534065 (2059 / 2187) 7 = 0.960981557689377 (2084488606184 / 2169124463945) 8 = 0.973987705126251 (19171 / 19683) 9 = 0.982658470084167 (58025 / 59049) 10 = 0.988438980056112 (86405035409 / 87415649476) 11 = 0.992292653370741 (527345 / 531441) 12 = 0.994861768913827 (1586131 / 1594323) 13 = 0.996574512609218 (4766585 / 4782969) 14 = 0.997716341739479 (14316139 / 14348907) 15 = 0.998477561159653 (42981185 / 43046721) 16 = 0.998985040773102 (129009091 / 129140163) 17 = 0.999323360515401 (13831234700812334 / 13840599797125601) 18 = 0.999548907010267 (87508666695430382 / 87548159056244651) 19 = 0.999699271340178 (80530198785187021 / 80554423809101846) 20 = 0.999799514226785 (19084398474832364 / 19088225392459463) Quantile: 0.0100000 = 0 0.0250000 = 0 0.0500000 = 0 0.2500000 = 0 0.5000000 = 1 0.7500000 = 3 0.8400000 = 4 0.9750000 = 9 0.9900000 = 11 0.9990000 = 17 0.9999000 = 22 0.9999990 = 34 Survival function: 0.00020048577321452 Hazard function: 0.74999999999984401 */ test_geometric => _ = random2(), println("Geometric:"), P = 1/3, Qs = [0.01,0.025,0.05,0.25,0.50,0.75,0.84,0.975,0.99,0.999,0.9999,0.999999], println("Random:"), println([geometric_dist(P) : _ in 1..20]), Samples = [geometric_dist(P) : _ in 1..10000], println(mean=geometric_dist_mean(P)=avg(Samples)), println(variance=geometric_dist_variance(P)=variance(Samples)), println("\nPDF:"), foreach(I in 0..20) printf("%d = %w\n",I,geometric_dist_pdf(P,I).and_rat ), end, println("\nCDF:"), foreach(I in 0..20) printf("%d = %w\n",I,geometric_dist_cdf(P,I).and_rat()) end, println("\nQuantile:"), foreach(Q in Qs) printf("%.7f = %w\n",Q,geometric_dist_quantile(P,Q)) end, println("\nSurvival function:"), printf("%.17f\n",survival_function(geometric,[P,20])), println("\nHazard function:"), printf("%.17f\n",hazard_function_discrete(geometric,[P,20])), nl. /* Multinomial Random: [[0,5,5],[2,3,5],[2,1,7],[1,0,9],[2,3,5],[1,1,8],[0,3,7],[0,1,9],[2,3,5],[2,2,6],[2,1,7],[1,3,6],[0,2,8],[1,1,8],[0,5,5],[0,3,7],[2,2,6],[0,3,7],[0,2,8],[0,3,7]] samples_mean = ([1,2,7] = 1163) mean = [1.0,2.0,7.0] PDF multinomial_dist_pdf(5,[1,2,2],A) (CDF is the same): [1,1,3]: 0.1024000000000003 [1,2,2]: 0.1536000000000002 [1,3,1]: 0.1024000000000003 [2,1,2]: 0.0768000000000001 [2,2,1]: 0.0768000000000001 [3,1,1]: 0.0256000000000001 Variances - Covariance: variances = [0.9,1.6,2.1] covariance = {{0.9,-0.2,-0.7},{-0.2,1.6,-1.4},{-0.7,-1.4,2.1}} */ test_multinomial => _ = random2(), println("Multinomial:"), N = 10, Ps = [1,2,7], println("Random:"), println([multinomial_dist(N,Ps) : _ in 1..20]), Samples = [multinomial_dist(N,Ps) : _ in 1..10000], println(samples_mean=Samples.get_freq().to_list.sort_down(2).first), println(mean=multinomial_dist_mean(N,Ps)), println("\nPDF multinomial_dist_pdf(5,[1,2,2],A) (CDF is the same):"), X = new_list(3), X :: 1..5, sum(X) #= 5, foreach(A in solve_all(X)) printf("%w: %.16f\n", A, multinomial_dist_pdf(5,[1,2,2],A)) end, println("\nVariances - Covariance:"), (Var,Cov) = multinomial_dist_varcov(N, Ps), println(variances=Var), println(covariance=Cov), nl. test_multinomial => true. /* Gamma: dist = gamma_dist(1,2) Random sample sample = [0.583265,1.45027,0.379525,0.847819,0.678783,0.73669,0.798996,1.06253,1.93474,7.94571,1.13413,1.71674,0.514637,3.00882,0.492091,0.467369,0.988038,2.66035,0.192563,2.29631] Mean: sample_mean = 2.02565 2 Variance: sample_variance = 4.18639 variance = 4 PDF: 0.020100671707003 0.495 1.020100671707003 0.300232676557754 2.020100671707003 0.182100323379864 3.020100671707003 0.110449429273473 4.020100671707003 0.066990965202123 5.020100671707003 0.04063207431883 6.020100671707003 0.024644598842093 7.020100671707003 0.014947704794048 8.020100671707002 0.009066241249923 9.020100671707002 0.00549895328643 CDF: 0.020100671707003 0.01 1.020100671707003 0.399534646884493 2.020100671707003 0.635799353240273 3.020100671707003 0.779101141453055 4.020100671707003 0.866018069595753 5.020100671707003 0.91873585136234 6.020100671707003 0.950710802315815 7.020100671707003 0.970104590411905 8.020100671707002 0.981867517500153 9.020100671707002 0.98900209342714 Quantile: 0.01 0.020100671707003 0.025 0.05063561596858 0.05 0.102586588775101 0.25 0.575364144903562 0.5 1.386294361119891 0.75 2.772588722239781 0.84 3.66516292749662 0.975 7.377758908227871 0.99 9.210340371976182 0.999 13.815510557964272 0.9999 18.420680743952587 0.999999 27.631021115871036 */ test_gamma => test_distribution($gamma_dist(1,2)), nl. /* Exponential dist = exponential_dist(1 / 10) Random sample sample = [37.4256,2.55343,5.11018,1.30208,2.95454,6.32414,22.1991,3.12518,0.169885,5.7454,1.89816,9.79639,10.8835,1.00377,5.24491,6.14,6.68421,21.5676,7.56496,4.46117] Mean: sample_mean = 10.2716 10.0 Variance: sample_variance = 100.383 variance = 100.0 PDF: 1.053605156578263 0.09 2.053605156578262 0.081435367623236 3.053605156578262 0.073685767777018 4.053605156578262 0.066673639861355 5.053605156578262 0.060328804143208 6.053605156578262 0.054587759374137 7.053605156578262 0.049393047248462 8.053605156578262 0.044692677341227 9.053605156578262 0.04043960677055 10.053605156578262 0.036591269376654 11.053605156578262 0.03310914970543 12.053605156578262 0.029958397532827 13.053605156578262 0.027107479072098 14.053605156578262 0.024527861373061 15.053605156578262 0.022193726754745 16.053605156578264 0.020081714413359 17.053605156578264 0.018170686619519 18.053605156578264 0.016441517164746 19.053605156578264 0.014876899939943 20.053605156578264 0.013461175730037 21.053605156578264 0.012180175491295 22.053605156578264 0.011021078542768 CDF: 1.053605156578263 0.1 2.053605156578262 0.185646323767636 3.053605156578262 0.263142322229816 4.053605156578262 0.333263601386454 5.053605156578262 0.396711958567925 6.053605156578262 0.45412240625863 7.053605156578262 0.506069527515376 8.053605156578262 0.553073226587731 9.053605156578262 0.595603932294501 10.053605156578262 0.634087306233461 11.053605156578262 0.668908502945702 12.053605156578262 0.700416024671728 13.053605156578262 0.728925209279018 14.053605156578262 0.754721386269389 15.053605156578262 0.778062732452554 16.053605156578264 0.799182855866413 17.053605156578264 0.81829313380481 18.053605156578264 0.835584828352539 19.053605156578264 0.851231000600572 20.053605156578264 0.865388242699628 21.053605156578264 0.878198245087049 22.053605156578264 0.889789214572316 Quantile: 0.01 0.100503358535015 0.025 0.253178079842899 0.05 0.512932943875506 0.25 2.876820724517809 0.5 6.931471805599452 0.75 13.862943611198904 0.84 18.325814637483099 0.975 36.888794541139355 0.99 46.051701859880907 0.999 69.077552789821354 0.9999 92.103403719762937 0.999999 138.155105579355165 */ test_exponential => test_distribution($exponential_dist(1/10),new_map([cs=[0.1,0.9]])), nl. /* Normal dist = normal_dist(100,15) Random sample sample = [122.687,90.6957,109.566,86.8601,109.646,101.828,107.485,92.5174,85.6586,109.504,94.3949,84.79,107.907,123.932,92.913,116.12,78.0921,89.5657,92.6163,103.548] Mean: sample_mean = 100.113 100 Variance: sample_variance = 220.317 variance = 225 PDF: 87.375681496406287 0.018664128027187 88.375681496406287 0.019697451350251 89.375681496406287 0.020695797697146 90.375681496406287 0.021648315404154 91.375681496406287 0.022544252776372 92.375681496406287 0.02337315753206 93.375681496406287 0.024125078176682 94.375681496406287 0.024790761932513 95.375681496406287 0.025361843748889 96.375681496406287 0.025831021010618 97.375681496406287 0.026192208850754 98.375681496406287 0.026440671452924 99.375681496406287 0.026573125383376 100.375681496406287 0.026587811801137 101.375681496406287 0.026484535326275 102.375681496406287 0.026264668365544 103.375681496406287 0.025931120761514 104.375681496406287 0.025488275703511 105.375681496406287 0.024941893873607 106.375681496406287 0.024298988757875 107.375681496406287 0.023567676895059 108.375681496406287 0.022757007530289 109.375681496406287 0.021876776665931 110.375681496406287 0.020937330838507 111.375681496406287 0.019949366091952 112.375681496406287 0.018923727563956 CDF: 87.375681496406287 0.2 88.375681496406287 0.219183253299368 89.375681496406287 0.23938324475127 90.375681496406287 0.260559571378979 91.375681496406287 0.28266101212378 92.375681496406287 0.305625727157376 93.375681496406287 0.329381658042208 94.375681496406287 0.353847127998533 95.375681496406287 0.378931636096824 96.375681496406287 0.404536833748999 97.375681496406287 0.430557666617583 98.375681496406287 0.456883660192244 99.375681496406287 0.483400322981961 100.375681496406287 0.509990637703734 101.375681496406287 0.536536608154088 102.375681496406287 0.562920827733536 103.375681496406287 0.589028034924677 104.375681496406287 0.614746621428119 105.375681496406287 0.639970060121061 106.375681496406287 0.664598222463234 107.375681496406287 0.688538558337006 108.375681496406287 0.71170711544178 109.375681496406287 0.734029380107666 110.375681496406287 0.755440926570064 111.375681496406287 0.775887867162782 112.375681496406287 0.795327101346782 Quantile: 0.01 65.104781889387283 0.025 70.600540231899274 0.05 75.327195595727929 0.25 89.882653747058782 0.5 100.0 0.75 110.117346252941218 0.84 114.916868248146287 0.975 129.399459768100712 0.99 134.895218110612745 0.999 146.353484592516338 0.9999 155.785247281830948 0.999999 171.301364631740569 */ test_normal => test_distribution($normal_dist(100,15),[0.2,0.8]), nl. /* Pascal dist = pascal_dist(10,1 / 2) Random sample sample = [23,28,17,17,18,15,18,26,20,21,24,18,18,18,24,19,26,19,19,20] Mean: sample_mean = 19.972 20.0 Variance: sample_variance = 20.1834 variance = 20.0 PDF: 15 0.06109619140625 16 0.076370239257812 17 0.0872802734375 18 0.092735290527344 19 0.092735290527344 20 0.088098526000977 21 0.080089569091797 22 0.070078372955322 23 0.05929708480835 24 0.048708319664001 25 0.038966655731201 26 0.030442699790001 CDF: 15 0.150878906249999 16 0.227249145507812 17 0.314529418945313 18 0.407264709472653 19 0.500000000000005 20 0.588098526000979 21 0.668188095092777 22 0.738266468048097 23 0.797563552856448 24 0.84627187252045 25 0.885238528251649 26 0.91568122804165 Quantile: 0.01 12 0.025 13 0.05 14 0.25 17 0.5 19 0.75 23 0.84 24 0.975 30 0.99 33 0.999 38 0.9999 43 0.999999 53 */ test_pascal => test_distribution($pascal_dist(10,1/2),[0.1,0.9]), nl. /* Negative Binomial dist = negative_binomial_dist(10,1 / 2) Random sample sample = [5,4,3,4,8,5,8,15,3,11,4,10,11,19,13,13,12,6,16,17] Mean: sample_mean = 10.0907 10.0 Variance: sample_variance = 20.1713 Variance: Not supported PDF: 5 0.06109619140625 6 0.076370239257812 7 0.0872802734375 8 0.092735290527344 9 0.092735290527344 10 0.088098526000977 11 0.080089569091797 12 0.070078372955322 13 0.05929708480835 14 0.048708319664001 15 0.038966655731201 16 0.030442699790001 CDF: 5 0.15087890625 6 0.227249145507812 7 0.314529418945312 8 0.407264709472656 9 0.5 10 0.588098526000977 11 0.668188095092773 12 0.738266468048096 13 0.797563552856445 14 0.846271872520447 15 0.885238528251648 16 0.915681228041649 Quantile: 0.01 2 0.025 3 0.05 4 0.25 7 0.5 10 0.75 13 0.84 14 0.975 20 0.99 23 0.999 28 0.9999 33 0.999999 43 */ test_negative_binomial => test_distribution($negative_binomial_dist(10,1/2),[0.1,0.9]), nl. test_negative_binomial => true. /* Binomial dist = binomial_dist(10,1 / 2) Random sample sample = [5,6,6,5,6,7,4,4,4,6,5,3,6,5,2,6,5,4,5,4] Mean: sample_mean = 5.0051 5.0 Variance: sample_variance = 2.51227 variance = 2.5 PDF: 1 0.009765625 2 0.0439453125 3 0.1171875 4 0.205078125 5 0.24609375 6 0.205078125 7 0.1171875 8 0.0439453125 9 0.009765625 CDF: 1 0.0107421875 2 0.0546875 3 0.171875 4 0.376953125 5 0.623046875 6 0.828125 7 0.9453125 8 0.9892578125 9 0.9990234375 Quantile: 0.01 1 0.025 2 0.05 2 0.25 4 0.5 5 0.75 6 0.84 7 0.975 8 0.99 9 0.999 9 0.9999 10 0.999999 10 */ test_binomial => test_distribution($binomial_dist(10,1/2)), nl. test_binomial => true. /* Geometric dist = geometric_dist(1 / 3) Random sample sample = [1,0,7,1,1,5,0,1,2,2,1,0,0,1,4,0,5,4,3,1] Mean: sample_mean = 1.9709 2.0 Variance: sample_variance = 5.80305 variance = 6.0 PDF: 0 0.333333333333333 1 0.222222222222222 2 0.148148148148148 3 0.098765432098765 4 0.065843621399177 5 0.043895747599451 6 0.029263831732968 7 0.019509221155312 8 0.013006147436874 9 0.008670764957916 10 0.005780509971944 11 0.003853673314629 CDF: 0 0.333333333333333 1 0.555555555555555 2 0.703703703703704 3 0.802469135802469 4 0.868312757201646 5 0.912208504801097 6 0.941472336534065 7 0.960981557689377 8 0.973987705126251 9 0.982658470084167 10 0.988438980056112 11 0.992292653370741 Quantile: 0.01 0 0.025 0 0.05 0 0.25 0 0.5 1 0.75 3 0.84 4 0.975 9 0.99 11 0.999 17 0.9999 22 0.999999 34 */ test_geometric2 => test_distribution($geommetric(1/3)), nl. /* Extreme value dist = extreme_value_dist(10,1) Random sample sample = [10.691,8.71526,10.2563,11.5698,9.32986,10.1622,15.4092,10.4836,9.60255,11.0913,10.3088,11.866,12.4374,10.5353,11.5932,8.6639,9.42098,10.8056,9.60122,12.476] Mean: sample_mean = 10.5743 mean = 10.5772 Variance: sample_variance = 1.60546 variance = 1.64493 PDF: 9.165967554752044 0.230258509299404 9.37159420625607 0.287591596866789 9.577220857760096 0.331735257941626 9.782847509264123 0.358659764234393 9.988474160768149 0.36785491237167 10.194100812272175 0.36143405087711 10.399727463776202 0.342929558674686 10.605354115280228 0.316245900188426 10.810980766784255 0.284961058503929 11.016607418288281 0.251974400042716 11.222234069792307 0.219411699381157 11.427860721296334 0.188683902047295 11.63348737280036 0.160616642229154 11.839114024304386 0.135596431371511 12.044740675808413 0.113704258903819 12.250367327312439 0.094824464092044 CDF: 9.165967554752044 0.1 9.37159420625607 0.153413304133037 9.577220857760096 0.217360679819435 9.782847509264123 0.288651972908124 9.988474160768149 0.363639416024803 10.194100812272175 0.438859977945239 10.399727463776202 0.511451377159125 10.605354115280228 0.579331116952862 10.810980766784255 0.641194793575578 11.016607418288281 0.696407455428988 11.222234069792307 0.744850808029865 11.427860721296334 0.786768350624319 11.63348737280036 0.82263104426367 11.839114024304386 0.853032017660277 12.044740675808413 0.878610369034095 12.250367327312439 0.899999999999999 Quantile: 0.000001 7.374208085523989 0.00001 7.556529642317944 0.001 8.067355266083934 0.01 8.472820374192098 0.025 8.694677259036764 0.05 8.902811299635051 0.25 9.673365740021719 0.5 10.366512920581664 0.75 11.245899323707238 0.84 11.74667107877773 0.975 13.676247257954175 0.99 14.60014922677658 0.999 16.907255070523718 0.99999 21.512920464953947 0.999999 23.81551005793531 */ test_extreme_value => test_distribution($extreme_value(10,1),[0.1,0.9]), nl. /* Chi dist = chi_dist(10) Random sample sample = [2.63671,4.17133,4.00073,3.98488,3.72203,3.9946,2.3449,3.30857,3.44993,1.82022,2.51197,3.23848,3.05426,2.80572,3.99444,2.95083,2.34237,2.56342,3.33273,3.24355] Mean: sample_mean = 3.08427 mean = 3.08433 Variance: sample_variance = 0.483306 variance = 0.486922 PDF: 1.599441202478917 0.0496448929634 1.813984993611608 0.106866101175441 2.028528784744299 0.193532480189593 2.243072575876989 0.302489008324452 2.45761636700968 0.415673849035756 2.672160158142371 0.50921865949378 2.886703949275062 0.562066980119302 3.101247740407753 0.563678864106734 3.315791531540444 0.517051920885496 3.530335322673134 0.43616242543191 3.744879113805825 0.33986788606506 3.959422904938516 0.245545534951378 4.173966696071207 0.164995005533217 4.388510487203898 0.103390122763529 4.603054278336589 0.060554203657763 CDF: 1.599441202478917 0.01 1.813984993611608 0.026263421644374 2.028528784744299 0.057986594287008 2.243072575876989 0.110927671914178 2.45761636700968 0.188098209958666 2.672160158142371 0.28787661182283 2.886703949275062 0.403660677385282 3.101247740407753 0.525354422731876 3.315791531540444 0.642051267544283 3.530335322673134 0.744753039443702 3.744879113805825 0.8281057203207 3.959422904938516 0.890741401338866 4.173966696071207 0.934467626467435 4.388510487203898 0.962906619018319 4.603054278336589 0.980180606542135 Quantile: 0.000001 0.581486030446096 0.00001 0.738355971655244 0.001 1.216035963216411 0.01 1.599441202478917 0.025 1.801935842430812 0.05 1.985018673997578 0.25 2.595611829984337 0.5 3.056438739054308 0.75 3.542437211424275 0.84 3.780736862986404 0.975 4.525834436963671 0.99 4.817598069469278 0.999 57.913797379113312 0.99999 887.095732525521271 0.999999 5264.768024270112619 */ test_chi => test_distribution($chi_dist(10)), nl. /* Chi square dist = chi_square_dist(10) Random sample sample = [10.6033,3.45227,9.38703,13.3655,9.16313,11.3755,9.93059,5.30522,13.2663,9.18931,16.5811,10.262,13.2578,4.94008,6.88296,8.01236,8.13931,12.7686,8.55489,7.66069] Mean: sample_mean = 10.0646 mean = 10 Variance: sample_variance = 20.2245 variance = 20.0 PDF: 2.558212160187205 0.015519449194649 3.558212160187205 0.035229800580516 4.558212160187205 0.057545812619956 5.558212160187205 0.077166503953344 6.558212160187205 0.090715803641945 7.558212160187205 0.097066680255196 8.558212160187205 0.096778484298525 9.558212160187205 0.091328441302781 10.558212160187205 0.082473358133312 11.558212160187205 0.071840202387076 12.558212160187205 0.060725195458838 13.558212160187205 0.050040324712895 14.558212160187205 0.040345523301161 15.558212160187205 0.031919398084832 16.558212160187203 0.024838334181768 17.558212160187203 0.019047703536305 18.558212160187203 0.014418455909083 19.558212160187203 0.010788065707388 20.558212160187203 0.007987688223691 21.558212160187203 0.005858459824457 22.558212160187203 0.004259944648234 CDF: 2.558212160187205 0.01 3.558212160187205 0.03491525406477 4.558212160187205 0.081327070698846 5.558212160187205 0.149084598708562 6.558212160187205 0.23361018973815 7.558212160187205 0.328097797201676 8.558212160187205 0.425520547330601 9.558212160187205 0.519931368863318 10.558212160187205 0.607044141890002 11.558212160187205 0.68428926351132 12.558212160187205 0.750568308794692 13.558212160187205 0.805886992257015 14.558212160187205 0.850982115409584 15.558212160187205 0.887003165476066 16.558212160187203 0.91527070060173 17.558212160187203 0.937110783931255 18.558212160187203 0.953753588862353 19.558212160187203 0.966280704081648 20.558212160187203 0.975606269988846 21.558212160187203 0.982479585295909 22.558212160187203 0.987499849753296 Quantile: 0.000001 0.338126003603958 0.00001 0.54516954087896 0.001 1.478743463835664 0.01 2.558212160187205 0.025 3.246972780236839 0.05 3.940299136119104 0.25 6.737200771954639 0.5 9.341817765591886 0.75 12.548861396883396 0.84 14.293971227144272 0.975 20.483177350806269 0.99 23.20925115895411 0.999 3354.007926868991945 0.99999 786938.838664991082624 0.999999 27717782.349377028644085 */ test_chi_square => test_distribution($chi_square_dist(10)), nl. /* Erlang dist = erlang_dist(10,3) Random sample sample = [2.55194,3.50553,3.67586,3.51554,1.13387,3.3881,2.63545,3.9287,2.28629,1.92204,3.47589,4.42527,3.77542,2.89498,3.56292,2.19807,2.25624,2.91102,3.53249,1.93002] Mean: sample_mean = 3.31662 mean = 3.33333 Variance: sample_variance = 1.10814 variance = 1.11111 PDF: 1.376733055424405 0.046491597256372 1.70235346046972 0.118284819879477 2.027973865515035 0.21517763114846 2.353594270560349 0.309438883054289 2.679214675605664 0.373949267409901 3.004835080650979 0.395262304737835 3.330455485696294 0.375653029196132 3.656075890741609 0.327450439711434 3.981696295786924 0.265690792769957 4.307316700832239 0.202945363660373 4.632937105877553 0.147224502228811 4.958557510922867 0.102146904677787 5.284177915968182 0.068167672949302 5.609798321013496 0.043960374269348 5.935418726058811 0.027501284301896 6.261039131104125 0.016744147475251 CDF: 1.376733055424405 0.01 1.70235346046972 0.035878967788683 2.027973865515035 0.089822233708226 2.353594270560349 0.17572085240718 2.679214675605664 0.288057347151087 3.004835080650979 0.41450289566461 3.330455485696294 0.540989677467913 3.656075890741609 0.65603131418261 3.981696295786924 0.752777636444923 4.307316700832239 0.828970498885921 4.632937105877553 0.885722705612007 4.958557510922867 0.926015803815285 5.284177915968182 0.95345585123654 5.609798321013496 0.9714723568013 5.935418726058811 0.982925562427188 6.261039131104125 0.989999999999999 Quantile: 0.000001 0.425606262614822 0.00001 0.554779221037459 0.001 0.986840124247978 0.01 1.376733055424405 0.025 1.598462898710805 0.05 1.808468565697101 0.25 2.575295589841293 0.5 3.222904871571381 0.75 3.971282007171801 0.84 4.36306869655906 0.975 5.694934483806376 0.99 6.261039131104126 0.999 7.55245776968761 0.99999 9.840758397815385 0.999999 10.903446839159731 */ test_erlang => test_distribution($erlang_dist(10,3)), nl. /* Kumaraswamy dist = kumaraswamy_dist(1,2) Random sample sample = [0.0480649,0.208902,0.68234,0.472078,0.395266,0.039304,0.781635,0.343372,0.932522,0.485917,0.38158,0.407147,0.711506,0.701354,0.136627,0.305904,0.625687,0.354186,0.430234,0.781642] Mean: sample_mean = 0.337317 mean = 0.333333 Variance: sample_variance = 0.0566297 variance = 0.0555556 PDF: 0.00501256289338 1.98997487421324 0.064678392033821 1.870643215932357 0.124344221174263 1.751311557651475 0.184010050314704 1.631979899370592 0.243675879455145 1.512648241089709 0.303341708595587 1.393316582808827 0.363007537736028 1.273984924527944 0.422673366876469 1.154653266247061 0.482339196016911 1.035321607966179 0.542005025157352 0.915989949685296 0.601670854297793 0.796658291404414 0.661336683438234 0.677326633123531 0.721002512578676 0.557994974842648 0.780668341719117 0.438663316561766 0.840334170859558 0.319331658280883 0.9 0.200000000000001 CDF: 0.00501256289338 0.01 0.064678392033821 0.125173489671562 0.124344221174263 0.233226957009091 0.184010050314704 0.334160402012588 0.243675879455145 0.427973824682052 0.303341708595587 0.514667225017484 0.363007537736028 0.594240603018882 0.422673366876469 0.666693958686248 0.482339196016911 0.732027292019582 0.542005025157352 0.790240603018882 0.601670854297793 0.84133389168415 0.661336683438234 0.885307158015385 0.721002512578676 0.922160402012588 0.780668341719117 0.951893623675758 0.840334170859558 0.974506823004895 0.9 0.99 Quantile: 0.000001 0.000000500000125 0.00001 0.0000050000125 0.001 0.000500125062539 0.01 0.00501256289338 0.025 0.012579117093425 0.05 0.025320565519104 0.25 0.133974596215561 0.5 0.292893218813452 0.75 0.5 0.84 0.6 0.975 0.841886116991581 0.99 0.9 0.999 0.968377223398316 0.99999 0.996837722339839 0.999999 0.998999999999986 */ test_kumaraswamy => test_distribution($kumaraswamy_dist(1,2)), nl. /* Triangular() dist dist = triangular_dist Random sample sample = [0.420238,0.288625,0.694243,0.512575,0.558384,0.309652,0.435088,0.811776,0.236069,0.414873,0.295632,0.189129,0.487891,0.483686,0.352442,0.527693,0.619636,0.382869,0.784396,0.631994] Mean: sample_mean = 0.501906 mean = 0.5 Variance: sample_variance = 0.0416053 variance = 0.0416667 PDF: 0.070710678118655 0.282842712474619 0.127949254369501 0.511797017478003 0.185187830620347 0.740751322481387 0.242426406871193 0.969705627484771 0.299664983122039 1.198659932488155 0.356903559372885 1.42761423749154 0.414142135623731 1.656568542494924 0.471380711874577 1.885522847498308 0.528619288125423 1.885522847498308 0.585857864376269 1.656568542494924 0.643096440627115 1.427614237491539 0.700335016877961 1.198659932488155 0.757573593128807 0.969705627484771 0.814812169379653 0.740751322481387 0.872050745630499 0.511797017478003 CDF: 0.070710678118655 0.01 0.127949254369501 0.032742023387422 0.185187830620347 0.068589065219741 0.242426406871193 0.117541125496954 0.299664983122039 0.179598204219064 0.356903559372885 0.254760301386069 0.414142135623731 0.34302741699797 0.471380711874577 0.444399551054766 0.528619288125423 0.555600448945234 0.585857864376269 0.656972583002031 0.643096440627115 0.745239698613931 0.700335016877961 0.820401795780936 0.757573593128807 0.882458874503046 0.814812169379653 0.931410934780259 0.872050745630499 0.967257976612578 Quantile: 0.000001 0.000707106781187 0.00001 0.0022360679775 0.001 0.022360679774998 0.01 0.070710678118655 0.025 0.111803398874989 0.05 0.158113883008419 0.25 0.353553390593274 0.5 0.5 0.75 0.646446609406726 0.84 0.717157287525381 0.975 0.88819660112501 0.99 0.929289321881345 0.999 0.977639320225002 0.99999 0.997763932022505 0.999999 0.999292893218803 */ test_triangular0 => test_distribution($triangular_dist()), nl. /* Triangular (Min,Max) distribution dist = triangular_dist(1,10) Random sample sample = [6.94236,5.23792,5.66347,4.69645,7.65329,5.17123,5.34849,9.6581,5.16193,6.20305,6.51684,4.93514,3.86356,1.98388,2.17228,8.01016,2.91061,5.64726,4.82626,6.45912] Mean: sample_mean = 5.49444 mean = 5.5 Variance: sample_variance = 3.31492 variance = 3.375 PDF: 1.636396103067893 0.031426968052735 2.636396103067893 0.080809684102118 3.636396103067893 0.130192400151501 4.636396103067893 0.179575116200884 5.636396103067893 0.215486612194178 6.636396103067893 0.166103896144795 7.636396103067893 0.116721180095413 8.636396103067893 0.06733846404603 CDF: 1.636396103067893 0.01 2.636396103067893 0.066118326077427 3.636396103067893 0.171619368204236 4.636396103067893 0 5.636396103067893 0.529850889646393 6.636396103067893 0.72064614381588 7.636396103067893 0.862058681935984 8.636396103067893 0.954088504006706 Quantile: 0.000001 1.006363961030679 0.00001 1.020124611797498 0.001 1.201246117974981 0.01 1.636396103067893 0.025 2.006230589874905 0.05 2.423024947075771 0.25 4.181980515339464 0.5 5.5 0.75 6.818019484660536 0.84 7.454415587728429 0.975 8.993769410125093 0.99 9.363603896932107 0.999 9.798753882025018 0.99999 9.979875388202547 0.999999 9.99363603896923 */ test_triangular1 => test_distribution($triangular_dist(1,10)), nl. /* Triangular (Min,Max,C) dist dist = triangular2_dist(1,10,0) Random sample sample = [3.06347,1.10045,1.53789,4.17186,3.4854,7.43512,7.9797,5.10969,2.19809,1.53218,8.41654,3.84658,1.8064,5.90961,3.61645,3.99164,1.59725,2.72151,5.44791,4.78083] Mean: sample_mean = 3.67451 mean = 3.66667 Variance: sample_variance = 5.03746 variance = 5.05556 PDF: 0.560720366468637 0.20976176963403 1.560720366468637 0.187539547411808 2.560720366468637 0.165317325189586 3.560720366468637 0.143095102967364 4.560720366468637 0.120872880745141 5.560720366468637 0.098650658522919 6.560720366468637 0.076428436300697 7.560720366468637 0.054206214078475 8.560720366468637 0.031983991856253 CDF: 0.560720366468637 0.01 1.560720366468637 0.208650658522919 2.560720366468637 0.385079094823616 3.560720366468637 0.539285308902091 4.560720366468637 0.671269300758343 5.560720366468637 0.781031070392374 6.560720366468637 0.868570617804182 7.560720366468637 0.933887942993768 8.560720366468637 0.976983045961131 Quantile: 0.000001 0.513171762912538 0.00001 0.513214453778351 0.001 0.517911622432536 0.01 0.560720366468637 0.025 0.632503002402403 0.05 0.753378995546536 0.25 1.784161637422509 0.5 3.291796067500631 0.75 5.256583509747431 0.84 6.205266807797944 0.975 8.5 0.99 9.051316701949485 0.999 9.699999999999999 0.99999 9.970000000000068 0.999999 9.990513167019358 */ test_triangular2 => test_distribution($triangular2_dist(1,10,0)), nl. /* Student's T dist dist = student_t_dist(10) Random sample sample = [0.121943,-1.98527,-2.03563,-1.08092,-1.26023,0.758814,-0.397821,0.0229453,1.08024,-1.12461,0.649062,-1.48772,0.39254,1.45991,0.0668521,0.963586,-0.462571,0.154643,0.944239,0.189578] Mean: sample_mean = -0.0167287 mean = 0.0 Variance: sample_variance = 1.20622 variance = 1.25 PDF: -2.763769458112591 0.017160981822171 -1.763769458112591 0.087719260727185 -0.763769458112591 0.284868623827201 0.236230541887409 0.377379220457342 1.236230541887409 0.177978958227507 2.236230541887409 0.041826631699719 CDF: -2.763769458112591 0.010000000000002 -1.763769458112591 0.054120253031062 -0.763769458112591 0.231322110721615 0.236230541887409 0.590989000583839 1.236230541887409 0.877688869430365 2.236230541887409 0.975340702607178 Quantile: 0.000001 -9.751995490852909 0.00001 -7.526954019317212 0.001 -4.143700494045533 0.01 -2.763769458112591 0.025 -2.228138851985152 0.05 -1.812461122683027 0.25 -0.69981206131243 0.5 0.0 0.75 0.69981206131243 0.84 1.046422610493593 0.975 2.228138851985152 0.99 2.76376945811259 0.999 4.143700494045532 0.99999 7.526954019321185 0.999999 9.751995490822186 */ test_student_t => test_distribution($student_t_dist(10)), nl. /* Student's T / 3 distribution dist = student_t_dist(100,15,10) Random sample sample = [102.276,76.3139,74.1048,105.517,118.537,104.412,122.569,92.5455,97.6568,78.4536,100.844,78.1423,93.5858,116.854,97.0791,109.959,99.7598,113.312,106.379,89.0194] Mean: sample_mean = 100.14 mean = 100 Variance: sample_variance = 286.59 variance = 281.25 PDF: 86.814132571741226 0.017226012490273 87.814132571741226 0.018252372338205 88.814132571741226 0.019262336543186 89.814132571741226 0.020244144288934 90.814132571741226 0.02118553664603 91.814132571741226 0.022074013672516 92.814132571741226 0.022897123815256 93.814132571741226 0.023642776487958 94.814132571741226 0.024299566540489 95.814132571741226 0.024857097671184 96.814132571741226 0.025306290849344 97.814132571741226 0.025639663647641 98.814132571741226 0.02585156711208 99.814132571741226 0.02593836842526 100.814132571741226 0.025898570071691 101.814132571741226 0.025732859339588 102.814132571741226 0.025444085574586 103.814132571741226 0.025037166374668 104.814132571741226 0.024518927600583 105.814132571741226 0.023897885399263 106.814132571741226 0.023183981162429 107.814132571741226 0.022388282290343 108.814132571741226 0.021522662696934 109.814132571741226 0.020599477152408 110.814132571741226 0.01963124286536 111.814132571741226 0.018630340276403 112.814132571741226 0.017608743036517 CDF: 86.814132571741226 0.2 87.814132571741226 0.217740086107272 88.814132571741226 0.236499287477889 89.814132571741226 0.25625537929389 90.814132571741226 0.276974106980689 91.814132571741226 0.298608813635863 92.814132571741226 0.321100341369801 93.814132571741226 0.344377234492544 94.814132571741226 0.368356262243108 95.814132571741226 0.392943266591274 96.814132571741226 0.418034327138095 97.814132571741226 0.443517221052542 98.814132571741226 0.469273142169274 99.814132571741226 0.495178630741157 100.814132571741226 0.521107654758938 101.814132571741226 0.546933775974083 102.814132571741226 0.572532329358337 103.814132571741226 0.597782544031435 104.814132571741226 0.62256953673934 105.814132571741226 0.646786115542022 106.814132571741226 0.670334340987994 107.814132571741226 0.693126804019192 108.814132571741226 0.715087593328597 109.814132571741226 0.736152938983641 110.814132571741226 0.756271532944642 111.814132571741226 0.775404539849457 112.814132571741226 0.793525322447734 Quantile: 0.000001 -46.27993236279363 0.00001 -12.904310289758172 0.001 37.844492589316999 0.01 58.543458128311137 0.025 66.577917220222716 0.05 72.813083159754598 0.25 89.502819080313543 0.5 100.0 0.75 110.497180919686457 0.84 115.696339157403884 0.975 133.42208277977727 0.99 141.456541871688842 0.999 162.155507410682986 0.99999 212.904310289817772 0.999999 246.279932362332772 */ test_student_t3 => test_distribution($student_t_dist(100,15,10),[0.2,0.8]), nl. /* F dist dist = f_dist(10,10) Random sample sample = [1.43258,2.252,1.49815,2.56411,1.32603,0.516846,0.942378,0.884333,0.906202,1.51246,0.363508,2.04148,1.38628,0.506588,3.57948,1.71058,0.985123,0.775057,0.969574,1.72825] Mean: sample_mean = 1.25044 mean = 1.25 Variance: sample_variance = 0.90243 variance = 0.9375 PDF: 0.206221844958601 0.174746033819055 0.515750175433348 0.696340756887653 0.825278505908096 0.711952942972069 1.134806836382843 0.53142560333667 1.444335166857591 0.360084918015637 1.753863497332338 0.237629093906659 2.063391827807085 0.15690684123543 2.372920158281833 0.104812346247597 2.68244848875658 0.071137616210293 2.991976819231327 0.049123956689856 3.301505149706075 0.034513101912864 3.611033480180822 0.024653799163784 3.92056181065557 0.017889032530153 4.230090141130317 0.013171865801147 4.539618471605064 0.009831491771125 4.849146802079812 0.007431503100279 CDF: 0.206221844958601 0.010000000000002 0.515750175433348 0.15570898673287 0.825278505908096 0.383642782538583 1.134806836382843 0.57728888547358 1.444335166857591 0.714110034366691 1.753863497332338 0.805372093368437 2.063391827807085 0.865531615913041 2.372920158281833 0.905447561057608 2.68244848875658 0.932304648832877 2.991976819231327 0.95068040286759 3.301505149706075 0.963473553121655 3.611033480180822 0.972532889467292 3.92056181065557 0.979052895610321 4.230090141130317 0.983817220416249 4.539618471605064 0.987348294621335 4.849146802079812 0.989999999999998 Quantile: 0.000001 0.024990268693551 0.00001 0.04061507527109 0.001 0.114235238297491 0.01 0.206221844958601 0.025 0.269049232895368 0.05 0.335769112599182 0.25 0.644639036038997 0.5 1.0 0.75 1.551255732424349 0.84 1.916109183896505 0.975 3.716791864591177 0.99 4.849146802079812 0.999 8.753866275446473 0.99999 24.621399648458528 0.999999 40.015576152786863 */ test_f => test_distribution($f_dist(10,10)), nl. /* Log normal dist dist = lognormal_dist(1,1) Random sample sample = [4.94806,4.07483,12.3362,1.63828,3.14541,0.620572,1.36091,10.2667,0.612455,1.7244,0.45977,1.30864,1.17358,0.470734,2.4145,0.828529,1.72709,0.725413,6.76903,4.64801] Mean: sample_mean = 4.51079 mean = 4.48169 Variance: sample_variance = 36.3165 variance = 34.5126 PDF: 0.265444931522626 0.100405541935111 1.265444931522626 0.235357248583495 2.265444931522626 0.17319911674364 3.265444931522626 0.120133505237674 4.265444931522626 0.08450191321325 5.265444931522626 0.06089073864516 6.265444931522626 0.044930336856958 7.265444931522626 0.033866128748313 8.265444931522627 0.026007065657169 9.265444931522627 0.020300164209466 10.265444931522627 0.016073962029659 11.265444931522627 0.012889387039922 12.265444931522627 0.010452370943923 13.265444931522627 0.008561574375726 14.265444931522627 0.007076359275966 15.265444931522627 0.005896691845141 16.265444931522627 0.004950242452844 17.265444931522627 0.004183928641271 18.265444931522627 0.003558262035475 19.265444931522627 0.003043501392302 20.265444931522627 0.002616991409332 21.265444931522627 0.002261293807188 22.265444931522627 0.001962856438882 23.265444931522627 0.001711053294604 24.265444931522627 0.001497483765592 25.265444931522627 0.001315455483334 26.265444931522627 0.00115959871082 27.265444931522627 0.001025576063172 CDF: 0.265444931522626 0.01 1.265444931522626 0.222261968402213 2.265444931522626 0.427701577256064 3.265444931522626 0.572756353305147 4.265444931522626 0.673841782409264 5.265444931522626 0.745746956119833 6.265444931522626 0.798155110167975 7.265444931522626 0.837228155923658 8.265444931522627 0.866948888373565 9.265444931522627 0.88995557230094 10.265444931522627 0.908040278843385 11.265444931522627 0.922449138436958 12.265444931522627 0.934067234433851 13.265444931522627 0.943535294141509 14.265444931522627 0.951325134992036 15.265444931522627 0.957789559756109 16.265444931522627 0.963196047756625 17.265444931522627 0.967749941126256 18.265444931522627 0.971610680664144 19.265444931522627 0.974903356139653 20.265444931522627 0.977727043063248 21.265444931522627 0.980160900385759 22.265444931522627 0.982268685245486 23.265444931522627 0.984102133516362 24.265444931522627 0.985703517563568 25.265444931522627 0.987107600224545 26.265444931522627 0.988343140987122 27.265444931522627 0.98943406673422 Quantile: 0.000001 0.023437351558323 0.00001 0.038201106648988 0.001 0.123658405870131 0.01 0.265444931522626 0.025 0.382906676286843 0.05 0.52473934418307 0.25 1.384737027546682 0.5 2.718281828459045 0.75 5.336071724767648 0.84 7.348218355360598 0.975 19.297276742689519 0.99 27.836493454767073 0.999 59.753771261540152 0.99999 193.425184427099396 0.999999 315.268390310236782 */ test_lognormal => test_distribution($lognormal_dist(1,1)), nl. /* Weibull dist dist = weibull_dist(10,1) Random sample sample = [0.967968,1.13528,0.860294,0.893148,0.862359,0.862641,0.897651,0.733572,1.00897,0.906836,0.817703,0.637642,0.905946,0.971066,1.04667,0.957464,0.855853,0.907303,1.02337,0.927307] Mean: sample_mean = 0.952465 mean = 0.951351 Variance: sample_variance = 0.0130185 variance = 0.0131005 PDF: 0.631274225134862 0.157615060124478 0.666855700794987 0.256291439673442 0.702437176455111 0.4043577528207 0.738018652115236 0.619137552574715 0.77360012777536 0.918988380234463 0.809181603435485 1.318696915685403 0.844763079095609 1.820694138231049 0.880344554755733 2.401310366900324 0.915926030415858 2.994198241045085 0.951507506075982 3.479573191198956 0.987088981736107 3.696885604026066 1.022670457396231 3.501016357310159 1.058251933056356 2.85941842753709 1.09383340871648 1.930597501421771 1.129414884376605 1.021070101392351 CDF: 0.631274225134862 0.01 0.666855700794987 0.017240418279018 0.702437176455111 0.028823024587085 0.738018652115236 0.0468064296217 0.77360012777536 0.073892876187729 0.809181603435485 0.113393349164687 0.844763079095609 0.168958573196609 0.880344554755733 0.243908849488638 0.915926030415858 0.340010638417787 0.951507506075982 0.455727980106755 0.987088981736107 0.584444270588324 1.022670457396231 0.713863838620627 1.058251933056356 0.828218623839149 1.09383340871648 0.913874632997518 1.129414884376605 0.965851314008684 Quantile: 0.000001 0.251188655711118 0.00001 0.316227924131275 0.001 0.501212304063641 0.01 0.631274225134862 0.025 0.692376964155347 0.05 0.743029504640401 0.25 0.882858860205762 0.5 0.96401223546779 0.75 1.033202731534665 0.84 1.062444686691608 0.975 1.139434713525838 0.99 1.164996360036729 0.999 1.213203611167138 0.99999 1.276787344491138 0.999999 1.300279435101868 */ test_weibull => test_distribution($weibull_dist(10,1)), nl. /* Weibull / 3 dist dist = weibull_dist(10,1,1) Random sample sample = [0.853148,1.09261,1.11239,0.846716,1.0083,0.824216,0.918707,1.01659,1.02369,0.757786,1.12891,0.760507,0.906869,1.02232,0.875963,0.94562,0.877497,0.931625,1.05673,0.986196] Mean: sample_mean = 0.952716 mean = 1.95135 Variance: sample_variance = 0.0130783 variance = 0.0131005 PDF: 1.00100503358535 1.0 1.031639165919581 1.0 1.062273298253811 1.0 1.092907430588042 1.0 1.123541562922272 1.0 1.154175695256503 1.0 1.184809827590733 0.999999999999988 1.215443959924964 0.999999999999785 1.246078092259194 0.999999999997306 1.276712224593425 0.999999999974965 1.307346356927655 0.999999999815951 1.337980489261886 0.999999998880714 1.368614621596116 0.999999994180595 1.399248753930347 0.999999973476684 1.429882886264577 0.999999891942991 1.460517018598808 0.999999600360952 CDF: 1.00100503358535 0.0 1.031639165919581 0.000000000000001 1.062273298253811 0.000000000000877 1.092907430588042 0.000000000047919 1.123541562922272 0.000000000828192 1.154175695256503 0.000000007588556 1.184809827590733 0.00000004647834 1.215443959924964 0.000000215448355 1.246078092259194 0.000000814196696 1.276712224593425 0.00000263198183 1.307346356927655 0.000007521060175 1.337980489261886 0.000019449662945 1.368614621596116 0.000046314344718 1.399248753930347 0.000102899519868 1.429882886264577 0.000215503714765 1.460517018598808 0.000428907549766 Quantile: 0.000001 1.00000010000005 0.00001 1.000001000005 0.001 1.000100050033358 0.01 1.00100503358535 0.025 1.002531780798429 0.05 1.005129329438755 0.25 1.028768207245178 0.5 1.069314718055995 0.75 1.138629436111989 0.84 1.183258146374831 0.975 1.368887945411394 0.99 1.460517018598809 0.999 1.690775527898214 0.99999 2.151292546497478 0.999999 2.381551055793552 */ test_weibull3 => test_distribution($weibull_dist(10,1,1)), nl. /* Frechet dist dist = frechet_dist(10,1) Random sample sample = [1.15086,1.17405,0.900333,1.05407,0.947854,1.60309,1.40513,0.967429,1.00257,0.97742,0.90778,1.38764,0.827657,0.95281,1.20733,1.26357,0.968132,0.869893,1.14833,0.911275] Mean: sample_mean = 1.06873 mean = 1.06863 Variance: sample_variance = 0.0229796 variance = 0.0222624 PDF: 0.858371780636699 0.536500650402578 0.906753503514008 2.050188791251563 0.955135226391316 3.404108383446913 1.003516949268624 3.66366929337111 1.051898672145932 3.136472233796051 1.10028039502324 2.379303086090932 1.148662117900549 1.695418190499784 1.197043840777857 1.171916996730587 1.245425563655165 0.800075686218612 1.293807286532473 0.544992846900098 1.342189009409782 0.372528451991599 1.39057073228709 0.256337461782029 1.438952455164398 0.177859968508219 1.487334178041706 0.124539763494016 1.535715900919015 0.088029480009353 1.584097623796323 0.062810727984816 CDF: 0.858371780636699 0.01 0.906753503514008 0.06985146514413 0.955135226391316 0.205455072331084 1.003516949268624 0.380792246747827 1.051898672145932 0.547210501004033 1.10028039502324 0.680748808033536 1.148662117900549 0.778739354274731 1.197043840777857 0.847437100404666 1.245425563655165 0.894595288826075 1.293807286532473 0.92673661417636 1.342189009409782 0.948658513409191 1.39057073228709 0.963687017750076 1.438952455164398 0.974067606831136 1.487334178041706 0.98130084612173 1.535715900919015 0.986388107746806 1.584097623796323 0.99 Quantile: 0.000001 0.76906545855003 0.00001 0.783215783203575 0.001 0.824263949427227 0.01 0.858371780636699 0.025 0.877628167835632 0.05 0.896086016518311 0.25 0.967864262722817 0.5 1.037331232123571 0.75 1.132683880826588 0.84 1.190849726129156 0.975 1.444299928753309 0.99 1.584097623796323 0.999 1.995162512756324 0.99999 3.162276079024796 0.999999 3.981071506469862 */ test_frechet => test_distribution($frechet_dist(10,1)), nl. /* Frechet / 3 dist dist = frechet_dist(10,1,2) Random sample sample = [3.20174,2.88311,3.13047,3.13372,3.05207,3.15787,2.98514,3.01025,2.87804,3.30607,2.96938,3.10447,3.1743,3.28045,2.97009,2.99756,2.96434,3.15728,2.9966,2.91612] Mean: sample_mean = 3.0696 mean = 3.06863 Variance: sample_variance = 0.0215377 variance = 0.0222624 PDF: 2.858371780636699 0.536500650402575 2.906753503514008 2.050188791251559 2.955135226391316 3.404108383446911 3.003516949268624 3.66366929337111 3.051898672145932 3.136472233796051 3.10028039502324 2.379303086090932 3.148662117900549 1.695418190499784 3.197043840777857 1.171916996730587 3.245425563655165 0.800075686218612 3.293807286532473 0.544992846900098 3.342189009409782 0.372528451991599 3.39057073228709 0.256337461782029 3.438952455164398 0.177859968508219 3.487334178041706 0.124539763494016 3.535715900919015 0.088029480009353 3.584097623796323 0.062810727984816 CDF: 2.858371780636699 0.01 2.906753503514008 0.06985146514413 2.955135226391316 0.205455072331083 3.003516949268624 0.380792246747827 3.051898672145932 0.547210501004033 3.10028039502324 0.680748808033536 3.148662117900549 0.778739354274731 3.197043840777857 0.847437100404666 3.245425563655165 0.894595288826075 3.293807286532473 0.92673661417636 3.342189009409782 0.948658513409191 3.39057073228709 0.963687017750076 3.438952455164398 0.974067606831136 3.487334178041706 0.98130084612173 3.535715900919015 0.986388107746806 3.584097623796323 0.99 Quantile: 0.000001 2.76906545855003 0.00001 2.783215783203576 0.001 2.824263949427228 0.01 2.858371780636699 0.025 2.877628167835632 0.05 2.896086016518311 0.25 2.967864262722817 0.5 3.037331232123571 0.75 3.132683880826588 0.84 3.190849726129156 0.975 3.444299928753309 0.99 3.584097623796323 0.999 3.995162512756324 0.99999 5.162276079024796 0.999999 5.981071506469862 */ test_frechet3 => test_distribution($frechet_dist(10,1,1)), nl. /* Gumbel dist dist = gumbel_dist(10,3) Random sample sample = [3.47069,8.35712,9.65682,8.58453,8.96952,4.66857,12.3398,6.58935,9.21248,13.8341,5.73835,3.66888,7.60385,5.59447,2.76175,7.47299,9.55991,9.08881,6.56572,4.0618] Mean: sample_mean = 8.2298 mean = 8.26835 Variance: sample_variance = 14.5593 variance = 14.8044 PDF: -3.800447680329736 0.003350110817515 -2.800447680329736 0.004675453563781 -1.800447680329736 0.006525110773227 -0.800447680329736 0.009106486545065 0.199552319670264 0.012708977344669 1.199552319670264 0.017736243623726 2.199552319670264 0.024750786006303 3.199552319670264 0.034534402622712 4.199552319670264 0.04816591903408 5.199552319670264 0.067104542714207 6.199552319670264 0.093211724253368 7.199552319670264 0.128431987207983 8.199552319670264 0.173108539830446 9.199552319670264 0.219777970645654 10.199552319670264 0.23715368779764 11.199552319670264 0.164479092043229 12.199552319670264 0.034306530717736 13.199552319670264 0.000273025646651 14.199552319670264 0.000000000302909 CDF: -3.800447680329736 0.01 -2.800447680329736 0.013928462329912 -1.800447680329736 0.019385027595473 -0.800447680329736 0.026949839121271 0.199552319670264 0.037409928537374 1.199552319670264 0.051820456877745 2.199552319670264 0.071572046246874 3.199552319670264 0.098451700850626 4.199552319670264 0.134669349633183 5.199552319670264 0.182795894243903 6.199552319670264 0.245520555269048 7.199552319670264 0.325094125623829 8.199552319670264 0.42231685046489 9.199552319670264 0.535044719912899 10.199552319670264 0.656572620585582 11.199552319670264 0.774988123575091 12.199552319670264 0.875281791156163 13.199552319670264 0.945264576014675 14.199552319670264 0.982657495228558 Quantile: 0.000001 -31.446530173805925 0.00001 -24.538761394861837 0.001 -10.721765211571146 0.01 -3.800447680329736 0.025 -1.028741773862528 0.05 1.089414252873508 0.25 6.262302028878286 0.5 8.900461238255007 0.75 10.979902779934843 0.84 11.81717682630757 0.975 13.91596822288971 0.99 14.581538877423704 0.999 15.797934201748195 0.99999 17.330411073047355 0.999999 17.877375743421787 */ test_gumbel => test_distribution($gumbel_dist(10,3)), nl. /* Max stable dist dist = max_stable_dist(1,2,0.2) Random sample sample = [2.48764,1.46594,3.29829,8.68656,15.661,2.43486,1.2308,-1.18907,5.96666,1.97745,3.67846,0.338781,3.17385,3.26285,1.61269,-0.323546,1.71577,5.28357,2.04262,6.60844] Mean: sample_mean = 2.58441 mean = 2.6423 Variance: sample_variance = 12.4727 variance = 13.3761 PDF: -1.63197886206582 0.031251065243817 -0.63197886206582 0.12728672060218 0.36802113793418 0.184992533958032 1.36802113793418 0.174701777037877 2.36802113793418 0.136807963238276 3.36802113793418 0.098878615496248 4.36802113793418 0.069316614792835 5.36802113793418 0.048268435909581 6.36802113793418 0.033775274075563 7.36802113793418 0.023879589607257 8.36802113793418 0.017099639909512 9.36802113793418 0.012411493991017 10.36802113793418 0.009131103847319 11.36802113793418 0.006805936170092 12.36802113793418 0.005136119450415 13.36802113793418 0.003921466075619 14.36802113793418 0.00302695320012 15.36802113793418 0.002360444927554 CDF: -1.63197886206582 0.01 -0.63197886206582 0.087407702417424 0.36802113793418 0.25007562847641 1.36802113793418 0.434012823922137 2.36802113793418 0.590541751338921 3.36802113793418 0.707837692765552 4.36802113793418 0.791170494013481 5.36802113793418 0.849327079893018 6.36802113793418 0.88989050463239 7.36802113793418 0.918404319742742 8.36802113793418 0.938683090823799 9.36802113793418 0.953297117949461 10.36802113793418 0.963972800856001 11.36802113793418 0.97187607147422 12.36802113793418 0.977802039976317 13.36802113793418 0.982299323226754 14.36802113793418 0.985751219236256 15.36802113793418 0.988428920974476 Quantile: 0.000001 -3.085383204652324 0.00001 -2.865730369408099 0.001 -2.20588941674629 0.01 -1.63197886206582 0.025 -1.297687990214714 0.05 -0.970298510003449 0.25 0.367612310559831 0.5 1.760560851390051 0.75 3.829727738843799 0.84 5.181230702218858 0.975 11.860022841968133 0.99 16.093652817171559 0.999 30.806734523081307 0.99999 90.999899999724349 0.999999 149.489303396262102 */ test_max_stable => test_distribution($max_stable_dist(1,2,0.2)), nl. /* Min stable dist dist = min_stable_dist(1,2,0.2) Random sample sample = [0.852448,-0.422634,1.06373,0.374595,2.38623,0.615187,1.29806,1.06723,0.689294,-1.19774,-2.02684,0.475524,1.91177,-4.06391,1.09018,-0.99938,-1.12945,-2.05159,-1.41334,-1.43181] Mean: sample_mean = -0.673864 mean = -0.642297 Variance: sample_variance = 13.3496 variance = 13.3761 PDF: -14.093652817171561 0.001982539681939 -13.093652817171561 0.002524672998143 -12.093652817171561 0.003246402674905 -11.093652817171561 0.004218081738966 -10.093652817171561 0.00554190955875 -9.093652817171561 0.007368146943354 -8.093652817171561 0.009920244158758 -7.093652817171561 0.013533726184522 -6.093652817171561 0.018715537638827 -5.093652817171561 0.026231059639653 -4.093652817171561 0.037219045572108 -3.093652817171561 0.053299828989226 -2.093652817171561 0.07651747433243 -1.093652817171561 0.108579002668961 -0.093652817171561 0.147928481407544 0.906347182828439 0.18203826336906 1.906347182828439 0.177075594929792 2.906347182828439 0.099923264556944 CDF: -14.093652817171561 0.01 -13.093652817171561 0.012240946913213 -12.093652817171561 0.015108979112612 -11.093652817171561 0.018816722185568 -10.093652817171561 0.023662002948296 -9.093652817171561 0.030067215723528 -8.093652817171561 0.038639031633244 -7.093652817171561 0.050259631762822 -6.093652817171561 0.066226431181212 -5.093652817171561 0.088464473275552 -4.093652817171561 0.119840532685055 -3.093652817171561 0.1645947030602 -2.093652817171561 0.228820369593022 -1.093652817171561 0.320607380597561 -0.093652817171561 0.44852069955264 0.906347182828439 0.61498038539901 1.906347182828439 0.799728605488516 2.906347182828439 0.943822289400296 Quantile: 0.000001 -147.489303396262102 0.00001 -88.999899999724349 0.001 -28.806734523081307 0.01 -14.093652817171561 0.025 -9.860022841968133 0.05 -7.11289549357503 0.25 -1.829727738843799 0.5 0.239439148609949 0.75 1.632387689440169 0.84 2.14094613879671 0.975 3.297687990214714 0.99 3.63197886206582 0.999 4.205889416746289 0.99999 4.865730369408585 0.999999 5.085383204649862 */ test_min_stable => test_distribution($min_stable_dist(1,2,0.2)), nl. /* Logistic dist dist = logistic_dist(10,3) Random sample sample = [18.3335,11.1124,25.6606,7.83643,12.0185,5.14285,13.1368,0.139513,6.21704,8.24372,7.49045,-2.12077,11.6209,8.28723,7.47794,11.1787,6.06979,10.4564,8.39929,10.6558] Mean: sample_mean = 10.017 mean = 10 Variance: sample_variance = 28.5942 variance = 29.6088 PDF: -3.785359550403768 0.0033 -2.785359550403768 0.004569296083014 -1.785359550403768 0.006307401031476 -0.785359550403768 0.008669826178713 0.214640449596232 0.011847876630724 1.214640449596232 0.016062581582108 2.214640449596232 0.021543139423375 3.214640449596232 0.028479344972831 4.214640449596232 0.036937574160286 5.214640449596232 0.046738992585768 6.214640449596232 0.057324266490266 7.214640449596232 0.067671503604348 8.214640449596232 0.076369491253496 9.214640449596232 0.081921730494795 10.214640449596232 0.083226779523934 11.214640449596232 0.080009353308581 12.214640449596232 0.072936882996581 13.214640449596232 0.063342804883227 14.214640449596232 0.052738987861774 15.214640449596232 0.042392595562866 16.214640449596232 0.033124379457373 17.214640449596232 0.025315086262233 18.214640449596232 0.019021502152322 19.214640449596232 0.01411137874303 20.214640449596232 0.010370034714667 21.214640449596232 0.007567734896621 22.214640449596232 0.005494687191848 23.214640449596232 0.003974805290961 CDF: -3.785359550403768 0.01 -2.785359550403768 0.01390112965472 -1.785359550403768 0.019294480055021 -0.785359550403768 0.026723630989395 0.214640449596232 0.036905657443511 1.214640449596232 0.050764810757576 2.214640449596232 0.069453159656381 3.214640449596232 0.094337621806622 4.214640449596232 0.126921888180047 5.214640449596232 0.16866478870682 6.214640449596232 0.220666506610466 7.214640449596232 0.28323863539146 8.214640449596232 0.355460987136647 9.214640449596232 0.434924593619294 10.214640449596232 0.517879077945994 11.214640449596232 0.599859601813035 12.214640449596232 0.676605070737669 13.214640449596232 0.744890966248901 14.214640449596232 0.802957152770283 15.214640449596232 0.850460002441653 16.214640449596232 0.888106765758961 17.214640449596232 0.917198683139463 18.214640449596232 0.93924422994848 19.214640449596232 0.955703701730532 20.214640449596232 0.967856704404241 21.214640449596232 0.976756536725126 22.214640449596232 0.983234868800312 23.214640449596232 0.987929896734272 Quantile: 0.000001 -31.446528673891322 0.00001 -24.538746394760686 0.001 -10.720264335945661 0.01 -3.785359550403768 0.025 -0.990684938388938 0.05 1.166683062500679 0.25 6.704163133995671 0.5 10.0 0.75 13.295836866004329 0.84 14.974684229810597 0.975 20.990684938388938 0.99 23.785359550403768 0.999 30.720264335945657 0.99999 44.538746394774336 0.999999 51.446528673805055 */ test_logistic => test_distribution($logistic_dist(10,3)), nl. /* Discrete Laplace dist dist = discrete_laplace_dist(5,0.25) Random sample sample = [5,7,5,5,5,5,5,5,5,3,5,5,5,5,5,5,5,5,3,5] Mean: sample_mean = 5.0071 mean = 5 Variance: sample_variance = 0.55325 variance = 0.888889 PDF: 1 0.00234375 2 0.009375 3 0.0375 4 0.15 5 0.6 6 0.15 7 0.0375 8 0.009375 CDF: 1 0.003125 2 0.0125 3 0.05 4 0.2 5 0.8 6 0.95 7 0.9875 8 0.996875 Quantile: 0.000001 -5 0.00001 -4 0.001 0 0.01 1 0.025 2 0.05 3 0.25 4 0.5 4 0.75 4 0.84 6 0.975 7 0.99 8 0.999 9 0.99999 13 0.999999 14 */ test_discrete_laplace => test_distribution($discrete_laplace_dist(5,0.25)), nl. /* Logseries dist dist = logseries_dist(0.5) Random sample sample = [1,1,1,2,2,1,1,1,1,1,1,1,1,1,3,1,3,1,3,2] Mean: sample_mean = 1.4461 mean = 1.4427 Variance: sample_variance = 0.807495 variance = 0.804021 PDF: 1 0.721347520444482 2 0.18033688011112 3 0.060112293370373 4 0.02254211001389 5 0.009016844005556 CDF: 1 0.721347520444482 2 0.901684400555602 3 0.961796693925976 4 0.984338803939866 5 0.993355647945422 Quantile: 0.000001 1 0.00001 1 0.001 1 0.01 1 0.025 1 0.05 1 0.25 1 0.5 1 0.75 2 0.84 2 0.975 4 0.99 5 0.999 8 0.99999 14 0.999999 17 */ test_logseries => test_distribution($logseries_dist(0.5)), nl. /* Beta prime / 4 distribution dist = beta_prime_dist(10,4,4,3) Random sample sample = [4.19136,4.89666,3.36536,4.035,3.43707,5.41428,3.21573,4.15108,3.4586,3.58019,5.1779,3.64297,3.9336,4.38447,4.22296,3.81739,3.63452,3.78701,5.35791,3.92785] Mean: sample_mean = 3.90346 mean = 3.89567 Variance: sample_variance = 0.401656 variance = 0.392083 PDF: 2.74542308402118 0.070489854318945 2.945032669356391 0.188098289122106 3.144642254691601 0.367207890969658 3.344251840026812 0.553931512490105 3.543861425362023 0.678154885449158 3.743471010697233 0.703092112130893 3.943080596032444 0.639851759103231 4.142690181367655 0.526445988040689 4.342299766702866 0.401058154686221 4.541909352038077 0.28834696112451 4.741518937373288 0.198615795222577 4.9411285227085 0.132625042812712 5.140738108043711 0.086644937425871 5.340347693378922 0.055778175771035 5.539957278714133 0.035578105694642 CDF: 2.74542308402118 0.01 2.945032669356391 0.034597555871389 3.144642254691601 0.089313437568569 3.344251840026812 0.181741275174874 3.543861425362023 0.306208859983332 3.743471010697233 0.445750642934109 3.943080596032444 0.580969298958691 4.142690181367655 0.697857857679703 4.342299766702866 0.790373008052906 4.541909352038077 0.85884461664022 4.741518937373288 0.907036726482356 4.9411285227085 0.93972487901887 5.140738108043711 0.961316746739299 5.340347693378922 0.975319508273927 5.539957278714133 0.984291878269748 Quantile: 0.000001 1.940754275199844 0.00001 2.088220896973428 0.001 2.47005525107861 0.01 2.74542308402118 0.025 2.887544726184724 0.05 3.016094440249397 0.25 3.458529647316044 0.5 3.821399298626594 0.75 4.248439653875073 0.84 4.480027451060234 0.975 5.334655826220123 0.99 5.739566864049341 0.999 6.787241331282392 0.99999 9.217843716919301 0.999999 10.681477992995111 */ test_beta_prime4 => test_distribution($beta_prime_dist(10,4,4,3)), nl. /* Beta prime / 3 distribution dist = beta_prime_dist(10,4,3) Random sample sample = [8.35777,5.91598,13.4581,20.8301,10.8097,11.1245,4.17372,6.05463,9.81244,16.4083,3.66156,10.8816,2.93652,4.55035,7.01636,7.01053,3.39171,3.71766,17.3523,4.93517] Mean: sample_mean = 10.0498 mean = 10.0 Variance: sample_variance = 63.2482 variance = 65.0 PDF: 2.104133834094352 0.022993365500419 3.104133834094352 0.062169636945692 4.104133834094352 0.091767478717447 5.104133834094352 0.103337290384861 6.104133834094352 0.101420700968298 7.104133834094352 0.092355763295671 8.104133834094352 0.080616672202752 9.104133834094352 0.068695250989206 10.104133834094352 0.057759893401499 11.104133834094352 0.048235119100844 12.104133834094352 0.040171028655257 13.104133834094352 0.033450509401681 14.104133834094352 0.027896751239991 15.104133834094352 0.023325177529197 16.104133834094352 0.019566108852198 17.104133834094352 0.016472734276153 18.104133834094352 0.013922119669621 19.104133834094352 0.011813217470811 20.104133834094352 0.010063838756215 21.104133834094352 0.00860750775728 22.104133834094352 0.007390591248538 23.104133834094352 0.006369836031687 24.104133834094352 0.005510326831348 25.104133834094352 0.004783825801151 26.104133834094352 0.004167437881968 27.104133834094352 0.003642545162194 28.104133834094352 0.003193958945491 29.104133834094352 0.002809245931445 30.104133834094352 0.0024781926761 31.104133834094352 0.002192379458105 32.104133834094355 0.001944840562571 33.104133834094355 0.001729792812961 34.104133834094355 0.001542418048112 35.104133834094355 0.001378688307231 36.104133834094355 0.001235224898356 37.104133834094355 0.001109184416318 38.104133834094355 0.000998166254413 39.104133834094355 0.000900137308934 40.104133834094355 0.000813370478409 CDF: 2.104133834094352 0.01 3.104133834094352 0.052410188121126 4.104133834094352 0.130848125407051 5.104133834094352 0.229798613257422 6.104133834094352 0.333018826601229 7.104133834094352 0.430281958104843 8.104133834094352 0.516861645575588 9.104133834094352 0.591469006966949 10.104133834094352 0.654588798431057 11.104133834094352 0.707462934375038 12.104133834094352 0.751547661872663 13.104133834094352 0.788253442217254 14.104133834094352 0.818837650936479 15.104133834094352 0.844374155875101 16.104133834094352 0.8657585784197 17.104133834094352 0.883728002728604 18.104133834094352 0.89888472260133 19.104133834094352 0.911719269940186 20.104133834094352 0.922630824525652 21.104133834094352 0.931944487891682 22.104133834094352 0.939925530101951 23.104133834094352 0.94679096535009 24.104133834094352 0.952718877074786 25.104133834094352 0.957855896059749 26.104133834094352 0.96232318580991 27.104133834094352 0.966221232349803 28.104133834094352 0.969633681201302 29.104133834094352 0.972630416786789 30.104133834094352 0.975270039833511 31.104133834094352 0.977601866085308 32.104133834094355 0.979667543788632 33.104133834094355 0.981502366926039 34.104133834094355 0.983136345007243 35.104133834094355 0.984595077518172 36.104133834094355 0.985900471146275 37.104133834094355 0.98707133005974 38.104133834094355 0.988123843353694 39.104133834094355 0.989071988921925 40.104133834094355 0.989927869181602 Quantile: 0.000001 0.52543432674842 0.00001 0.704274535228682 0.001 1.378678195742391 0.01 2.104133834094352 0.025 2.574845147099357 0.05 3.064897678367243 0.25 5.299101613491629 0.5 7.898159758179692 0.75 12.065742454143948 0.84 14.919660346004189 0.975 29.995897280462259 0.99 40.193212055769898 0.999 78.597621160573794 0.99999 267.395194722145163 0.999999 482.127202701541933 */ test_beta_prime3 => test_distribution($beta_prime_dist(10,4,3)), nl. /* Beta prime / 2 distribution dist = beta_prime_dist(10,4) Random sample sample = [1.91314,2.41113,2.13561,2.40777,3.46057,2.97529,5.51481,1.66297,2.45455,5.0404,6.7101,1.86082,1.41782,1.35183,1.29703,4.40518,1.723,5.8398,0.973664,3.41549] Mean: sample_mean = 3.33308 mean = 3.33333 Variance: sample_variance = 6.62825 variance = 7.22222 PDF: 0.701377944698117 0.068980096501258 1.701377944698117 0.310011871154582 2.701377944698117 0.241850016608255 3.701377944698117 0.144705357302531 4.701377944698118 0.083690253719972 5.701377944698118 0.049418202828458 6.701377944698118 0.030191516268645 7.701377944698118 0.019109508095061 8.701377944698118 0.012502313645905 9.701377944698118 0.008427737794335 10.701377944698118 0.005834521687712 11.701377944698118 0.004136064921693 12.701377944698118 0.002994498763239 CDF: 0.701377944698117 0.01 1.701377944698117 0.229798613257422 2.701377944698117 0.516861645575589 3.701377944698117 0.707462934375038 4.701377944698118 0.81883765093648 5.701377944698118 0.883728002728604 6.701377944698118 0.922630824525652 7.701377944698118 0.94679096535009 8.701377944698118 0.96232318580991 9.701377944698118 0.972630416786789 10.701377944698118 0.979667543788632 11.701377944698118 0.984595077518172 12.701377944698118 0.988123843353694 Quantile: 0.000001 0.175144775582807 0.00001 0.234758178409561 0.001 0.459559398580797 0.01 0.701377944698117 0.025 0.858281715699786 0.05 1.021632559455748 0.25 1.76636720449721 0.5 2.632719919393231 0.75 4.021914151381316 0.84 4.97322011533473 0.975 9.998632426820754 0.99 13.397737351923299 0.999 26.199207053524596 0.99999 89.131731574048388 0.999999 160.709067567180654 */ test_beta_prime2 => test_distribution($beta_prime_dist(10,4)), nl. /* Log gamma dist dist = log_gamma_dist(1,0.2,2) Random sample sample = [2.20041,2.23449,2.28263,3.75916,2.51503,2.0257,2.40461,2.66199,2.50106,2.29371,2.15739,2.14257,2.92405,2.13019,2.1354,2.12045,2.18136,2.17509,2.07762,2.18135] Mean: sample_mean = 2.24732 mean = 2.25 Variance: sample_variance = 0.0988428 variance = 0.104167 PDF: 2.002012088709965 4.94006016072406 2.10267037822994 2.781606909129737 2.203328667749914 1.646889362407391 2.303986957269888 1.017022401912076 2.404645246789863 0.650983649762457 2.505303536309837 0.429759526987718 2.605961825829811 0.291446401719831 2.706620115349786 0.202371263448068 2.80727840486976 0.143489343583536 2.907936694389734 0.103654041591988 3.008594983909709 0.076140506519863 3.109253273429683 0.0567802909617 3.209911562949658 0.042926021491857 3.310569852469632 0.032859079205285 3.411228141989606 0.025441351709831 CDF: 2.002012088709965 0.01 2.10267037822994 0.386560891484581 2.203328667749914 0.603650163520562 2.303986957269888 0.734763210531073 2.404645246789863 0.81711978212465 2.505303536309837 0.870616292852509 2.605961825829811 0.906389640912498 2.706620115349786 0.930925826206155 2.80727840486976 0.948134961602508 2.907936694389734 0.960446930104969 3.008594983909709 0.969412912106372 3.109253273429683 0.976047197084549 3.209911562949658 0.981027457750744 3.310569852469632 0.984815360441671 3.411228141989606 0.9877310193574 Quantile: 0.000001 2.00000020000002 0.00001 2.000002000012 0.001 2.000200120088046 0.01 2.002012088709965 0.025 2.005076403090296 0.05 2.010311459317865 0.25 2.059223841048806 0.5 2.148698354997035 0.75 2.319507910772894 0.84 2.442699905907213 0.975 3.091279105182546 0.99 3.51188643150958 0.999 4.981071705534972 0.99999 11.000000000009102 0.999999 16.848931924519988 */ test_log_gamma => test_distribution($log_gamma_dist(1,0.2,2)), nl. /* Birthday dist dist = birthday_dist(365,2) Random sample sample = [22,6,32,7,19,28,37,18,29,30,41,20,11,32,30,12,16,6,6,30] Mean: sample_mean = 24.3629 Mean: Not supported Variance: sample_variance = 147.654 Variance: Not supported PDF: 4 0.01635591246655 5 0.027135573699793 6 0.040462483649111 7 0.056235703095975 8 0.074335292351669 9 0.094623833889167 10 0.116948177711078 11 0.141141378321733 12 0.167024788838064 13 0.194410275232429 14 0.223102512004973 15 0.252901319763686 16 0.28360400525285 17 0.315007665296561 18 0.34691141787179 19 0.379118526031537 20 0.41143838358058 21 0.443688335165206 22 0.47569530766255 23 0.507297234323986 24 0.538344257914529 25 0.568699703969464 26 0.598240820135939 27 0.626859282263242 28 0.654461472342399 29 0.680968537477777 30 0.706316242719269 31 0.730454633728644 32 0.753347527850321 33 0.774971854175772 34 0.795316864620154 35 0.814383238874715 36 0.83218210637988 37 0.848734008216385 38 0.864067821082121 39 0.878219664366722 40 0.891231809817949 41 0.903151611481735 42 0.914030471561869 43 0.92392285565612 44 0.932885368551426 45 0.940975899465775 46 0.948252843367255 47 0.954774402833299 48 0.960597972879423 49 0.965779609322676 50 0.970373579577988 51 0.974431993334428 52 0.978004509334275 53 0.981138113483913 54 0.983876962758852 55 0.986262288816446 56 0.988332354885201 57 0.99012245934117 CDF: CDF: Not supported Quantile: 0.000001 2 0.00001 2 0.001 2 0.01 4 0.025 5 0.05 7 0.25 15 0.5 23 0.75 32 0.84 37 0.975 52 0.99 57 0.999 70 0.99999 89 0.999999 97 */ test_birthday => test_distribution($birthday_dist(365,2)), nl. /* Coupon collector dist = coupon_collector_dist(10,10) Random sample sample = [25,26,30,34,28,29,30,26,29,21,25,40,21,26,41,27,33,37,51,42] Mean: sample_mean = 29.2024 mean = 29.2897 Variance: sample_variance = 123.67 variance = 125.687 PDF: 17 0.029784618864 18 0.034578190373126 19 0.038528927611574 20 0.0415357755775 21 0.043586542461178 22 0.044733116259693 23 0.045068364358639 24 0.044707065704249 25 0.043771519771445 26 0.042381533617262 27 0.04064806409473 28 0.038669680608043 29 0.036531067596089 30 0.03430291158401 31 0.03204266116425 32 0.029795782029832 33 0.027597241577457 34 0.02547304594935 35 0.023441718456611 36 0.021515655696614 37 0.019702330293728 38 0.018005330690943 39 0.016425241844533 40 0.014960378429718 41 0.013607386073594 42 0.012361727525963 43 0.011218070507695 44 0.010170592895943 CDF: 17 0.100094429635195 18 0.134672620008322 19 0.173201547619896 20 0.214737323197396 21 0.258323865658574 22 0.303056981918267 23 0.348125346276906 24 0.392832411981154 25 0.436603931752599 26 0.478985465369861 27 0.519633529464591 28 0.558303210072634 29 0.594834277668723 30 0.629137189252733 31 0.661179850416983 32 0.690975632446814 33 0.718572874024271 34 0.744045919973621 35 0.767487638430232 36 0.789003294126846 37 0.808705624420573 38 0.826710955111517 39 0.84313619695605 40 0.858096575385768 41 0.871703961459363 42 0.884065688985326 43 0.895283759493021 44 0.905454352388964 Quantile: 0.000001 10 0.00001 10 0.001 11 0.01 13 0.025 14 0.05 16 0.25 21 0.5 27 0.75 35 0.84 39 0.975 57 0.99 66 0.999 88 0.99999 132 0.999999 153 */ test_coupon_collector => test_distribution($coupon_collector_dist(10,10),[0.1,0.9]), nl. /* transitions = [[0.1,0.6,0.3],[0.333333,0.333333,0.333333],[0.2,0.2,0.6]] Matrix [0.1,0.6,0.3] [0.333333,0.333333,0.333333] [0.2,0.2,0.6] [len1 = 3,len2 = 3] init = [1,0,0] Random: [3,2,3,3,3,1,2,3,2,2,2,3,2,2,3,3,3,3,1,3,1,2,1,3,1,2,1,1,3,1] PDF: 1 = 0.222223 2 = 0.333334 3 = 0.444443 CDF: 1 = 0.222223 2 = 0.555557 3 = 1.0 Quantile: 0.000001 = 1 0.00001 = 1 0.001 = 1 0.01 = 1 0.025 = 1 0.05 = 1 0.1 = 1 0.25 = 2 0.5 = 2 0.75 = 3 0.84 = 3 0.9 = 3 0.975 = 3 0.99 = 3 0.999 = 3 0.99999 = 3 0.999999 = 3 Markov chains: start = 1 = [1,3,3,2,2,2,2,3,2,3,3,3,3,3,2,2,3,3,1,3,3,1,2,2,3,2,1,1,2,1] start = 2 = [2,3,3,3,2,2,2,3,3,3,3,1,2,3,3,3,2,3,3,2,3,1,2,3,3,2,1,3,2,3] start = 3 = [3,3,3,3,3,3,2,3,3,3,3,2,3,3,1,3,3,3,3,2,3,2,2,1,2,1,2,2,1,3] Stationary: stationary1 = [0.222222,0.333333,0.444444] 1: 0.22222222222227 2: 0.33333333333349 3: 0.44444444444424 stationary2 = [0.222222,0.333333,0.444444] 1: 0.22222222222227 2: 0.33333333333349 3: 0.44444444444424 */ test_discrete_markov_process => Transitions = [[1/10, 6/10, 3/10], [1/3 , 1/3 , 1/3 ], [2/10, 2/10, 6/10]], % Transitions := [[1,0,0], % [0,1,0], % [0,0,1]], % This throws an convergence error % Transitions := [[1,1,1], % [0,1,1], % [0,0,1]], % Transitions := [[0,1,0], % [0,0,1], % [1,0,0]], % Transitions := random_transition_matrix(30,1), println(transitions=Transitions), show_matrix(Transitions), println([len1=Transitions.len,len2=Transitions[1].len]), Len = Transitions.len, Init = one_hot(Len,1), println(init=Init), println("Random:"), println(discrete_markov_process_dist_n(Transitions,Init,10,30)), nl, println("PDF:"), foreach(I in 1..Len) println(I=discrete_markov_process_dist_pdf(Transitions,Init,10,I)) end, nl, println("CDF:"), foreach(I in 1..Len) println(I=discrete_markov_process_dist_cdf(Transitions,Init,10,I)) end, nl, println("Quantile:"), foreach(Q in quantile_qs()) println(Q=discrete_markov_process_dist_quantile(Transitions,Init,10,Q)) end, nl, println("Markov chains:"), foreach(I in 1..Len) println(start=I=markov_chain(Transitions,one_hot(Len,I),30)) end, nl, println("Stationary:"), Stationary1 = stationary_dist(Transitions), println(stationary1=Stationary1), foreach({I,S} in zip(1..Len,Stationary1)) printf("%w: %.14f\n",I,S) end, nl, Stationary2 = stationary_dist1(Transitions,1.0e-16), println(stationary2=Stationary2), foreach({I,S} in zip(1..Len,Stationary1)) printf("%w: %.14f\n",I,S) end, nl. /* Shifted geometric distr dist = shifted_geometric_dist(0.5) Random sample sample = [1,1,1,2,3,1,3,2,1,1,2,2,5,3,3,1,2,1,1,3] Mean: sample_mean = 2.0295 mean = 2.0 Variance: sample_variance = 2.01183 variance = 2.0 PDF: 1 0.5 2 0.25 3 0.125 4 0.0625 5 0.03125 6 0.015625 7 0.0078125 8 0.00390625 9 0.001953125 10 0.0009765625 11 0.00048828125 12 0.000244140625 13 0.0001220703125 14 0.00006103515625 CDF: 1 0.5 2 0.75 3 0.875 4 0.9375 5 0.96875 6 0.984375 7 0.9921875 8 0.99609375 9 0.998046875 10 0.9990234375 11 0.99951171875 12 0.999755859375 13 0.9998779296875 14 0.99993896484375 Quantile: 0.000001 1 0.00001 1 0.001 1 0.01 1 0.025 1 0.05 1 0.1 1 0.25 1 0.5 1 0.75 2 0.84 3 0.9 4 0.975 6 0.99 7 0.999 10 0.99999 17 0.999999 20 */ test_shifted_geometric => test_distribution($shifted_geometric_dist(0.5),[0.001,0.9999]), nl. % TODO: All distributions does not have all functions. % E.g. % negative_binomial_dist has no variance % cauchy_dist has not mean or variance etc. % % And add_* does not support all distributions, e.g. % those with lists as parameters. not_supported(What) => println(What ++ ": Not supported"). % test_distribution(Dist) => test_distribution(Dist,new_map()). test_distribution(Dist) => test_distribution(Dist,[]). test_distribution(Dist,Qs) => _ = random2(), Dist =.. [DistName|Params], bp.atom_chars(DistName,DistL), if not once(append(_,[d,i,s,t],DistL)) then bp.atom_concat(DistName,'_dist',Dist1), F =.. [Dist1,Params].flatten, Dist := F end, println(dist=Dist), println("Random sample"), Sample = [apply(Dist) : _ in 1..20], println(sample=Sample), nl, Sample2 = [apply(Dist) : _ in 1..10_000], println("Mean:"), println(sample_mean=Sample2.mean), catch(println(mean=meanf(Dist)),_,not_supported("Mean")), println("Variance:"), println(sample_variance=Sample2.variance), catch(println(variance=variancef(Dist)),_,not_supported("Variance")), nl, println("PDF:"), if Qs.len > 0 then [Q1,Q2] = Qs, catch(pdf_all(Dist,Q1,Q2).printf_list,_,not_supported("PDF")), else catch(pdf_all(Dist,0.01,0.99).printf_list,_,not_supported("PDF")), end, nl, println("CDF:"), if Qs.len > 0 then [Q1,Q2] = Qs, catch(cdf_all(Dist,Q1,Q2).printf_list,_,not_supported("CDF")), else catch(cdf_all(Dist,0.01,0.99).printf_list,_,not_supported("CDF")), nl, end, nl, println("Quantile:"), catch(quantile_all(Dist).printf_list,_,not_supported("Quantile")), nl. /* prob_n_heads_after_k_in_max_m_tosses dist = prob_n_heads_after_k_in_max_m_tosses_dist(1 / 2,21,3) Random sample sample = [22,13,3,8,22,7,15,6,3,7,9,22,14,9,20,7,4,3,5,16] Mean: sample_mean = 11.7447 Mean: Not supported Variance: sample_variance = 47.2279 Variance: Not supported PDF: 3 0.125 4 0.0625 5 0.0625 6 0.0625 7 0.0546875 8 0.05078125 9 0.046875 10 0.04296875 11 0.03955078125 12 0.036376953125 13 0.033447265625 14 0.03076171875 15 0.028289794921875 16 0.026016235351562 17 0.02392578125 18 0.022003173828125 19 0.020235061645508 20 0.018609046936035 21 0.01711368560791 22 0.195858001708984 CDF: 3 0.125 4 0.1875 5 0.25 6 0.3125 7 0.3671875 8 0.41796875 9 0.46484375 10 0.5078125 11 0.54736328125 12 0.583740234375 13 0.6171875 14 0.64794921875 15 0.676239013671875 16 0.702255249023438 17 0.726181030273438 18 0.748184204101562 19 0.76841926574707 20 0.787028312683105 21 0.804141998291016 22 1 Quantile: 0.000001 3 0.00001 3 0.001 3 0.01 3 0.025 3 0.05 3 0.25 5 0.5 10 0.75 19 0.84 22 0.975 22 0.99 22 0.999 22 0.99999 22 0.999999 22 */ test_prob_n_heads_after_k_in_max_m_tosses => test_distribution($prob_n_heads_after_k_in_max_m_tosses_dist(1/2,21,3)), nl. /* Kth record dist = k_record_dist(2) Random sample sample = [5,2,2,2,3,6,2,3,4,2,5,2,6,2,2,4,2,5,4,4] Mean: sample_mean = 3.1565 Mean: Not supported Variance: sample_variance = 3.28681 Variance: Not supported PDF: 2 0.5 3 0.166666666666667 4 0.083333333333333 5 0.05 6 0.033333333333333 7 0.023809523809524 8 0.017857142857143 9 0.013888888888889 10 0.011111111111111 11 0.009090909090909 12 0.007575757575758 13 0.006410256410256 14 0.005494505494505 15 0.004761904761905 16 0.004166666666667 17 0.003676470588235 18 0.003267973856209 19 0.002923976608187 20 0.002631578947368 21 0.002380952380952 CDF: 2 0.5 3 0.666666666666667 4 0.75 5 0.8 6 0.833333333333333 7 0.857142857142857 8 0.875 9 0.888888888888889 10 0.9 11 0.909090909090909 12 0.916666666666667 13 0.923076923076923 14 0.928571428571428 15 0.933333333333333 16 0.9375 17 0.941176470588235 18 0.944444444444444 19 0.947368421052631 20 0.95 21 0.952380952380952 Quantile: k_record_dist_quantile(2,0.999000): overflow. This is an estimate! k_record_dist_quantile(2,0.999990): overflow. This is an estimate! k_record_dist_quantile(2,0.999999): overflow. This is an estimate! 0.000001 2 0.00001 2 0.001 2 0.01 2 0.025 2 0.05 2 0.1 2 0.25 2 0.5 2 0.75 4 0.84 7 0.9 10 0.975 41 0.99 101 0.999 172 0.99999 172 0.999999 172 */ test_kth_record => test_distribution($k_record_dist(2),[0.01,0.95]), nl. /* Num records dist = num_records_dist(10) Random sample sample = [2,3,2,5,3,1,3,1,2,1,2,2,4,2,3,5,1,4,3,4] Mean: sample_mean = 2.9338 mean = 2.92897 Variance: sample_variance = 1.38162 Variance: Not supported PDF: 1 0.1 2 0.282896825396825 3 0.323164682539683 4 0.199426807760141 5 0.07421875 6 0.017436342592593 7 0.002604166666667 8 0.000239748677249 9 0.000012400793651 10 0.000000275573192 CDF: 1 0.1 2 0.382896825396825 3 0.706061507936508 4 0.905488315696649 5 0.979707065696649 6 0.997143408289242 7 0.999747574955908 8 0.999987323633157 9 0.999999724426808 10 1.0 Quantile: 0.000001 1 0.00001 1 0.001 1 0.01 1 0.025 1 0.05 1 0.1 1 0.25 2 0.5 3 0.75 4 0.84 4 0.9 4 0.975 5 0.99 6 0.999 7 0.99999 9 0.999999 9 */ test_num_records => test_distribution($num_records_dist(10),[0.01,0.99999999]), nl. /* Random: random = [[0,3,2],[1,4,0],[0,4,1],[1,3,1],[4,0,1],[3,1,1],[0,4,1],[1,3,1],[1,3,1],[1,1,3]] PDF for all combinations: [1,3,1] 0.176120249574589 [2,2,1] 0.13838019609432 [2,3,0] 0.107629041406693 [1,2,2] 0.100640142614051 [1,4,0] 0.097844583096994 [0,4,1] 0.073383437322745 [0,3,2] 0.058706749858196 [3,2,0] 0.051251924479378 [2,1,2] 0.050320071307025 [3,1,1] 0.041933392755854 [0,5,0] 0.030984117980715 [1,1,3] 0.021347909039344 [0,2,3] 0.019568916619399 [4,1,0] 0.010483348188964 [3,0,2] 0.00729276395754 [2,0,3] 0.005104934770278 [4,0,1] 0.004102179726116 [0,1,4] 0.002668488629918 [1,0,4] 0.001392254937349 [5,0,0] 0.000729276395754 [0,0,5] 0.000116021244779 CDF is the same as the PDF: [1,3,1] 0.176120249574589 [2,2,1] 0.13838019609432 [2,3,0] 0.107629041406693 [1,2,2] 0.100640142614051 [1,4,0] 0.097844583096994 [0,4,1] 0.073383437322745 [0,3,2] 0.058706749858196 [3,2,0] 0.051251924479378 [2,1,2] 0.050320071307025 [3,1,1] 0.041933392755854 [0,5,0] 0.030984117980715 [1,1,3] 0.021347909039344 [0,2,3] 0.019568916619399 [4,1,0] 0.010483348188964 [3,0,2] 0.00729276395754 [2,0,3] 0.005104934770278 [4,0,1] 0.004102179726116 [0,1,4] 0.002668488629918 [1,0,4] 0.001392254937349 [5,0,0] 0.000729276395754 [0,0,5] 0.000116021244779 Mean: mean = [1.36364,2.61364,1.02273] */ test_multivariate_hypergeometric => N = 5, NumBalls = [12,23,9], println("Random:"), println(random=multivariate_hypergeometric_dist_n(N,NumBalls,10)), nl, println("PDF for all combinations:"), Cs = comb_sum(NumBalls.len,N,N), [C=multivariate_hypergeometric_dist_pdf(N,NumBalls,C) : C in Cs].sort_down(2).printf_list, nl, println("CDF is the same as the PDF:"), [C=multivariate_hypergeometric_dist_cdf(N,NumBalls,C) : C in Cs].sort_down(2).printf_list, nl, println("Mean:"), println(mean=multivariate_hypergeometric_dist_mean(N,NumBalls)), nl. /* Generalized extreme value (GEV) dist = generalized_extreme_value_dist(2,2,0.99) Random sample sample = [2.18718,1.68124,0.434181,4.23843,3.56686,4.39325,7.96969,29.0609,15.8345,1.30691,3.28249,23.6213,5.45116,0.604172,0.807186,0.428743,1.14669,23.3418,7.58521,2.63064] Mean: sample_mean = 23.111 mean = 200.854 Variance: sample_variance = 200846.0 Variance: Not supported PDF: 0.864508658289421 0.262893122556485 1.864508658289421 0.196667420171403 2.864508658289421 0.121602492834804 3.864508658289421 0.080132828925439 4.864508658289421 0.056258667410107 5.864508658289421 0.0415077083996 6.864508658289421 0.031823042483637 7.864508658289421 0.025145518862497 8.86450865828942 0.020355991064013 9.86450865828942 0.016808113521072 10.86450865828942 0.014108872679107 11.86450865828942 0.012008687555598 12.86450865828942 0.010343116840615 13.86450865828942 0.009000347381488 14.86450865828942 0.007902254873336 15.86450865828942 0.006992945319137 16.86450865828942 0.00623158919146 17.86450865828942 0.005587807706265 CDF: 0.864508658289421 0.1 1.864508658289421 0.342103604655407 2.864508658289421 0.497679895967926 3.864508658289421 0.596535850893639 4.864508658289421 0.663713570837842 5.864508658289421 0.712048518322803 6.864508658289421 0.748397238921866 7.864508658289421 0.776687230473537 8.86450865828942 0.799312647035514 9.86450865828942 0.817810412235445 10.86450865828942 0.83321022189002 11.86450865828942 0.846226928501612 12.86450865828942 0.85737190055339 13.86450865828942 0.867020397640808 14.86450865828942 0.8754539127048 15.86450865828942 0.882887670889596 16.86450865828942 0.889489007025837 17.86450865828942 0.895389959831455 Quantile: 0.000001 0.129915551746338 0.00001 0.15961092932594 0.001 0.277959248068268 0.01 0.425230143748681 0.025 0.534639920602227 0.05 0.661597722302951 0.1 0.864508658289421 0.25 1.441833415755584 0.5 2.883670818823004 0.75 6.915191851247599 0.84 11.365995572727652 0.9 18.727312232765755 0.975 76.893366280419897 0.99 191.950976890918838 0.999 1884.408609556793635 0.99999 180049.783118819032097 0.999999 1759521.51273583015427 */ test_generalized_extreme_value_dist => test_distribution($generalized_extreme_value_dist(2,2,0.99),[0.1,0.9]), nl. /* dist = poisson_process_dist(1 / 2,4) Random sample sample = [5,5,2,4,2,1,1,0,2,2,4,0,4,3,3,5,5,2,1,2] Mean: sample_mean = 1.9913 mean = 2.0 Variance: sample_variance = 2.05662 variance = 2.0 PDF: 0 0.135335283236613 1 0.270670566473225 2 0.270670566473225 3 0.180447044315484 4 0.090223522157742 5 0.036089408863097 6 0.012029802954366 CDF: 0 0.135335283236613 1 0.406005849709838 2 0.676676416183064 3 0.857123460498547 4 0.947346982656289 5 0.983436391519386 6 0.995466194473751 Quantile: 0.000001 0 0.00001 0 0.001 0 0.01 0 0.025 0 0.05 0 0.1 0 0.25 1 0.5 2 0.75 3 0.84 3 0.9 4 0.975 5 0.99 6 0.999 8 0.99999 10 0.999999 12 */ test_poisson_process => test_distribution($poisson_process_dist(1/2,4)), nl. /* Random walk process dist = random_walk_process_dist(3 / 5,10) Random sample sample = [-2,-2,4,4,0,4,2,2,6,2,4,2,0,-2,4,-4,4,2,-4,6] Mean: sample_mean = 2.0096 mean = 2.0 Variance: sample_variance = 9.75191 variance = 9.6 PDF: -6 0.010616832 -5 0.0 -4 0.042467328 -3 0.0 -2 0.111476736 -1 0.0 0 0.200658124799999 1 0.0 2 0.250822656000001 3 0.0 4 0.214990848 5 0.0 6 0.120932352 7 0.0 8 0.040310784 CDF: -6 0.0122945536 -5 0.0122945536 -4 0.0547618816 -3 0.0547618816 -2 0.1662386176 -1 0.1662386176 0 0.366896742400001 1 0.366896742400001 2 0.6177193984 3 0.6177193984 4 0.832710246400001 5 0.832710246400001 6 0.9536425984 7 0.9536425984 8 0.9939533824 Quantile: 0.000001 -10 0.00001 -10 0.001 -8 0.01 -6 0.025 -4 0.05 -4 0.1 -2 0.25 0 0.5 2 0.75 4 0.84 6 0.9 6 0.975 8 0.99 8 0.999 10 0.99999 10 0.999999 10 */ test_random_walk => test_distribution($random_walk_process_dist(3/5,10)), nl. /* Sum prob dist dist = sum_prob_dist(1,6,3) Random sample sample = [15,8,7,8,12,15,13,10,10,9,13,10,12,8,12,7,4,9,9,10] Mean: sample_mean = 10.444 mean = 10.5 Variance: sample_variance = 8.80946 variance = 8.75 PDF: 4 0.013888888888889 5 0.027777777777778 6 0.046296296296296 7 0.069444444444444 8 0.097222222222222 9 0.115740740740741 10 0.125 11 0.125 12 0.115740740740741 13 0.097222222222222 14 0.069444444444444 15 0.046296296296296 16 0.027777777777778 17 0.013888888888889 CDF: 4 0.018518518518519 5 0.046296296296296 6 0.092592592592593 7 0.162037037037037 8 0.259259259259259 9 0.375 10 0.5 11 0.625 12 0.740740740740741 13 0.837962962962963 14 0.907407407407407 15 0.953703703703704 16 0.981481481481481 17 0.99537037037037 Quantile: 0.000001 3 0.00001 3 0.001 3 0.01 4 0.025 5 0.05 6 0.1 7 0.25 8 0.5 10 0.75 13 0.84 14 0.9 14 0.975 16 0.99 17 0.999 18 0.99999 18 0.999999 18 */ test_sum_prob => test_distribution($sum_prob_dist(1,6,3)), nl. /* Binomial process dist = binomial_process_dist(0.2,10) Random sample sample = [4,2,4,2,3,3,2,2,0,2,3,2,3,3,0,3,3,3,3,2] Mean: sample_mean = 2.0036 mean = 2.0 Variance: sample_variance = 1.61859 variance = 1.6 PDF: 0 0.1073741824 1 0.268435456 2 0.301989888 3 0.201326592 4 0.088080384 5 0.0264241152 6 0.005505024 7 0.000786432 8 0.000073728 CDF: 0 0.1073741824 1 0.375809638400001 2 0.677799526400001 3 0.8791261184 4 0.9672065024 5 0.9936306176 6 0.9991356416 7 0.9999220736 8 0.9999958016 Quantile: 0.000001 0 0.00001 0 0.001 0 0.01 0 0.025 0 0.05 0 0.1 0 0.25 1 0.5 2 0.75 3 0.84 3 0.9 4 0.975 5 0.99 5 0.999 6 0.99999 8 0.999999 9 */ test_binomial_process => test_distribution($binomial_process_dist(0.2,10),[0.01,0.99999]), nl. /* dist = wiener_process_dist(3,2,3) Random sample sample = [9.40788,4.27167,12.3172,10.6208,14.7747,3.98544,14.2402,12.5157,7.64504,9.12487,7.53195,9.99768,4.71364,10.301,7.14872,9.30196,9.3849,11.4311,6.08215,6.265] Mean: sample_mean = 9.00419 mean = 9 Variance: sample_variance = 11.6328 variance = 12 PDF: 0.941294572162818 0.007693810737823 1.941294572162818 0.014444422073243 2.941294572162818 0.024949832531129 3.941294572162818 0.039650064004458 4.941294572162818 0.057973422994799 5.941294572162818 0.077987103007061 6.941294572162818 0.096521802867398 7.941294572162818 0.109909910882864 8.941294572162818 0.115148180373511 9.941294572162818 0.110990573716593 10.941294572162818 0.09842918889875 11.941294572162818 0.080310163404781 12.941294572162818 0.060287309961944 13.941294572162818 0.041638022498113 14.941294572162818 0.026458369562443 15.941294572162818 0.015468380771281 16.941294572162818 0.008320231751054 CDF: 0.941294572162818 0.01 1.941294572162818 0.020791336095567 2.941294572162818 0.040145716714249 3.941294572162818 0.072100734649734 4.941294572162818 0.120669337552209 5.941294572162818 0.188625645691406 6.941294572162818 0.276156720178558 7.941294572162818 0.379946259886215 8.941294572162818 0.49323952964258 9.941294572162818 0.607084544600451 10.941294572162818 0.712397867997984 11.941294572162818 0.802081223120907 12.941294572162818 0.872388336990839 13.941294572162818 0.923127708213775 14.941294572162818 0.956836920394662 15.941294572162818 0.977453138097149 16.941294572162818 0.989060278532013 Quantile: 0.000001 -7.466344825490641 0.00001 -5.774015087605868 0.001 -1.704878722946651 0.01 0.941294572162818 0.025 2.210485595542989 0.05 3.302059894212213 0.1 4.560575151914626 0.25 6.663498966951893 0.5 9.0 0.75 11.336501033048107 0.84 12.444903159413377 0.9 13.439424848085375 0.975 15.789514404457009 0.99 17.058705427837189 0.999 19.704878722946596 0.99999 23.774015087591437 0.999999 25.466344825489234 */ test_wiener_process => test_distribution($wiener_process_dist(3,2,3)), nl. /* Chinese restaurant process (crp) dist = crp_dist(1 / 2,10) Random sample sample = [3,1,1,1,2,3,1,3,1,1,2,1,2,2,4,1,1,2,3,2] Mean: sample_mean = 2.1442 mean = 2.13326 Variance: sample_variance = 0.941206 Variance: Not supported PDF: 1 0.28377319275152 2 0.401392676810632 3 0.229263684372043 4 0.070739977447924 5 0.013163307280954 CDF: 1 0.28377319275152 2 0.685165869562153 3 0.914429553934195 4 0.985169531382119 5 0.998332838663073 Quantile: 0.000001 1 0.00001 1 0.001 1 0.01 1 0.025 1 0.05 1 0.1 1 0.25 1 0.5 2 0.75 3 0.84 3 0.9 3 0.975 4 0.99 5 0.999 6 0.99999 7 0.999999 8 */ test_crp => test_distribution($crp_dist(1/2,10)), nl. /* test_dist_stats/1 tests a distribution with all kind of stuff given a generated data from a distribution. Picat> test_dist_stats($normal_dist(100,15)) ... dist = normal_dist(100,15) n = 10000 Probabilities (truncated): 160.74357723196988: 0.0001000000000000 157.065687592073402: 0.0001000000000000 156.131091112863857: 0.0001000000000000 152.752594375085977: 0.0001000000000000 ......... 49.508601646654455: 0.0001000000000000 48.491204123927574: 0.0001000000000000 48.197609851320948: 0.0001000000000000 47.2516935761195: 0.0001000000000000 mean = 99.9161 variance = 227.119 Percentiles: (0.001 54.951519744936256) (0.01 64.823654719953865) (0.025 70.295995337402388) (0.05 75.261478645688243) (0.1 80.680315293448928) (0.25 89.695236845302361) (0.5 99.894486160236767) (0.75 110.04339223299166) (0.84 114.7628732799068) (0.9 119.16589103849948) (0.95 124.75852614875184) (0.975 129.70817231456377) (0.99 135.21335571430859) (0.999 146.81025994184256) (0.9999 157.0660553810348) (0.99999 160.37582504688106) HPD intervals: HPD interval (0.5): 90.01506991203630..110.28258439001847 HPD interval (0.84): 79.00236562469793..120.85141384336431 HPD interval (0.9): 76.04039418017811..125.37809750215655 HPD interval (0.95): 69.78536801096877..128.64249254952512 HPD interval (0.99): 60.49964112725637..138.41657566557154 HPD interval (0.999): 49.86360854683320..148.67585174527946 HPD interval (0.9999): 47.25169357611950..157.06568759207340 HPD interval (0.99999): 47.25169357611950..160.74357723196988 Histogram (total 10000) 47.252: 3 (0.000 / 0.000) 50.089: 2 (0.000 / 0.001) 52.926: 3 (0.000 / 0.001) 55.764: 10 # (0.001 / 0.002) 58.601: 25 ## (0.003 / 0.004) 61.438: 27 ## (0.003 / 0.007) 64.275: 47 #### (0.005 / 0.012) 67.113: 79 ###### (0.008 / 0.020) 69.950: 96 ######## (0.010 / 0.029) 72.787: 148 ############ (0.015 / 0.044) 75.625: 196 ################ (0.020 / 0.064) 78.462: 271 ###################### (0.027 / 0.091) 81.299: 362 ############################# (0.036 / 0.127) 84.137: 435 ################################### (0.043 / 0.170) 86.974: 535 ########################################### (0.053 / 0.224) 89.811: 576 ############################################## (0.058 / 0.281) 92.648: 668 ##################################################### (0.067 / 0.348) 95.486: 722 ########################################################## (0.072 / 0.420) 98.323: 753 ############################################################ (0.075 / 0.496) 101.160: 733 ########################################################## (0.073 / 0.569) 103.998: 749 ############################################################ (0.075 / 0.644) 106.835: 665 ##################################################### (0.067 / 0.710) 109.672: 610 ################################################# (0.061 / 0.771) 112.510: 556 ############################################ (0.056 / 0.827) 115.347: 407 ################################ (0.041 / 0.868) 118.184: 370 ############################# (0.037 / 0.905) 121.021: 289 ####################### (0.029 / 0.934) 123.859: 192 ############### (0.019 / 0.953) 126.696: 167 ############# (0.017 / 0.970) 129.533: 100 ######## (0.010 / 0.980) 132.371: 77 ###### (0.008 / 0.987) 135.208: 48 #### (0.005 / 0.992) 138.045: 32 ### (0.003 / 0.995) 140.882: 19 ## (0.002 / 0.997) 143.720: 9 # (0.001 / 0.998) 146.557: 11 # (0.001 / 0.999) 149.394: 3 (0.000 / 0.999) 152.232: 2 (0.000 / 1.000) 155.069: 1 (0.000 / 1.000) 157.906: 2 (0.000 / 1.000) Summary statistics Count: 10000 Min: 47.2516935761195 Max: 160.74357723196988 Sum: 999161.11132348247 Mean: 99.91611113234876 Variance (pop): 227.11884710759227 Std dev (pop): 15.070462737009514 Variance (sample): 227.14156126371864 Std dev (sample): 15.071216316665309 Skewness (unbiased): 0.000168244730534703 Kurtosis excess: -3.0005983477726348 Median: 99.894486160236767 Q1 (25%): 89.695236845302361 Q3 (75%): 110.04339223299166 ... */ test_stats ?=> _ = random2(), RunAll = true, % Continuous distributions test_dist_stats($normal_dist(100,15)), if RunAll == true then test_dist_stats($exponential_dist(1/4)), test_dist_stats($exponential_dist(1/2000)), % my bulbs at home test_dist_stats($exponential_dist(2000)), test_dist_stats($gamma_dist(1,2)), % Discrete distributions test_dist_stats($geometric_dist(0.1)), test_dist_stats($geometric_dist(0.5)), test_dist_stats($geometric_dist(0.9)), test_dist_stats($bernoulli_dist(0.5)), test_dist_stats($bernoulli_dist(1/6)), test_dist_stats($binomial_dist(10,0.5)), test_dist_stats($pascal_dist(25,1/6)), test_dist_stats($binomial_dist(100,0.5)), test_dist_stats($negative_binomial_dist(3,0.7)), test_dist_stats($poisson_dist(1)) end, fail, nl. test_stats => true. test_dist_stats(Dist) => println($test_dist(Dist)), % Dist =.. [Dist|_], % Ns = [10,100,1_100,10_000,100_000,1_000_000], Ns = [10,100,1_000,10_000], foreach(N in Ns) garbage_collect(300_000_000), println(dist=Dist), println(n=N), L = [Dist.apply() : _ in 1..N], if N < 101 then println(l=L) end, % catch(show(L),_,true), % includes all the one below show(L), /* show_probs_trunc(L), nl, show_percentiles(L), nl, show_histogram(L), nl. show_hpd_intervals(L), nl, show_summary_stats(L), nl, */ nl end, nl.