Last active
October 13, 2019 02:01
-
-
Save AbeHandler/c55f9ebc5b3f681d1d35edfcfa1af9d8 to your computer and use it in GitHub Desktop.
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 | |
def prob_a_to_b(): return int(random.uniform(0,1) > 0) | |
def prob_b_to_a(): return int(random.uniform(0,1) > .5) | |
current_state, samples = 0, [] | |
for i in range(10000): | |
samples.append(current_state) | |
if current_state == 0: # i.e. you are in state a | |
current_state = prob_a_to_b() | |
else: # i.e. you are in state b | |
current_state = prob_b_to_a() | |
print("p(a): {}".format(sum(1 for i in samples if i == 0)/len(samples))) | |
print("p(b): {}".format(sum(1 for i in samples if i == 1)/len(samples))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment