/* Streaks in chess in Picat. From https://math.stackexchange.com/questions/417762/probability-of-20-consecutive-success-in-100-runs """ Probability of 20 consecutive success in 100 runs. Suppose a chess player have a win rate equal 90%, what is the chance to have 20 consecutive wins (successes) playing 100 games? Consider that lose/draw = fail. I've studied basic statistics in college and it seems like a binomial distribution problem (right?), but honestly I can't figure out a way to solve this problem considering "consecutive" successes. Is there a statistical distribution for this kinda problem? Thanks very much! I really appreciate any thoughts! """ From a comment: """ Feller has this all worked out on p. 325 of An Introduction to Probability Theory and Its Applications, 3rd Edition, equation 7.11: ... So the probability that the chess player will have at least one run of 20 successes is 0.7753, approximately. """ The model gets about the same result (average value of p = 0.7757400000000001) Here we also check how many times the run is >= 20 (average: 1). See the comments for probability_of_run_size in ppl_utils.pi for more on the theoretical calculation. Cf - ppl_runs.pi - ppl_streaks.pi - ppl_ppl_n_heads_in_a_row_after_k_tosses.pi - my Gamble model gamble_streaks_chess.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. /* [n = 100,p = 0.9,r = 20] var : max run Probabilities (truncated): 23: 0.0533000000000000 20: 0.0527000000000000 26: 0.0516000000000000 24: 0.0496000000000000 ......... 72: 0.0001000000000000 71: 0.0001000000000000 70: 0.0001000000000000 69: 0.0001000000000000 mean = 26.9812 HPD intervals: HPD interval (0.94): 12.00000000000000..44.00000000000000 HPD interval (0.99): 9.00000000000000..58.00000000000000 HPD interval (0.999): 9.00000000000000..80.00000000000000 HPD interval (0.9999): 9.00000000000000..85.00000000000000 HPD interval (0.99999): 9.00000000000000..93.00000000000000 Histogram (total 10000) 9.000: 17 # (0.002 / 0.002) 11.100: 94 ##### (0.009 / 0.011) 13.200: 275 ################ (0.028 / 0.039) 15.300: 525 ############################### (0.052 / 0.091) 17.400: 785 ############################################## (0.079 / 0.170) 19.500: 1000 ########################################################## (0.100 / 0.270) 21.600: 973 ######################################################### (0.097 / 0.367) 23.700: 1029 ############################################################ (0.103 / 0.470) 25.800: 1002 ########################################################## (0.100 / 0.570) 27.900: 777 ############################################# (0.078 / 0.648) 30.000: 850 ################################################## (0.085 / 0.733) 32.100: 601 ################################### (0.060 / 0.793) 34.200: 393 ####################### (0.039 / 0.832) 36.300: 376 ###################### (0.038 / 0.870) 38.400: 313 ################## (0.031 / 0.901) 40.500: 232 ############## (0.023 / 0.924) 42.600: 171 ########## (0.017 / 0.941) 44.700: 133 ######## (0.013 / 0.955) 46.800: 92 ##### (0.009 / 0.964) 48.900: 81 ##### (0.008 / 0.972) 51.000: 88 ##### (0.009 / 0.981) 53.100: 35 ## (0.004 / 0.984) 55.200: 30 ## (0.003 / 0.987) 57.300: 28 ## (0.003 / 0.990) 59.400: 28 ## (0.003 / 0.993) 61.500: 13 # (0.001 / 0.994) 63.600: 17 # (0.002 / 0.996) 65.700: 9 # (0.001 / 0.997) 67.800: 7 (0.001 / 0.997) 69.900: 2 (0.000 / 0.998) 72.000: 3 (0.000 / 0.998) 74.100: 5 (0.001 / 0.998) 76.200: 1 (0.000 / 0.998) 78.300: 4 (0.000 / 0.999) 80.400: 2 (0.000 / 0.999) 82.500: 5 (0.001 / 1.000) 84.600: 3 (0.000 / 1.000) 86.700: 0 (0.000 / 1.000) 88.800: 0 (0.000 / 1.000) 90.900: 1 (0.000 / 1.000) var : prob Probabilities: true: 0.7831000000000000 false: 0.2169000000000000 mean = 0.7831 HPD intervals: show_hpd_intervals: data is not numeric Histogram (total 10000) false : 2169 ################# (0.217 / 0.217) true : 7831 ############################################################ (0.783 / 1.000) var : num runs >= r Probabilities: 1: 0.4964000000000000 2: 0.2604000000000000 0: 0.2169000000000000 3: 0.0262000000000000 4: 0.0001000000000000 mean = 1.0962 HPD intervals: HPD interval (0.94): 0.00000000000000..2.00000000000000 HPD interval (0.99): 0.00000000000000..3.00000000000000 HPD interval (0.999): 0.00000000000000..3.00000000000000 HPD interval (0.9999): 0.00000000000000..3.00000000000000 HPD interval (0.99999): 0.00000000000000..4.00000000000000 Histogram (total 10000) 0: 2169 ########################## (0.217 / 0.217) 1: 4964 ############################################################ (0.496 / 0.713) 2: 2604 ############################### (0.260 / 0.974) 3: 262 ### (0.026 / 1.000) 4: 1 (0.000 / 1.000) theoretical_prob = 0.775299 */ go ?=> N = 100, P = 9/10, R = 20, println([n=N,p=P,r=R]), reset_store, run_model(10_000,$model(N,P,R),[show_probs_trunc,mean, % show_percentiles, show_hpd_intervals,hpd_intervals=[0.94,0.99,0.999,0.9999,0.99999], show_histogram % min_accepted_samples=1000,show_accepted_samples=true ]), println(theoretical_prob=probability_of_run_size(N,P,R)), nl, % show_store_lengths,nl, % fail, nl. go => true. model(N,P,R) => Runs = generate_01_runs(N,P), % We only care about the winning runs WinRuns = filter_runs(Runs,1), WinRunsLens = WinRuns.map(len), MaxRun = WinRunsLens.max, Prob = check(MaxRun >= R), % Num runs >= R NumRunsGeR = [1 : Run in WinRunsLens, Run >= R].sum, add("max run",MaxRun), add("prob",Prob), add("num runs >= r",NumRunsGeR).