Tuesday, January 18, 2022

Yet another probability Puzzle - HHT vs HTT

Flip a coin until either HHT or HTT appears. Is one more likely to appear first? If so, which one and with what probability ?

Both the sequence start once first Heads come.
Clearly from the diagram we can see that there are more possibility of reaching HHT than HTT. It can be calculated from diagram as

p(HHT | H)  = 0.25 + 0.25[0.5 + 0.52 + 0.53 + 0.54 ..... ] + 0.25*p(HHT | H)

p(HHT | H) = 0.5/0.75

p(HTT | H) = 0.25 +  0.25*p(HTT | H)

p(HTT | H)  = 0.25/0.75 

Clearly 2 times more likely to reach HHT.



Simulating the above transition matrix/ Markov Chain:

H    --> 0, HH --> 1, HT --> 2, TT --> 3

A = np.array([[0.25, 0.0, 0.0, 0.0],
              [0.25, 0.5, 0.0, 0.0],
              [0.25, 0.5, 1.0, 0.0],
              [0.25, 0.0, 0.0, 1.0]])

x = np.array([1, 0, 0, 0])
for i in range(10):
    print(x)
    x = np.round(np.matmul(A, x),2)
    
Output>> [1 0 0 0]
[0.25 (0.25) 0.25 (0.25)]
[0.06 (0.19) 0.44 (0.31)]
[0.02 (0.11) 0.55 (0.32)]
[0.   (0.06) 0.61 (0.32)]
[0.   (0.03) 0.64 (0.32)]
[0.   (0.02) 0.66 (0.32)]
[0.   (0.01) 0.67 (0.32)]
[0.   (0.  ) 0.68 (0.32)]
[0.   (0.  ) 0.68 (0.32)]

No comments:

Post a Comment

Self Attention

  x → Embedding → MultiHeadAttention → Concat → Project to lower dim → → Add(x) → LayerNorm → FFN → Add → LayerNorm Vocab to embedding t...