Question

Consider a sequence of n Bernoulli trials with success probabilty p per trial. A string of consecutive successes is known asPLEASE ANSWER FROM WHERE IT SAYS "Continuing from Part 1"

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I ran the length 5 and p = 0.5 eight times on my PC. The probability came around 0.53

I ran the length 7 and p = 0.7 five times on my PC. The probability came around 0.507

So scenario 1 definitely has greater probability.

Here's the code if you want to try it out. The code will take a few seconds to compute, especially if its an older PC.

import numpy as np
from collections import Counter
def count(ls,n): #n here defines the length of runs
    ls = ''.join(ls)
    #ms = ls.split('0')
    #ms = [i for i in ms if i]
    #cnt = Counter(ms)
    #print(cnt)
    srch = '0' + ('1'*n) + '0'
    if srch in ls:
        return 1
    else : return 0
expts = 100000
n = 100
run_length = 5 #change length of successive 1's (runs)
pr = 0.5 #change probability
ls = np.random.choice([0,1],(expts,n),p =(1-pr,pr))
fav = 0
for i in ls:
    i = list(map(str,i))
    a = count(i,run_length)
    fav = fav + a
    #print(a)
print(float(fav/expts))
#ls = [0,1,0,1,1,0,0,0,0,0,0,0,0,0,0]

#count(ls1)

Let me know if you want help figuring out how to change the parameters, I've commented what you'll need though.

Oh, and the commented counter lines are if you want to see how it runs, just remember to set the expts to around 100-1000 if you want to try to run them.

Add a comment
Know the answer?
Add Answer to:
PLEASE ANSWER FROM WHERE IT SAYS "Continuing from Part 1" Consider a sequence of n Bernoulli...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT