Guest User

Untitled

a guest
Jul 20th, 2020
48
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import matplotlib.pyplot as plt
  2.  
  3. n = 0.5 # number of smoke lovers
  4.  
  5. # some initial values
  6. k = 1 # ratio between smoke lovers and non-smoke lovers probabiltiies
  7. q = 0.01 # probability non smoke lovers smoke
  8. p = k*q  # probability smoke lovers smoke
  9.  
  10. pHist = []
  11. qHist = []
  12. kHist = []
  13.  
  14. for i in range(10000):
  15.     # calculate conditional probabilities
  16.     pKilledIfSmokes = p*n / (p*n + q*(1-n))
  17.     pKilledIfNoSmokes = (1-p)*n / (1 - p*n + q*(1-n))
  18.  
  19.     # make decision according to EDT
  20.     # if smoking is desirable, slightly increase the probability of smoking
  21.     # otherwise, decrease it
  22.     if -101*pKilledIfSmokes - 1*(1-pKilledIfSmokes) > -100*pKilledIfNoSmokes:
  23.         q *= 1.01
  24.     else:
  25.         q /= 1.01
  26.  
  27.     if -90*pKilledIfSmokes + 10*(1-pKilledIfSmokes) > -100*pKilledIfNoSmokes:
  28.         k *= 1.01
  29.     else:
  30.         k /= 1.01
  31.  
  32.     p = k*q
  33.  
  34.     # record the histories of p, q and k
  35.     pHist.append(p)
  36.     qHist.append(q)
  37.     kHist.append(k)
  38.  
  39. # plot either one
  40. # plotting p, q is best when n > 0.9
  41. # plotting k is best when n < 0.9
  42.  
  43. """ plt.plot(pHist)
  44. plt.plot(qHist)"""
  45.  
  46. plt.plot(kHist)
  47. plt.show()
RAW Paste Data