Skip to content

Instantly share code, notes, and snippets.

@jonathanng
Last active April 10, 2021 01:24
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 jonathanng/11000a20c4b1f6f0b27094ca8ab13eaf to your computer and use it in GitHub Desktop.
Save jonathanng/11000a20c4b1f6f0b27094ca8ab13eaf to your computer and use it in GitHub Desktop.
Clustering Illusion Test
# 'We see patterns where they don't exist and we invent causes to explain them.' - Amos Tversky
import numpy as np
def flip(prob_same, last=None):
if last is None:
p = [.5, .5]
elif last == 'H':
p = [prob_same, 1 - prob_same]
elif last == 'T':
p = [1 - prob_same, prob_same]
else:
raise NotImplementedError
return np.random.choice(a=['H', 'T'], p=p)
def flips(prob_same, n=30):
last = None
flips = []
for _ in range(n):
last = flip(prob_same=prob_same, last=last)
flips.append(last)
return ''.join(flips)
print(f'1: {flips(prob_same=0.05)}')
print(f'2: {flips(prob_same=0.10)}')
print(f'3: {flips(prob_same=0.25)}')
print(f'4: {flips(prob_same=0.50)}')
print(f'5: {flips(prob_same=0.75)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment