Created
November 24, 2013 22:21
-
-
Save CamDavidsonPilon/7633191 to your computer and use it in GitHub Desktop.
biased coins to unbiased (heh cheating)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
p1 = 0.9 | |
p2 = 0.1 | |
N = 10000 | |
s = 0.0 | |
i = 0 | |
while i < N: | |
if (random.random() < 0.5): #THIS IS WHERE I CHEAT | |
#group A, flip C1 first, want to get H1T2 | |
C1 = random.random() < p1 | |
C2 = random.random() < p2 | |
if C2 != C1: | |
if C1 == True and C2 == False: | |
s+=1 | |
i+=1 | |
else: | |
C2 = random.random() < p2 | |
C1 = random.random() < p1 | |
#group B, flip C2 first, want to get H2T1 | |
if C2 != C1: | |
if C2 == True and C1 == False: | |
s+=1 | |
i+=1 | |
print i | |
print s | |
print s/N |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment