1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| probabilities = [0.6236059479553904, 0.637646554189305, 0.3711181012296254, 0.8209465255933658, 0.05173005433228524, 0.3573062625107237, 0.13344295110094412, 0.14206462682299148, 0.04645410351730055,
0.6488132685158708, 0.17620817843866216, 0.2253645982270521, 0.04941378324277953, 0.2106519874177867, 0.17899628252788152, 0.17989705461824468, 0.22883900486131004, 0.2938232770946526,
0.19019159279382364, 0.28713182728052633, 0.3198598798970549, 0.505161567057478, 0.41765799256505587, 0.5947240491850156, 0.5154132113239918, 0.9011152416356876, 1.1022447812410636,
1.1028452959679726, 1.2561910208750358, 1.786231055190163, 1.9953817557906774, 1.9962396339719757, 1.7160566199599654, 1.9174006291106662, 1.6134114955676293, 1.7424363740348872,
1.1333857592221905, 0.5862453531598513, 0.58684586788676, 0.153846153846153, 0.4595224478124107, 0.4082499285101515, 0.4287675150128684, 0.4460680583357164, 0.4667143265656279,
0.4875464684014872, 0.4679582499285101, 0.4169002001715756, 0.4576923076923076, 0.4662710895052904, 0.4512582213325709, 0.4437517872462113, 0.4724192164712611, 0.4731913068344295,
0.889791249642551, 0.8183299971404061, 0.8190591935945095, 1.0605519016299687, 1.0772376322562196, 1.1741778667429226, 1.207034601086646, 1.1755075779239348, 1.6416356877323421,
1.3533886188161282, 1.7631112382041754, 1.9885616242493562, 2.0775664855590503, 2.102316271089505, 2.1190877895338858, 2.424578209894195, 2.5295824992851013, 2.498269945667715,
2.531040892193308, 2.2991135258793247, 2.227695167286245, 2.2204460966542747, 1.9724764083500141, 1.8287818129825564, 1.6210037174721188, 1.3330140120102945, 1.3976980268801826,
1.4227051758650273, 1.4634114955676292, 1.223591649985702, 1.0959822705175866, 0.9683728910494712, 0.9289533886188162, 1.0179582499285103, 0.6656705747783817, 0.5460823563054048,
0.3863454389476695, 0.9726622819559625, 0.7164998570203032, 0.8112810980840718, 0.6298541607091793, 0.6760651987417787]
# Value repartition based on above probabilities.
ev_list=[]
ev_number = 3300
for i in range(len(probabilities)):
number = int(ev_number * (probabilities[i] / 100))
ev_list.append(number)
print ev_list
# Construct histogram.
histo = []
for i in range(len(ev_list)):
value = ev_list[i]
for j in range(value):
histo.append(i)
# Compute the algorithm.
law_1 = NormalLaw(50.0, 15.0)
law_2 = NormalLaw(10.0, 25.0)
laws = [law_1, law_2]
results = em_algorithm(histo, laws, 5000)
print"Law 1 var: {}, mean: {}\nLaw 2 var: {}, mean: {}".format(law_1.variance, law_1.mean, law_2.variance, law_2.mean)
# Plot the histogram
x = np.linspace(0, 96, 200)
plt.hist(histo, x)
plt.show() |
Partager