Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- n = 0.5 # number of smoke lovers
- # some initial values
- k = 1 # ratio between smoke lovers and non-smoke lovers probabiltiies
- q = 0.01 # probability non smoke lovers smoke
- p = k*q # probability smoke lovers smoke
- pHist = []
- qHist = []
- kHist = []
- for i in range(10000):
- # calculate conditional probabilities
- pKilledIfSmokes = p*n / (p*n + q*(1-n))
- pKilledIfNoSmokes = (1-p)*n / (1 - p*n + q*(1-n))
- # make decision according to EDT
- # if smoking is desirable, slightly increase the probability of smoking
- # otherwise, decrease it
- if -101*pKilledIfSmokes - 1*(1-pKilledIfSmokes) > -100*pKilledIfNoSmokes:
- q *= 1.01
- else:
- q /= 1.01
- if -90*pKilledIfSmokes + 10*(1-pKilledIfSmokes) > -100*pKilledIfNoSmokes:
- k *= 1.01
- else:
- k /= 1.01
- p = k*q
- # record the histories of p, q and k
- pHist.append(p)
- qHist.append(q)
- kHist.append(k)
- # plot either one
- # plotting p, q is best when n > 0.9
- # plotting k is best when n < 0.9
- """ plt.plot(pHist)
- plt.plot(qHist)"""
- plt.plot(kHist)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement