Skip to content

Instantly share code, notes, and snippets.

@AbeHandler
Last active October 13, 2019 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbeHandler/c55f9ebc5b3f681d1d35edfcfa1af9d8 to your computer and use it in GitHub Desktop.
Save AbeHandler/c55f9ebc5b3f681d1d35edfcfa1af9d8 to your computer and use it in GitHub Desktop.
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