koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 1 | import sys |
| 2 | import collections |
| 3 | |
| 4 | import scipy.stats as stats |
| 5 | import matplotlib.mlab as mlab |
| 6 | import matplotlib.pyplot as plt |
| 7 | |
| 8 | from data_stat import med_dev, round_deviation |
| 9 | from data_stat import read_data_agent_result |
| 10 | |
| 11 | data = read_data_agent_result(sys.argv[1]) |
| 12 | |
| 13 | # for run in data: |
| 14 | # for name, numbers in run['res'].items(): |
| 15 | # # med, dev = round_deviation(med_dev(numbers['iops'])) |
| 16 | # # print name, med, '~', dev |
| 17 | # distr = collections.defaultdict(lambda: 0.0) |
| 18 | # for i in numbers['iops']: |
| 19 | # distr[i] += 1 |
| 20 | |
| 21 | # print name |
| 22 | # for key, val in sorted(distr.items()): |
| 23 | # print " ", key, val |
| 24 | # print |
| 25 | |
| 26 | |
| 27 | |
| 28 | # # example data |
| 29 | # mu = 100 # mean of distribution |
| 30 | # sigma = 15 # standard deviation of distribution |
| 31 | # x = mu + sigma * np.random.randn(10000) |
| 32 | |
| 33 | x = data[0]['res'][sys.argv[2]]['iops'] |
| 34 | # mu, sigma = med_dev(x) |
| 35 | # print mu, sigma |
| 36 | |
| 37 | # med_sz = 1 |
| 38 | # x2 = x[:len(x) // med_sz * med_sz] |
| 39 | # x2 = [sum(vals) / len(vals) for vals in zip(*[x2[i::med_sz] |
| 40 | # for i in range(med_sz)])] |
| 41 | |
| 42 | mu, sigma = med_dev(x) |
| 43 | print mu, sigma |
| 44 | print stats.normaltest(x) |
| 45 | |
| 46 | num_bins = 20 |
| 47 | # the histogram of the data |
| 48 | n, bins, patches = plt.hist(x, num_bins, normed=1, facecolor='green', alpha=0.5) |
| 49 | # add a 'best fit' line |
| 50 | |
| 51 | y = mlab.normpdf(bins, mu, sigma) |
| 52 | plt.plot(bins, y, 'r--') |
| 53 | |
| 54 | plt.xlabel('Smarts') |
| 55 | plt.ylabel('Probability') |
koder aka kdanilov | b896f69 | 2015-04-07 14:57:55 +0300 | [diff] [blame] | 56 | plt.title(r'Histogram of IQ: $\mu={}$, $\sigma={}$'.format(int(mu), int(sigma))) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 57 | |
| 58 | # Tweak spacing to prevent clipping of ylabel |
| 59 | plt.subplots_adjust(left=0.15) |
| 60 | plt.show() |