/* CDF from data in Picat. cdf_from_data/1 is a simple way of creating a CDF from data. It uses get_probs/1 which gives the PDF. Here are also some related functions shown: - pdf_from_data/1 - cdf_from_pdf/1, - quantile_from_cdf/2 Note: Some of these are variants of existing functions, e.g. get_freqs/1, quantiles_data/2, etc. Cf my Gamble model gamble_cdf_from_data.rkt This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ppl_distributions, ppl_utils. import util. % import ordset. main => go. /* PDF: 0 = 0.00008 1 = 0.00029 2 = 0.00211 3 = 0.00758 4 = 0.01885 5 = 0.03772 6 = 0.06375 7 = 0.08827 8 = 0.11246 9 = 0.12427 10 = 0.12452 11 = 0.11497 12 = 0.09638 13 = 0.07371 14 = 0.05269 15 = 0.03411 16 = 0.02123 17 = 0.01248 18 = 0.00724 19 = 0.0038 20 = 0.00193 21 = 0.00078 22 = 0.00044 23 = 0.00018 24 = 0.00008 25 = 0.00003 26 = 0.00003 27 = 0.00002 CDF: 0 = 0.00008 1 = 0.00037 2 = 0.00248 3 = 0.01006 4 = 0.02891 5 = 0.06663 6 = 0.13038 7 = 0.21865 8 = 0.33111 9 = 0.45538 10 = 0.5799 11 = 0.69487 12 = 0.79125 13 = 0.86496 14 = 0.91765 15 = 0.95176 16 = 0.97299 17 = 0.98547 18 = 0.99271 19 = 0.99651 20 = 0.99844 21 = 0.99922 22 = 0.99966 23 = 0.99984 24 = 0.99992 25 = 0.99995 26 = 0.99998 27 = 1.0 Quantile: 0.000001 = 0 0.00001 = 0 0.001 = 2 0.01 = 3 0.025 = 4 0.05 = 5 0.1 = 6 0.25 = 8 0.5 = 10 0.75 = 12 0.84 = 13 0.9 = 14 0.975 = 17 0.99 = 18 0.999 = 21 0.99999 = 27 0.999999 = 27 */ go ?=> _ = random2(), % Data = binomial_dist_n(10,1/2,10000), Data = poisson_dist_n(10,100_000), % Data = [roundf(V,0.1) : V in normal_dist_n(100,15,100)], % Data = normal_dist_n(100,15,10000), PDF = pdf_from_data(Data), println("PDF:"), foreach(V=C in PDF) println(V=C) end, nl, % CDF = cdf_from_data(Data), CDF = cdf_from_pdf(PDF), println("CDF:"), foreach(V=C in CDF) println(V=C) end, nl, println("Quantile:"), foreach(Q in quantile_qs()) println(Q=quantile_from_cdf(CDF,Q)) end, nl. go => true.